# 3d camera

Started by StiNKy, Sep 03 2001 06:25 PM

15 replies to this topic

###
#1
Members - Reputation: **144**

Posted 03 September 2001 - 06:25 PM

How can I do a 1st person view so the user can move forward in the exact direction they are looking at? without using freaking glu commands??? All the damn results for what I''m looking for is glu this, glu that. Some people don''t want to freaking use glu!
Thanks in advanced.

###
#4
Senior Moderators - Reputation: **1788**

Posted 03 September 2001 - 07:25 PM

glu is standard gl. It''s supported by the maintainers of OpenGL. it *is* gl. Why would you not want to use it??

With that said, some not-too-complex matrix math will give you your very own lookAt function. use gramm-schmidt orthonormalization to get three orthogonal unit vectors from your passed-in two(eye to target, and eye to up), make ''em into a matrix, and then use the eyepoint as a translation.

With that said, some not-too-complex matrix math will give you your very own lookAt function. use gramm-schmidt orthonormalization to get three orthogonal unit vectors from your passed-in two(eye to target, and eye to up), make ''em into a matrix, and then use the eyepoint as a translation.

###
#6
Members - Reputation: **144**

Posted 03 September 2001 - 11:24 PM

Well, this seems to be working for me so far:

glRotatef(rot.X, 0.1f, 0.0f, 0.0f);

glRotatef(rot.Y, 0.0f, 0.1f, 0.0f);

with rot.X being how much to rotate around the X axis, and rot.Y how much around the Y axis.

But if I''m storing the position at pos.X, pos.Y, and pos.Z how can I modify the pos.X, pos.Y, and pos.Z values so it moves forward in the world to exactly where the user is looking at? You can''t do that with gluLookAt()

glRotatef(rot.X, 0.1f, 0.0f, 0.0f);

glRotatef(rot.Y, 0.0f, 0.1f, 0.0f);

with rot.X being how much to rotate around the X axis, and rot.Y how much around the Y axis.

But if I''m storing the position at pos.X, pos.Y, and pos.Z how can I modify the pos.X, pos.Y, and pos.Z values so it moves forward in the world to exactly where the user is looking at? You can''t do that with gluLookAt()

###
#9
Anonymous Poster_Anonymous Poster_*
Guests - Reputation:

Posted 05 September 2001 - 04:37 AM

I don''t like gluLookAt, glRotate, glTranslate, whatever. I compute my own camera matrix and load it via glLoadMatrix(), that''s it.

###
#12
Members - Reputation: **122**

Posted 05 September 2001 - 10:54 AM

I can do this if you only want to move along the y=0 plane, like in a first-person-shooter where you are only moving along the floor. I don''t know how to do full 3D, like counter-strike free-look-mode.

You want to know how much to add to the x and z coordinates of your camera position. Use Sine and Cosine. they give you the x and z coordinates of the point on a circle of radius 1. Just input your angle of rotation.

If your angle of rotation (Yaw) is measured from the Z axis...

Camera.PositionX += sinf( Camera.Yaw );

Camera.PositionZ += cosf( Camera.Yaw );

Hope this helps you

You want to know how much to add to the x and z coordinates of your camera position. Use Sine and Cosine. they give you the x and z coordinates of the point on a circle of radius 1. Just input your angle of rotation.

If your angle of rotation (Yaw) is measured from the Z axis...

Camera.PositionX += sinf( Camera.Yaw );

Camera.PositionZ += cosf( Camera.Yaw );

Hope this helps you

###
#13
Members - Reputation: **122**

Posted 05 September 2001 - 10:54 AM

I can do this if you only want to move along the y=0 plane, like in a first-person-shooter where you are only moving along the floor. I don''t know how to do full 3D, like counter-strike free-look-mode.

You want to know how much to add to the x and z coordinates of your camera position. Use Sine and Cosine. they give you the x and z coordinates of the point on a circle of radius 1. Just input your angle of rotation.

If your angle of rotation (Yaw) is measured from the Z axis...

Camera.PositionX += sinf( Camera.Yaw );

Camera.PositionZ += cosf( Camera.Yaw );

Hope this helps you

You want to know how much to add to the x and z coordinates of your camera position. Use Sine and Cosine. they give you the x and z coordinates of the point on a circle of radius 1. Just input your angle of rotation.

If your angle of rotation (Yaw) is measured from the Z axis...

Camera.PositionX += sinf( Camera.Yaw );

Camera.PositionZ += cosf( Camera.Yaw );

Hope this helps you

###
#14
Members - Reputation: **528**

Posted 05 September 2001 - 05:35 PM

ive never seen cs but if its anything like q3 when u do a flythrough with the camera.

it is possible just use

camPOS += camDIR;

ie not

camera.PositionX += sinf( Camera.Yaw );

Camera.PositionZ += cosf( Camera.Yaw );

the reason u can do this is the camera doesnt do roll or loop, thus u can get away with usiong eulars.

it is possible just use

camPOS += camDIR;

ie not

camera.PositionX += sinf( Camera.Yaw );

Camera.PositionZ += cosf( Camera.Yaw );

the reason u can do this is the camera doesnt do roll or loop, thus u can get away with usiong eulars.

###
#15
Members - Reputation: **122**

Posted 06 September 2001 - 08:23 AM

Using camPOS += camDIR recommends camDIR to be a unit-size vector which contains the rotation of the player. if you''re storing the rotation value around the x and y axis seperatly you could do it this way:

posx -= sinf(roty) * cosf(rotx);

posy -= sinf(rotx);

posz -= cosf(roty) * cosf(rotx);

The method Sir Melvalot posted just uses the Yaw value.

(you might have to change some of the -= operators to += operators)

posx -= sinf(roty) * cosf(rotx);

posy -= sinf(rotx);

posz -= cosf(roty) * cosf(rotx);

The method Sir Melvalot posted just uses the Yaw value.

(you might have to change some of the -= operators to += operators)

###
#16
Members - Reputation: **122**

Posted 06 September 2001 - 08:58 AM

I have a function in my game engine which does this, but it''s VB DirectX code, so you''ll have to translate it since I''m not too familiar with OpenGL.

Hopefully it is formatted correctly below.

'' gets the translation relative to the direction the frame is facing

Public Property Get RelativeVector(Velocity As D3DVECTOR, Optional deltaTime As Single = 1) As D3DVECTOR

Dim matView As D3DMATRIX, matTrans As D3DMATRIX, matRot As D3DMATRIX

Dim Translation As D3DVECTOR

On Error Resume Next

'' multiply matrices together to create rotation matrix

D3DXMatrixRotationYawPitchRoll matRot, vecOrientation.y, vecOrientation.x, vecOrientation.z

'' translate

D3DXVec3Scale Translation, Velocity, deltaTime

D3DXMatrixTranslation matTrans, Translation.x, Translation.y, Translation.z

'' multiply that translation and rotation

D3DXMatrixMultiply matView, matTrans, matRot

'' translate by matrix

D3DXVec3TransformCoord RelativeVector, RelativeVector, matView

End Property

You have to supply the direction you want the camera to move in as a velocity (for example (0,0,1) will move the camera foward 1 unit).

It returns the vector by which the frame (or camera) needs to be translated in order to move in the correct direction.

Explanations of variables out of scope of this function for you:

vecOrientation is the orientation (direction it is facing) of the frame (or in your case, camera).

The D3DX functions have long descriptive names I hope it''s clear what they do, and can be replaced with your own code?

I don''t think I''ve been too helpful but I hope that makes some sort of sense. I tried my best anyway.

Hopefully it is formatted correctly below.

'' gets the translation relative to the direction the frame is facing

Public Property Get RelativeVector(Velocity As D3DVECTOR, Optional deltaTime As Single = 1) As D3DVECTOR

Dim matView As D3DMATRIX, matTrans As D3DMATRIX, matRot As D3DMATRIX

Dim Translation As D3DVECTOR

On Error Resume Next

'' multiply matrices together to create rotation matrix

D3DXMatrixRotationYawPitchRoll matRot, vecOrientation.y, vecOrientation.x, vecOrientation.z

'' translate

D3DXVec3Scale Translation, Velocity, deltaTime

D3DXMatrixTranslation matTrans, Translation.x, Translation.y, Translation.z

'' multiply that translation and rotation

D3DXMatrixMultiply matView, matTrans, matRot

'' translate by matrix

D3DXVec3TransformCoord RelativeVector, RelativeVector, matView

End Property

You have to supply the direction you want the camera to move in as a velocity (for example (0,0,1) will move the camera foward 1 unit).

It returns the vector by which the frame (or camera) needs to be translated in order to move in the correct direction.

Explanations of variables out of scope of this function for you:

vecOrientation is the orientation (direction it is facing) of the frame (or in your case, camera).

The D3DX functions have long descriptive names I hope it''s clear what they do, and can be replaced with your own code?

I don''t think I''ve been too helpful but I hope that makes some sort of sense. I tried my best anyway.