Sign in to follow this  

how to create automatic move without keypress in 3d world

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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++;"

Share this post


Link to post
Share on other sites
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

}

Share this post


Link to post
Share on other sites
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...

/////////////////////////////////////////
// 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 MoveCamera

void 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]

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this