how to create automatic move without keypress in 3d world
elo!!! i have created a 3d world and i want to remove the keypress so that it would automatically move by itself like a screensaver is this possible??? this is the code for moving forward MoveCamera(speed); bounce += speed/1.2f; i'm trying to put a counter so that it would stop like this: int x=0; while(x<5){ MoveCamera(speed); bounce += speed/1.2f; x++; } but it won't stop because the code "MoveCamera(speed); bounce += speed/1.2f;" is moving forward without stopping so it cannot reach the "x++;"
what do u mean with "is moving forward without stopping" ?
anyway, try with a bit of debug. and if u declare at every renderinc cycle the variable x, the while will never stop.
try this:
void Render(){
// other rendering stuff
static float bounce = 0;
MoveCamera(bounce);
bounce += speed/1.2f;
if(bounce > 5)
bounce = 0;
// other rendering stuff
}
anyway, try with a bit of debug. and if u declare at every renderinc cycle the variable x, the while will never stop.
try this:
void Render(){
// other rendering stuff
static float bounce = 0;
MoveCamera(bounce);
bounce += speed/1.2f;
if(bounce > 5)
bounce = 0;
// other rendering stuff
}
i mean the code "MoveCamera(speed);" when u remove the keypress it will just move forward without stopping. i've tried the code that you have give to me it still won't stop it just keep on moving forward.
the code for moving is this...
all i want to do is remove all the keypress then set a path or a way so that it would automatically move w/o keypress like a screensaver
[/source]
[Edited by - wyvern10 on October 9, 2004 5:59:26 PM]
the code for moving is this...
/////////////////////////////////////////// Moves camera in current direction/////////////////////////////////////////void GameMain(){ gluLookAt(Player.xPos, Player.yPos+0.2*sin(bounce), Player.zPos, Player.xPos + (50.0f*(GLfloat)cos(Player.Angle)), Player.yPos + Player.yLook, Player.zPos - (50.0f*(GLfloat)sin(Player.Angle)), 0.0f, 1.0f, 0.0f);}void MoveCamera(GLdouble dStep){ GLdouble xDelta,zDelta; xDelta = dStep*cos(Player.Angle); // moves on X plane in player direction zDelta = -dStep*sin(Player.Angle); // moves on Z plane in player direction Player.xPos += (GLfloat)xDelta; // do the move on X Player.zPos += (GLfloat)zDelta; // do the move on Z if(Player.xPos > 98.0f) Player.xPos = 98.0f; // limit on +X if(Player.xPos < -98.0f) Player.xPos = -98.0f; // limit on -X if(Player.zPos > 98.0f) Player.zPos = 98.0f; // limit on +Z if(Player.zPos < -98.0f) Player.zPos = -98.0f; // limit on -Z} // END OF MoveCameravoid ProcessInput(){ if (KEYDOWN(VK_SHIFT)) speed=0.4f; // holding shift makes you run else speed=0.2f; // otherwise normal speed if (KEYDOWN(VK_UP) || KEYDOWN(VK_RBUTTON)) // up arrow or right mouse moves forward { MoveCamera(speed); bounce += speed/1.2f; // bouncy bouncy } if (KEYDOWN(VK_DOWN)) // down arrow { MoveCamera(-speed); bounce -= speed/1.2f; // bouncy bouncy } if (KEYDOWN(VK_RIGHT)) // right arrow turns player right { Player.Angle -= speed / (PI*PI); if (Player.Angle < 0.0f) Player.Angle = 6.27f; // avoids errors SetCursorPos(width - 1 - ((int)(Player.Angle * 101.7f)),mYpos); // reset cursor } if (KEYDOWN(VK_LEFT)) // left arrow turns player left { Player.Angle += speed / (PI*PI); if (Player.Angle > (2.0f * PI)) Player.Angle = 0.03f; // avoids errors SetCursorPos(width - 1 - ((int)(Player.Angle * 101.7f)),mYpos); // reset cursor } if (KEYDOWN(90)) // Z looks down { Player.yLook -= 1.0f; if (Player.yLook < -40.0f) Player.yLook = -40.0f; // limit angle down SetCursorPos(mXpos,height/2 - ((int)Player.yLook * 6)); // reset cursor } if (KEYDOWN(65)) // A looks up { Player.yLook += 1.0f; if (Player.yLook > 40.0f) Player.yLook = 40.0f; // limit angle up SetCursorPos(mXpos,height/2 - ((int)Player.yLook * 6)); // reset cursor } if (KEYDOWN(83)) // S moves up { Player.yPos += 0.2f; if (Player.yPos > 20.0f) Player.yPos = 20.0f; // limit height up } if (KEYDOWN(88)) // X moves down { Player.yPos -= 0.2f; if (Player.yPos < 0.0f) Player.yPos = 0.0f; // don't allow thru floor }}
all i want to do is remove all the keypress then set a path or a way so that it would automatically move w/o keypress like a screensaver
[/source]
[Edited by - wyvern10 on October 9, 2004 5:59:26 PM]
Quote:
Original post by wyvern10
elo!!! i have created a 3d world and i want to remove the keypress so that it would automatically move by itself like a screensaver is this possible???
this is the code for moving forward
MoveCamera(speed); bounce += speed/1.2f;
i'm trying to put a counter so that it would stop like this:
int x=0;
while(x<5){
MoveCamera(speed); bounce += speed/1.2f;
x++;
}
but it won't stop because the code "MoveCamera(speed); bounce += speed/1.2f;" is moving forward without stopping so it cannot reach the "x++;"
You are increasing bounce but moving the camera by speed.
Also, if MoveCamera() does soething similar to glTranslatef() (ie if you pass 5 on the z axis every frame, you will not keep increasing your z position every frame) then you will need to make the variable that you pass to MoveCamera either global or static.
Also if you put [ source] and [ /source] (minus the spaces) around code it will put the code into a source box, and so not make the page huge ;)
____________________________________________________________Programmers Resource Central
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement