Skip to main content
gamedev.net
🔒 Locked

OpenGLGame programming engine....

Started by kajjait Apr 10, 2002 at 7:23 PM 5 replies 200+ views
Original Post
kajjait
kajjait
i have recently purchased "OpenGL game programming" (prima techs game dev series) and after i finished with the book i started messing around with the engine... there are a few things that are bothering me... in the engine i want to be able to "fly" around but i cant seem to figure out how to modify it so that it moves the camera forward from where im looking, so instead of moving me either forward or sidedways on the ground i would be able to move up and down. i know right now if i hit W, it will move me a few spaces forward on the ground, instead of this i want it to move me a few spaces in whatever direction i am looking at. how do i do this?
Ataru
Ataru
There is probably a vector in the code that gives you the direction you are looking in.

If so, here''s how you do it, say you have a position of your camera, x,y,z and the direction vector xV,yV,zV.

All you have to do is set your position to be

x = x+xV
y = y+yV
z = z+zV

To make it better, normalize the vector, and then you can multiply it by a scalar. This scalar detertmines the amount you are going to move by.

Hope this helps a little.
kajjait
kajjait
that helps a little, the problem now is finding the right vectors.. i guess ill just try stuff out untill it works :

*edit*
i thought this would work..... gameCamera->position = gameCamera->position + gameCamera->lookAt; but it just moves the camera up :[

can anyone who is familiar with this engine please help me get the right vectors?



[edited by - kajjait on April 10, 2002 8:56:58 PM]

[edited by - kajjait on April 10, 2002 9:05:18 PM]
kajjait
kajjait
well im at the point where im just about to flip out and slam my head on my monitor.... i guess im going to look for a new engine, or perhaps even create my own ... :\ unless one of you knows what to do... ill check back here a bit later
rgirard413
rgirard413
what is it using for the camera? gluLookAt? if so here are two functions that might help out, but you will have to figure out how they work and adjust accordingly

m_vView and m_vPosition are vectors for the camera that should already be set up, rotateview will rotate the camera that much around each axis and movecamera will move the camera in taht ammount of distance passed in, in the direction you are looking


    
void RotateView(float X, float Y, float Z)
{
Vector vVector;

vVector.x = m_vView.x - m_vPosition.x;
vVector.y = m_vView.y - m_vPosition.y;
vVector.z = m_vView.z - m_vPosition.z;

if(X) {
m_vView.z = (float)(m_vPosition.z + sin(X)*vVector.y + cos(X)*vVector.z);
m_vView.y = (float)(m_vPosition.y + cos(X)*vVector.y - sin(X)*vVector.z);
}
if(Y) {
m_vView.z = (float)(m_vPosition.z + sin(Y)*vVector.x + cos(Y)*vVector.z);
m_vView.x = (float)(m_vPosition.x + cos(Y)*vVector.x - sin(Y)*vVector.z);
}
if(Z) {
m_vView.x = (float)(m_vPosition.x + sin(Z)*vVector.y + cos(Z)*vVector.x);
m_vView.y = (float)(m_vPosition.y + cos(Z)*vVector.y - sin(Z)*vVector.x);
}
}

Vector MoveCamera(float speed)
{
Vector vVector=Vector(0, 0, 0);

Vector m_vOld = m_vPosition;

vVector.x = m_vView.x - m_vPosition.x;
vVector.y = m_vView.y - m_vPosition.y;
vVector.z = m_vView.z - m_vPosition.z;

//just add movement for y in here

m_vPosition.x += vVector.x * speed;
m_vPosition.z += vVector.z * speed;
m_vView.x += vVector.x * speed;
m_vView.z += vVector.z * speed;

return Vector((m_vPosition.x - m_vOld.x),
(m_vPosition.y - m_vOld.y),
(m_vPosition.z - m_vOld.z));
}


[edited by - rgirard413 on April 10, 2002 11:47:34 PM]
http://www.thedizzle.com
kajjait
kajjait
Oh my god, thank you SO MUCH! I must have spent about 8 hours sitting there trying different things out. You sir, are the man!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.