void CCamera::MoveCamera()
{
int x;
int y;
float deltax;
float deltay;
x=1280/2;
y=1028/2;
POINT cursorpos;
GetCursorPos(&cursorpos);
SetCursorPos(1280/2,1024/2);
if(x==cursorpos.x && y==cursorpos.y)
return;
deltax=(float)(x - cursorpos.x)*-0.01;
deltay=(float)(y - cursorpos.y)*-0.01;
gPlayer.viewangle[0] +=deltay * 4;//gPlayer.scrollratio;
gPlayer.viewangle[1] +=deltax * 4;//gPlayer.scrollratio;
gPlayer.viewangle[2]=0.0;
}
void CCamera::MovePlayer()
{
vec3_t angle;
VectorCopy(gPlayer.viewangle,angle);
angle[0]=-angle[0];
angle[1]+=90;
AngleVectors(angle,forward,right,up);
VectorNormalize(forward);
VectorNormalize(right);
VectorNormalize(up);
if(gApp.IsKeyPressed(DIK_UP))
VectorMA(gPlayer.origin,-10,forward,gPlayer.origin);
if(gApp.IsKeyPressed(DIK_DOWN))
VectorMA(gPlayer.origin,+10,forward,gPlayer.origin);
if(gApp.IsKeyPressed(DIK_LEFT))
VectorMA(gPlayer.origin,-7,right,gPlayer.origin);
if(gApp.IsKeyPressed(DIK_RIGHT))
VectorMA(gPlayer.origin,7,right,gPlayer.origin);
}
🔒 Locked
my first engine with steering code +problem
Advertisement
Original Post
http://www.planethalflife.com/borderline/members/basiror/bas3d.zip
as you notice the move moves up and down but never stands still
is that because i check the mouse position every frame?
see underneath
I''m not downloading 1.4meg just for a random question, exactly what is the problem? I''m guessing that you are talking about the mouse cursor flickering up and down rather than being rock steady. This is due to the mouse event handling being done in a completely different place to your programs thread (probably a separate blocked thread or an interrupt basis). The windowing system draws the mouse cursor on a completely different time basis (probably directly it senses the movement) therefore the mouse cursor will be drawn at it''s new position then redrawn when you reset it. Just hide the mouse cursor if it bothers you.
If this isn''t the problem then sorry. The code looks like it should do what you mean it to do.
If this isn''t the problem then sorry. The code looks like it should do what you mean it to do.
I think I know what your problem is.
The camera continues to move even after you stop moving the mouse?
If I am right about your problem then changing this
if(x==cursorpos.x && y==cursorpos.y)
return;
deltax=(float)(x - cursorpos.x)*-0.01;
deltay=(float)(y - cursorpos.y)*-0.01;
to this
if(x==cursorpos.x && y==cursorpos.y)
return;
if(x!=cursorpos.x)
deltax=(float)(x - cursorpos.x)*-0.01;
if(y!=cursorpos.y)
deltay=(float)(y - cursorpos.y)*-0.01;
This is because x can equal the x cursopos, while y doesn''t. In this situation your code moves both x and y. Now y equals corsorpos.y and x doesn''t, you kinda get caought in a loop there.
Jason Mickela
ICQ : 873518
Excuse my speling.
Vallejo Punk
The V-Town Have-Nots
Eskapo
"I don''t have to take this, I''m going to where I''m appreciated, my mom''s house"
The camera continues to move even after you stop moving the mouse?
If I am right about your problem then changing this
if(x==cursorpos.x && y==cursorpos.y)
return;
deltax=(float)(x - cursorpos.x)*-0.01;
deltay=(float)(y - cursorpos.y)*-0.01;
to this
if(x==cursorpos.x && y==cursorpos.y)
return;
if(x!=cursorpos.x)
deltax=(float)(x - cursorpos.x)*-0.01;
if(y!=cursorpos.y)
deltay=(float)(y - cursorpos.y)*-0.01;
This is because x can equal the x cursopos, while y doesn''t. In this situation your code moves both x and y. Now y equals corsorpos.y and x doesn''t, you kinda get caought in a loop there.
Jason Mickela
ICQ : 873518
Excuse my speling.
Vallejo Punk
The V-Town Have-Nots
Eskapo
"I don''t have to take this, I''m going to where I''m appreciated, my mom''s house"
griffenjam, that's actually *worse* than his way, your way deltax or deltay could be used uninitialized
Notice if x == cursorpos.x then (x - cursorpos.x) == 0.0, in which case deltax will not affect the outcome at all.
Ok, I've broken down and am downloading the code...
EDIT:
Ok, I see what the problem is now, the view continues to drift upwards no matter what happens, yes?
Hmm, I don't see why in that code, what about your rendering setup code?
As a side note: good work on the engine, an option to set the screen mode to less than 1280x1024 would be *very* useful, we don't all have 19" monitors
[edited by - JuNC on November 1, 2002 8:32:59 AM]
Notice if x == cursorpos.x then (x - cursorpos.x) == 0.0, in which case deltax will not affect the outcome at all.
Ok, I've broken down and am downloading the code...
EDIT:
Ok, I see what the problem is now, the view continues to drift upwards no matter what happens, yes?
Hmm, I don't see why in that code, what about your rendering setup code?
As a side note: good work on the engine, an option to set the screen mode to less than 1280x1024 would be *very* useful, we don't all have 19" monitors
[edited by - JuNC on November 1, 2002 8:32:59 AM]
gCamera.MoveCamera();
gCamera.MovePlayer();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f,(GLfloat)1280/(GLfloat)1024,32.0f,60000.0f);
//glRotatef(0.4,0,1,0);
glRotatef(gPlayer.viewangle[0],1,0,0);
glRotatef(gPlayer.viewangle[1],0,1,0);
//glTranslatef(-gPlayer.origin[0],gPlayer.origin[2],-gPlayer.origin[1]);
glTranslatef(-2000,-256,2000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
int i=0;
int a=0;
int s=2;
int iMode=0;
int iOldMode=0;
vec3_t dir;
vec3_t forward,right,up;
AngleVectors(gPlayer.viewangle,forward,right,up);
forward[0]=-forward[0];
forward[1]=-forward[1];
forward[2]=-forward[2];
//if(gApp.polygonstack)
//return;
glBindTexture(GL_TEXTURE_2D, gApp.texture.texID);
float d;
d=-DotProduct(gCamera.forward,gPlayer.origin);
if(gApp.polygonstack){
for(i=0;i<gApp.m_iPolygons;i++)
{
if(gApp.polygonstack[i].m_iVertices==3)
{
iMode=GL_TRIANGLES;
}
else if(gApp.polygonstack[i].m_iVertices==4)
{
iMode=GL_QUADS;
}
else if(gApp.polygonstack[i].m_iVertices>4)
{
iMode=GL_TRIANGLE_FAN;
}
if(gApp.polygonstack[i].m_iVertices>2)
{
//VectorSubtract(gApp.polygonstack[i].v[0].p,gPlayer.origin,dir);
//VectorNormalize(dir);
if(1)//DotProduct(gCamera.forward,gApp.polygonstack[i].v[0].p)+d>0)
{
glBegin(iMode);
for(a=0;a<gApp.polygonstack[i].m_iVertices;a++)
{
if(iMode!=GL_TRIANGLE_FAN)
glTexCoord2f(texcoord[a][0],texcoord[a][1]);
glVertex3f(
gApp.polygonstack[i].v[a].p[0],//x
gApp.polygonstack[i].v[a].p[1],//z
-gApp.polygonstack[i].v[a].p[2]//y
);
}
glEnd();
}
}
}
}glCullFace(GL_BACK);
glPushMatrix();
glTranslatef(gPlayer.origin[0],gPlayer.origin[2],gPlayer.origin[1]);
DrawSky();
glPopMatrix();glCullFace(GL_FRONT);
Hmm, this looks like a tricky thing (or maybe I'm just blind). I'd suggest checking all of your math routines and make sure you have all the array indices correct, the thing I'm looking at goes something like this:
I'd guess you declare your player structure like this:
struct Player
{
vec3_t origin;
vec3_t angles;
};
Now, if in some function you are doing
origin[3] += 3; // 3 is just some random example number
Then you will constantly be incrementing angles[0]. Now, I can't see it being done in any of the code there, but you call quite a few functions which operate on the vectors and it's a very easy typo to make.
EDIT:
Aggh! I just spotted you are putting the camera transform in the PROJECTION matrix - BAD! Although this isn't your problem, make sure you rearrange things:
[edited by - JuNC on November 2, 2002 7:43:09 AM]
I'd guess you declare your player structure like this:
struct Player
{
vec3_t origin;
vec3_t angles;
};
Now, if in some function you are doing
origin[3] += 3; // 3 is just some random example number
Then you will constantly be incrementing angles[0]. Now, I can't see it being done in any of the code there, but you call quite a few functions which operate on the vectors and it's a very easy typo to make.
EDIT:
Aggh! I just spotted you are putting the camera transform in the PROJECTION matrix - BAD! Although this isn't your problem, make sure you rearrange things:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f,(GLfloat)1280/(GLfloat)1024,32.0f,60000.0f);
//glRotatef(0.4,0,1,0);
glRotatef(gPlayer.viewangle[0],1,0,0);
glRotatef(gPlayer.viewangle[1],0,1,0);
//glTranslatef(-gPlayer.origin[0],gPlayer.origin[2],-gPlayer.origin[1]);
glTranslatef(-2000,-256,2000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f,(GLfloat)1280/(GLfloat)1024,32.0f,60000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//glRotatef(0.4,0,1,0);
glRotatef(gPlayer.viewangle[0],1,0,0);
glRotatef(gPlayer.viewangle[1],0,1,0);
//glTranslatef(-gPlayer.origin[0],gPlayer.origin[2],-gPlayer.origin[1]);
glTranslatef(-2000,-256,2000);
[edited by - JuNC on November 2, 2002 7:43:09 AM]
Well, you''re going to have to do some work narrowing down where the problem is occuring. Start by disabling the code which reads the mouse, if the problem still occurs, work through all the areas where you modify the viewangles or the players origin (it''s definitely modifying the viewangles because the movement is affected). It could be that the GetCursor/SetCursor calls are acting screwy but it''s bizarre why it should only affect the Y axis.
Conventionally you put *only* the screen projection transformation in the PROJECTION matrix. Any other space transforms (ie the camera rotation/translation and object positioning) go into MODELVIEW (hence the name - MODEL VIEW). It still works if you put the camera in the PROJECTION (as you''ve found) but it is not the correct way.
Conventionally you put *only* the screen projection transformation in the PROJECTION matrix. Any other space transforms (ie the camera rotation/translation and object positioning) go into MODELVIEW (hence the name - MODEL VIEW). It still works if you put the camera in the PROJECTION (as you''ve found) but it is not the correct way.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement