Good morning hi Charles ...
How I can set a camera Position in a. OpenGL Scene and what"s camera content exactly?
Here Just the Triangel example with some few camera Features Code lines ... Found Not enough about camera properties in oxygen folders
includepath "$\inc\"
$ FileName "t.exe"
'include "RTL32.inc"
'include "RTL64.inc"
$ title "Rotating Triangle"
int width=740
int height=580
#include "OpenglSceneFrame.inc"
sub Initialize(sys hWnd)
'=======================
end sub
'
sub Scene(sys hWnd)
'==================
'
long wwidth,wHeight
static single ang1,angi1=1
'
' ---------- how to use camera in a scene ? --------------------- //
dim cameraProjectionMatrix(16) as single
float cameraPosition[3]
float CameraProjectionMatrix[16],cameraViewMatrix[16]
CameraPosition={0,0,0}
' ---------- how to use camera in a scene ? --------------------- //
glClearColor 0.3, 0.3, 0.5, 0
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
'glMatrixMode GL_PROJECTION '
glLoadIdentity
'
'gluPerspective 45, Width/Height, 1.0, 100
'gluPerspective 45, 0.65, 5.0, 100 'gut1
gluPerspective 45, 0.75, 7.0, 100 'gut1
'--------------------------------------
gltranslatef 0.0, 0.0, -4.0
glrotatef ang1, 0.0, 1.0, 0.0 '1.0
'
glBegin GL_TRIANGLES
glColor3f 1.0, 0.0, 0.0 : glVertex3f 0.0, 1.0, 0.0
glColor3f 0.0, 1.0, 0.0 : glVertex3f -1.0, -1.0, 0.0
glColor3f 0.0, 0.0, 1.0 : glVertex3f 1.0, -1.0, 0.0
glEnd
'
'UPDATE ROTATION ANGLES
'----------------------
'
ang1+=angi1
if ang1>360 then ang1-=360
'
end sub
sub Release(sys hwnd)
'====================
end sub
Thanks
PS found this litte Code snippet and Guess its belonging to camera Features and Options but I am Not Sure.. built this example only for Testing If its running... Thanks
uses MathUtil.inc
print "yes"
'mathUtil.inc
'
'CAMERA SPACE
'http://ogldev.atspace.co.uk/www/tutorial13/tutorial13.html
'
function SetViewMatrix(float *r, vec3 *vp,*vu,*vv,*vn)
======================================================
indexbase 0
vec3 u,v,n
float p[16], m[16]
'
SetIdentity p,4
p[12]={-vp.x, -vp.y, -vp.z}
'
normalize u,vu
normalize v,vv
normalize n,vn
'itr cross product u from n and v
'
' U V N
' UP RIGHT LOOKAT
--------------------------------------
m
[o]= {u.x, v.x, n.x, 0.0} 'column 0
m[4] = {u.y, v.y, n.y, 0.0} 'column 1
m[8] = {u.z, v.z, n.z, 0.0} 'column 2
m[12]= {0.0, 0.0, 0.0, 1.0} 'column 3
--------------------------------------
'
Mat4x4Mul r,m,p
'
end function
print "yes2"
There is a macro called Navigation which provides camera-like features, enabling you to move through a landscape using arrow keys, PgUp PgDn etc. It should be invoked before the scene objects are constructed (After fog etc.)
macro Navigation()
==================
'
'VIEW CONTROL WITH KEYBOARD KEYS
'
static float cmmx,cmmy,cmmz,cmax,cmay,cmaz,ns
glrotatef cmax,1,0,0 'rotate yz : pitch
glrotatef cmay,0,1,0 'rotate xz : yaw
glrotatef cmaz,0,0,1 'rotate xy : roll
glTranslatef cmmx,cmmy,cmmz
'
if not key[VK_CONTROL]
'MOVE
ns=0.02
if key[VK_SHIFT] then ns=0.1
if key[37] then cmmx+=ns*cos(rad(cmay)) : cmmz+=ns*sin(rad(cmay)) 'left
if key[39] then cmmx-=ns*cos(rad(cmay)) : cmmz-=ns*sin(rad(cmay)) 'right
if key[38] then cmmx-=ns*sin(rad(cmay)) : cmmz+=ns*cos(rad(cmay)) 'up
if key[40] then cmmx+=ns*sin(rad(cmay)) : cmmz-=ns*cos(rad(cmay)) 'dpwn
if key[33] then cmmy-=ns 'pgup
if key[34] then cmmy+=ns 'pgdn
else
'ROTATE
ns=.4
if key[VK_SHIFT] then ns=1.0
if key[37] then cmay-=ns 'left
if key[39] then cmay+=ns 'right
if key[38] then cmax-=ns 'up
if key[40] then cmax+=ns 'down
if key[33] then cmaz+=ns 'pgup
if key[34] then cmaz-=ns 'pgdn
if key[36]
cmax=0. : cmay=0. : cmaz=0. 'HOME'
end if
end if
end macro
Best example here:
demos\opengl\TravelTowardsPick.o2bas
$ FileName "t.exe"
'uses RTL64.inc
string title="Travel Towards objects (use mouse or press 1..6) "
% ExplicitMain
uses OpenglSceneFrame
uses MinMidi
uses glo2\shapes
uses glo2\textures
uses glo2\materials
uses glo2\particles
indexbase 1
sys GdiplusToken
float ang1
float ma[16]
float li[16]
int cube,sphere
Cloud cloud1
sub initialize(sys hWnd)
========================
'
GDIplus 1
'
static int res=256
BuildTextures 16,res
'
cube=CompileList : CubeForm : glEndList
sphere=CompileList : Spheric 1,1,6 : glEndList
'
end sub
sub Release(sys hwnd)
'====================
DeleteAllGlCompiled
DeleteTextures 16
Gdiplus 0
end sub
sub RenderCube(float x,y,z,sc,int tex)
======================================
glBindTexture GL_TEXTURE_2D,tex
glPushMatrix
gltranslatef x,y,z
glscalef sc,sc,sc
glCallList cube
'glCallList pent
glPopMatrix
end sub
sub RenderPlane(float x,y,z,sc,int tex, float u,v)
==================================================
glBindTexture GL_TEXTURE_2D,tex
glPushMatrix
gltranslatef x,y,z
glscalef sc,1,sc
glBegin GL_QUADS
glTexCoord2f 0.0,0.0 : glVertex3f -1.0,0,-1.0
glTexCoord2f u ,0.0 : glVertex3f 1.0,0,-1.0
glTexCoord2f u ,v : glVertex3f 1.0,0, 1.0
glTexCoord2f 0.0,v : glVertex3f -1.0,0, 1.0
glend
glPopMatrix
end sub
sub scene(sys hWnd)
'==================
'
static single ra,ri,angi1=.5
int t1=texn[10]
int t2=texn[11]
'
'
ActiveFrame
glClearColor 0.5, 0.5, 0.7, 0.0 'rgba
Fog 0.5, 0.5, 0.7, 0.05 'rgb and density
BeginPick
Navigation
StandardLighting li
StandardMaterial ma
'
'
'SPHERE OBJECTS
'
type dest
float x,y,z,r
end type
static dest v=
{
'x y z r
-20.,10.,-60.0,6.0,
2.5,-.5,-06.0,1.0,
2.5,-.5,-12.0,1.0,
-2.5,-.5,-18.0,1.0,
-2.5,-.5,-24.0,1.0,
0.0,-.5,-30.0,1.0
}
macro Translate(v) '(dest*v)
glTranslatef v.x, v.y, v.z
glScalef v.r,v.r,v.r
end macro
'
indexbase 1
macro RenderSphere(n,m)
PickLabel n
glPushMatrix
Translate v[n]
Material m
glCallList sphere
glPopMatrix
end macro
'
RenderSphere 1,Red
RenderSphere 2,White
RenderSphere 3,RedShiny
RenderSphere 4,GreenShiny
RenderSphere 5,BlueShiny
RenderSphere 6,White
'
label 0
'
'
'ORIENTATE AND TRAVEL TOWARDS
'
macro PlusMinus180(a) '(float*a)
if a>=360 then a-=360 'clamp 0 to 359..
if a<0 then a+=360
if a>180 then a-=360 'clamp +180 / -179..
end macro
'
static float cx,cz,dh,di,dy,dz,dr,ds,ay,az,aay,clos
static int targ,targy,targm,targsel
'
select lastkey
case "1" to "6"
targsel=LastKey-0x30
LastKey=0 'stop further evaluation
end select
'
if picked<>0 and picking=0
targsel=picked
'SetWindowText hwnd,str picked
picked=0
end if
'
if targsel
targ=targsel 'target object index
dx=cmmx+v[targ].x 'x distance to target
dy=cmmy+v[targ].y 'y distance to target
dz=cmmz+v[targ].z 'z distance to target
dr=hypot(dx,dz) 'distance to target
di=dy/dr 'upward y increment
ay=atan(dx,-dz)*180/pi '
PlusMinus180 ay 'target angle
PlusMinus180 cmay 'start angle
aay=.01*(ay-cmay) 'angle increment
ds=0.125*v[targ].r 'limit to step resolution
clos=v[targ].r*2.0+1.0 'nearest allowed
targy=targ 'activate turning
targsel=0
end if
'
'Turning: Look left/right
'
if targy then
if abs(cmay-ay)<=abs(aay)
aay*=.5
if abs(aay)<.001 then
targm=targy 'Activate Travel
targy=0
end if
else
cmay+=aay
end if
end if
'
'Travel Towards
'
if targm
cx=cmmx-ds*sin(rad(cmay))
cz=cmmz+ds*cos(rad(cmay))
dh=hypot(cx+v[targ].x,cz+v[targm].z)
if dh<=clos
ds*=.5
if ds<.00001 then targm=0
else
cmmx=cx
cmmz=cz
cmmy-=di*ds
end if
'
end if
'
EndPick
'
Material White
glEnable GL_TEXTURE_2D
'
RenderCube 2.5,-2.0,-6.0, 0.5,t1
'
RenderPlane 0.0,-2.0,-16.0,16.0,t2,8,8
'
glDisable GL_TEXTURE_2D
glDisable GL_LIGHTING
'
'CLOUD
glEnable GL_TEXTURE_2D
glPushMatrix
gltranslatef -10.0, -10.0, -48.0
glscalef 20.0,12.0,1.0
cloud1.render 30 'max 50
glPopMatrix
glDisable GL_TEXTURE_2D
'
ang1+=angi1
if ang1>360 then ang1-=360
sleep 10
end sub
MainWindow width,height,WS_OVERLAPPEDWINDOW