OpenGL: Moving through a world
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
OpenGL: Moving through a world
Hello,
I don't understand the cos-, sin- and tanmathematics. So I want to walk through a world made in opengl. In opengl you can only rotate around the zeropoint of the world, if you can't make such a calculating-function. Can somebody help me?
[EDIT] I have tryed it, but it doesn't work correctly: http://nopaste.php.cd/7058
I don't understand the cos-, sin- and tanmathematics. So I want to walk through a world made in opengl. In opengl you can only rotate around the zeropoint of the world, if you can't make such a calculating-function. Can somebody help me?
[EDIT] I have tryed it, but it doesn't work correctly: http://nopaste.php.cd/7058
Re: OpenGL: Moving through a world
IMHO really good tutorial here:
http://nehe.gamedev.net/data/articles/a ... article=08
Nice explainations, pictures and all the formulas you need.
You'll also find some nicely commented codes (c++) on this site:
http://www.ultimategameprogramming.com/ ... nGL&page=5
but I think you don't even have to know c in order to understand this.
http://nehe.gamedev.net/data/articles/a ... article=08
Nice explainations, pictures and all the formulas you need.
You'll also find some nicely commented codes (c++) on this site:
http://www.ultimategameprogramming.com/ ... nGL&page=5
but I think you don't even have to know c in order to understand this.
Good programmers don't comment their code. It was hard to write, should be hard to read.
-
Blade
- Enthusiast

- Posts: 362
- Joined: Wed Aug 06, 2003 2:49 pm
- Location: Venice - Italy, Japan when possible.
- Contact:
Re: OpenGL: Moving through a world
Walking in a OpenGL world needs more math than some sin-cos calculations.DarkDragon wrote:Hello,
I don't understand the cos-, sin- and tanmathematics.
I wasn't very good at math lessons (many-many years ago) but I've found myself studing a lot when I decided to make my GL world-walking (using C) some years ago...
As suggested, the Ne-He site is a very good start.
Good luck
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Thx
Thanks
. I will try to learn it.
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Hello,
I have found the answer. Look here:
Uhm, here it looks a little bit crazy, but in my engine it works. And you can't show glu objects in this code. But maybe it will help other people with their walkthrough
.
I have found the answer. Look here:
Code: Select all
#GL_COLOR_BUFFER_BIT = $00004000
#GL_DEPTH_BUFFER_BIT = $00000100
#GL_TRIANGLES = $0004
#GL_FOG = $0B60
#GL_MODELVIEW = $1700
#GL_PROJECTION = $1701
#WindowWidth = 500
#WindowHeight = 400
#WindowFlags = #PB_Window_TitleBar | #PB_Window_MaximizeGadget | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered
Global floatX.f
Global floatY.f
Global floatZ.f
Global CameraX.f, CameraY.f, CameraZ.f, CamrotX.f, CamrotY.f, CamrotZ.f, CameraSpeed.f, CameraZoom.f, hDC
CamSpeed.f = 0.025
CameraZoom = 0.5
If OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #WindowFlags, "OpenGLCamera")
piover180.f = (ATan(1)*4)/180
pfd.PIXELFORMATDESCRIPTOR ;OpenGL starten
hDC = GetDC_(hWnd)
pfd\nSize = SizeOf(PIXELFORMATDESCRIPTOR)
pfd\nVersion = 1
pfd\dwFlags = #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER | #PFD_DRAW_TO_WINDOW
pfd\iLayerType = #PFD_MAIN_PLANE
pfd\iPixelType = #PFD_TYPE_RGBA
pfd\cColorBits = 24
pfd\cDepthBits = 32
pixformat = ChoosePixelFormat_(hDC, pfd)
SetPixelFormat_(hDC, pixformat, pfd)
hrc = wglCreateContext_(hDC)
wglMakeCurrent_(hDC, hrc)
pixformat = ChoosePixelFormat_(hDC, pfd)
SetPixelFormat_(hDC, pixformat, pfd)
hrc = wglCreateContext_(hDC)
wglMakeCurrent_(hDC,hrc)
SwapBuffers_(hDC)
floatX = 0.5
floatY = 0.25
floatZ = -0.5
Repeat
glTranslatef_(0, 0, -7.0)
glMatrixMode_(#GL_MODELVIEW)
If GetAsyncKeyState_(#VK_UP) <> 0
CameraZ = CameraZ - Sin((CamrotY-90)*piover180)*CamSpeed
CameraX = CameraX - Cos((CamrotY+90)*piover180)*CamSpeed
ElseIf GetAsyncKeyState_(#VK_DOWN) <> 0
CameraZ = CameraZ + Sin((CamrotY-90)*piover180)*CamSpeed
CameraX = CameraX + Cos((CamrotY+90)*piover180)*CamSpeed
EndIf
If GetAsyncKeyState_(#VK_RIGHT) <> 0
CamrotY - (CamSpeed*5)
ElseIf GetAsyncKeyState_(#VK_LEFT) <> 0
CamrotY + (CamSpeed*5)
EndIf
glMatrixMode_(#GL_PROJECTION) ;Höhere Sichtweite, Kamera und Zoom
glLoadIdentity_()
glOrtho__(-2.0+CameraZoom, 2.0-CameraZoom, -2.0+CameraZoom, 2.0-CameraZoom, 0.0, 50.0)
glRotatef_(-CamrotY, 0.0, 1.0, 0.0)
glTranslatef_(0, 0, -10.0)
glMatrixMode_(#GL_MODELVIEW)
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_()
glRotatef_(45.0, 0, 1.0, 0.0)
glTranslatef_(-CameraX, -CameraY, -CameraZ)
glBegin_(#GL_TRIANGLES)
glNormal3f_(0, 0, 1.0)
glColor4f_(0.0, 0.0, 1.0, 1.0)
glVertex3f_(floatX, floatY, floatZ)
glColor4f_(0.0, 1.0, 0.0, 1.0)
glVertex3f_(-floatX, floatY, floatZ)
glColor4f_(1.0, 1.0, 0.0, 1.0)
glVertex3f_(-floatX, -floatY, floatZ)
glEnd_()
glBegin_(#GL_TRIANGLES)
glNormal3f_(0, 0, 1.0)
glColor4f_(0.0, 0.0, 1.0, 1.0)
glVertex3f_(floatX, floatY, floatZ+0.25)
glColor4f_(0.0, 1.0, 0.0, 1.0)
glVertex3f_(-floatX, floatY, floatZ+0.25)
glColor4f_(1.0, 1.0, 0.0, 1.0)
glVertex3f_(-floatX, -floatY, floatZ+0.25)
glEnd_()
SwapBuffers_(hDC)
Event = WindowEvent()
Delay(1) ;For WinME users
Until Event = #PB_Event_CloseWindow
End
EndIf
-
legider_pb
- User

- Posts: 39
- Joined: Tue Nov 25, 2003 12:28 pm
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
does this help?DarkDragon wrote:Can you give me the standart arguments for gluLookAtf in PureBasic?
Code: Select all
gluLookAt__(eyex, eyey, eyez, <- where you are
centerx, centery, centerz <- where you look to
upx, upy, upz) <- up-vector
Good programmers don't comment their code. It was hard to write, should be hard to read.
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
what do you mean by "standard settings" ?DarkDragon wrote:Uhm, I know the parameters, but I want the standart settings.
that totally depends on the purpose.
EDIT:
try gluLookAt__(0.0,0.0,0.0, 0.0,0.0,-1.0, 0.0,1.0,0.0)
instead of glOrtho__() and remark the glTranslatef_() s.
Now you should see something...
Last edited by traumatic on Thu Jan 29, 2004 7:54 pm, edited 1 time in total.
Good programmers don't comment their code. It was hard to write, should be hard to read.
your code CAN'T work because you're trying to get the dc of nothing:DarkDragon wrote: Ohh, I have the same problem, if I use the glu objects, but it should work!
Code: Select all
hDC = GetDC_(hWnd)Code: Select all
[...]
If OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #WindowFlags, "OpenGLCamera")
[...]Code: Select all
[...]
hWnd = OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #WindowFlags, "OpenGLCamera")
If hWnd
[...]Good programmers don't comment their code. It was hard to write, should be hard to read.
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
