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.

Dark GDK / Move/rotate camera with keys/mouse

Author
Message
theagg
16
Years of Service
User Offline
Joined: 11th Feb 2008
Location:
Posted: 13th Feb 2008 20:11
A simple routine for moving the camera forwards/backwards, left/right with keys ( the usual arrows or WSAD ). ( Note, not rotating with the left/right arrows, AD keys but moving it ) would be appreciated.

Added to that, pointing the camera in the desired direction of travel using the mouse.

In other words, Standard FPS stuff.

Thanks
D Bellis
18
Years of Service
User Offline
Joined: 6th Jul 2006
Location: UK
Posted: 13th Feb 2008 20:29
if you look through the examples i.e. the FPS mini game you would find this code in there plus a lot of other good FPS based code

Amd Athlon 64 3000+ Newcastle , Asus K8N4-E Deluxe, 1.50GB DDR Ram , XFX Geforce 6600 Extreame Edition 512MB DDR2 Ram
GDK,DarkPhysics,DarkShader,DarkLights,DarkAI,BlueGUI,Unity
theagg
16
Years of Service
User Offline
Joined: 11th Feb 2008
Location:
Posted: 13th Feb 2008 21:17
Aye, straight after posting the message, I did find the "rotate camera with mouse" code in the 'Game Level' tutorial. Don't know how I missed that !

What I could not find however in that example, was how to slide the camera left/right using the keys ( I can see that this is used in the "Dark Dungeon" sample but do not know how to browse the code for that, given its an .exe file.
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 14th Feb 2008 00:43
im just heading to bed so I wont be giving my usual in-depth code examples this time (sorry! if you still have trouble tomorrow then I will after work ) but the functions you want to slide (strafe) the camera are dbNewXValue() and dbNewZValue().

These two commands (and there is one for Y too but you dont need that in this case) calculate a new position along the x and z values based off the current value, an angle given and a distance value saying how much to move.

In short it can be read as: give me the position I would be in if I move from this position in the direction of this angle and I go this far.

The same can be acheived using sin/cos math but these functions make it easier. In the case of your camera you want to slide left and right. If you think about it thats just moving along a line 90 degrees from the current angle of the camera, so we can just say something like:

float fSideAngleLeft = dbWrapValue(dbCameraAngleY(0) - 90.0f);
float fSideAngleRight = dbWrapValue(dbCameraAngleY(0) + 90.0f);
float fDistanceToMove = 1.5f;

float fNewX = dbCameraPositionX(0);
float fNewZ = dbCameraPositionZ(0);

if (user pressing left key) {
fNewX = dbNewXValue(dbCameraPositionX(0), fSideAngleLeft, fDistanceToMove);
fNewZ = dbNewZValue(dbCameraPositionZ(0), fSideAngleLeft, fDistanceToMove);
} else {
if (user pressing right key) {
fNewX = dbNewXValue(dbCameraPositionX(0), fSideAngleRight, fDistanceToMove);
fNewZ = dbNewZValue(dbCameraPositionZ(0), fSideAngleRight, fDistanceToMove);
}
}

dbPositionCamera(0, fNewX, dbCameraPositionY(0), fNewZ);

There, if I havnt made some sleepy mistake that should work (sigh, guess I wrote the code anyway huh? ). dbWrapValue() just keeps a value between 0 and 360 and wraps it around so you always get a "real angle" that makes sense. I store off the current X and Z positions of the camera in the new position variables first incase the user presses no keys (then it will just position the camera at its current location with no problems).

the left and right angles are just the current rotation of the camera plus and minus 90 degrees as nessiary. The rest I think I already explained

Hope that helps!

CoffeeGrunt
17
Years of Service
User Offline
Joined: 5th Oct 2007
Location: England
Posted: 14th Feb 2008 01:08
I'm trying to do the same with an edited version of the terrain level, (using custom terrain maps and textures, etc). I've tried lots of ways of going about it but how would I merege this Code:


With this Code:


My thanks to any who reply...

D Bellis
18
Years of Service
User Offline
Joined: 6th Jul 2006
Location: UK
Posted: 14th Feb 2008 02:03
the code to Dark Dungeon is in you examples folder also

my path is

C:\Program Files\The Game Creators\Dark GDK\Samples\Visual Studio 9

Amd Athlon 64 3000+ Newcastle , Asus K8N4-E Deluxe, 1.50GB DDR Ram , XFX Geforce 6600 Extreame Edition 512MB DDR2 Ram
GDK,DarkPhysics,DarkShader,DarkLights,DarkAI,BlueGUI,Unity
CoffeeGrunt
17
Years of Service
User Offline
Joined: 5th Oct 2007
Location: England
Posted: 14th Feb 2008 02:19
Thanks mate, I'm now 1 step closer to my C++ FPS Dream....

blargmob
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location:
Posted: 14th Feb 2008 04:10
You can rotate the camera like that, but it isn't genuine. When you move the mouse slightly and the camera rotates, it rotates by a chunk. Where in a real FPS, the camera will rotate angle by angle i.e. pixel by pixel in the crosshair.

I'm still trying to figure out how to truly rotate the cam.

"I used to have a handle on life, but it broke."

Login to post a reply

Server time is: 2024-11-20 01:13:40
Your offset time is: 2024-11-20 01:13:40