Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / camera movements

Author
Message
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 25th Jan 2009 01:36
i created these two functions and the point of them is to move a camera forwards and backwards in either the direction you are facing or for backwards the opposite direction. the forwards function works but the backwards function only does one movement then stops instead of continuing on it the direction. here's my code:

void movecameraforward(int direction, int speed)
{
int camx=dbCameraPositionX();
int camz=dbCameraPositionZ();
float x=dbSin(direction)*speed;
float z=dbCos(direction)*speed;
dbPositionCamera ( camx+x, dbCameraPositionY(), camz+z );

void movecamerabackward(int direction, int speed)
{
int camx=dbCameraPositionX();
int camz=dbCameraPositionZ();
float x=dbSin(direction)*speed;
float z=dbCos(direction)*speed;
dbPositionCamera ( camx-x, dbCameraPositionY(), camz-z );


void DarkGDK ( void )
{
dbSetWindowSize ( 1024, 768 );
dbSetWindowPosition(0,0);
dbSyncOn ( );
dbSyncRate ( 60 );

while ( LoopGDK ( ) )
{

//make objects
dbMakeObjectCube ( 2, 10 );

//camera movements
if (dbUpKey())
{
movecameraforward(dbCameraAngleZ(), 1);
}
if (dbDownKey())
{
movecamerabackward(dbCameraAngleZ(), 1);
}
}
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 25th Jan 2009 10:56 Edited at: 25th Jan 2009 10:57
It doesn't fit together with why the forward function works, but the sole errorous thing I can find in there is that you select the manual synchronisation mode but then do not perform the updates yourself. You would have to put in dbSync(); at the end of your main loop I think.

Edit: Hey, by the way, does that actually compile?
You haven't added any curly brackets to end your camera movement functions?

"We know some things about poodles, for example that they are alive, they can bark, they eat meat..."
- Extract from Objects first with Java.
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 25th Jan 2009 13:36 Edited at: 25th Jan 2009 13:41
Here try this way:

Complete source code.



EDIT: Fixed a typo.
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 25th Jan 2009 21:16
wow pillarofire that worked thank you. i just have one question. why does it work?
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 25th Jan 2009 21:52
thanks to your help the first function worked but only for speeds of two or greater.how do you make it so it runs with a speed of less than 2?
I attempted to make it work like this but i was unsuccessful.



I think the problem is that calls doesn't equal 0 at the start but i dont know how to only make it equal 0 the first time it is used.
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 27th Jan 2009 04:16
help?

Login to post a reply

Server time is: 2024-11-16 01:11:19
Your offset time is: 2024-11-16 01:11:19