Jump to content

  • Log In with Google      Sign In   
  • Create Account


3d camera


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 StiNKy   Members   -  Reputation: 144

Like
Likes
Like

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.

Sponsor:

#2 smitty1276   Members   -  Reputation: 560

Like
Likes
Like

Posted 03 September 2001 - 06:48 PM

Sorry, but...

gluLookAt() is the best way to do that. Why would you want to rewrite all of the code that is already written for you?

#3 StiNKy   Members   -  Reputation: 144

Like
Likes
Like

Posted 03 September 2001 - 06:51 PM

Cause I''m trying to write an engine using nothing but gl, ie no glu, no glut, nothing else but your standard gl. Working damn well so far.... Surely there IS a way.

#4 Sneftel   Senior Moderators   -  Reputation: 1776

Like
Likes
Like

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.

#5 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 03 September 2001 - 10:17 PM

in quake, carmack doesn''t use gluLookAt(..) he uses MygluLookAt(..)

#6 StiNKy   Members   -  Reputation: 144

Like
Likes
Like

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()


#7 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 04 September 2001 - 09:55 AM

easy find the direction the person is looking at
Dir = camera/person(first person) direction
cam = camera/person
gluLookAt( cam.x, cam.y, cam.z, cam.x+dir.x, cam.y+dir.y, cam.z+dir.z, 0,1,0 );



#8 StiNKy   Members   -  Reputation: 144

Like
Likes
Like

Posted 04 September 2001 - 07:09 PM

what?

#9 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

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.


#10 TerranFury   Members   -  Reputation: 142

Like
Likes
Like

Posted 05 September 2001 - 09:54 AM

glRotatef(camera.yaw, 1, 0, 0);
glRotatef(camera.pitch, 0, 1, 0);
glRotatef(camera.roll, 0, 0, 1);
glTranslatef(-camera.x, -camera.y, -camera.z);

#11 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 05 September 2001 - 10:19 AM

the above method will suffer from gimbal lock (unless u limit the values passed)
check my camera rotation post below

#12 Sir Melvalot   Members   -  Reputation: 122

Like
Likes
Like

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

#13 Sir Melvalot   Members   -  Reputation: 122

Like
Likes
Like

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

#14 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

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.


#15 -IceDragon-   Members   -  Reputation: 122

Like
Likes
Like

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)

#16 bazee   Members   -  Reputation: 122

Like
Likes
Like

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS