Top-Down Game?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Jett
Posts: 4
Joined: Wed Jul 12, 2006 5:23 pm

Top-Down Game?

Post by Jett »

I want to make a top down game, but i dont know how to adjust the camera to do so. :cry:

Thanks in advance.
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

If your wanting a camera to hover above the map and look down, it would be rather simple:

Taken directly from Irrlicht API:

Code: Select all

virtual ICameraSceneNode* irr::scene::ISceneManager::addCameraSceneNode  (  ISceneNode *  parent = 0,  
  const core::vector3df &  position = core::vector3df(0, 0, 0),  
  const core::vector3df &  lookat = core::vector3df(0, 0, 100),  
  s32  id = -1 
 )  [pure virtual] 

Adds a camera scene node to the scene graph and sets it as active camera. 

This camera does not react on user input like for example the one created with addCameraSceneNodeFPS(). If you want to move or animate it, use animators or the ISceneNode::setPosition(), ICameraSceneNode::setTarget() etc methods. 

Parameters:
 position,:  Position of the space relative to its parent where the camera will be placed.  
 lookat,:  Position where the camera will look at. Also known as target.  
 parent,:  Parent scene node of the camera. Can be null. If the parent moves, the camera will move too.  
 id,:  id of the camera. This id can be used to identify the camera.  

Returns:
Returns pointer to interface to camera if successful, otherwise 0. This pointer should not be dropped. See IUnknown::drop() for more information. 
scene::ICameraSceneNode * camera = scene_manager->addCameraSceneNode(0,vector3df(0,1000,0),vector3df(0,0,0));

Basically you are setting the camera 1000 points in height above 0,0 point with the second parameter, and telling it to "look down" at the 0,0 point in the third parameter. I used something similar to create a mini-map, so I know it can give you a top down view. You would obviously have to adjust the "lookat" point to get the angled view then set it as a child to your model to have it follow.
elander
Posts: 193
Joined: Tue Oct 05, 2004 11:37 am

Post by elander »

The only thing left to do is to tilt the synthetic camera apropriatly and thats where things can get confusing. Heres some explanation of how the irrlicht coordinate system works.

Irrlicht uses a left-handed coordinate system so when you model something the Z direction is inverted (in relation to a right-handed cordinate system). Y is considered the up direction in Irrlicht for the FPS camera and the Maya camera.

Think of coordinates as (X,Y,Z). X axis is red, Y green and Z blue as we see in modelers. This helps remenber XYZ = RGB. Imagine the X (red) axis running horizontaly on the screen from left to right with right being the positive directon. Now rotate the X axis 90 degres in positive direction (counter-clockwise) and you will obtain the Y (green) axis running bottom to top with top being positive direction.

Ok so you probably could figure this out by yourself. The not so obvious part is identified the left-handed coordinate system.

Apply the negative cross-product to the normal vectors that represent the X and Y axis and you will obtain a vector aligned with the Z axis of the LHCS. This is how we construct it. If we applied the positive cross-product we would obtain a right-handed coordinate system.

In LHCS the Z (blue) axis is perpendicular to the screen, with the positive direction running away from the screen (running towards the screen in RHCS). The Z axis makes a 90 degree angle with the XY plane because the cross-product of A x B allways creates a vector perpendicular to A and B.

How this can help in seting the camera?

You have three methods for the camera: setPosition, setTarget and setUpVector.

When you position the camera and make it point to a certain target point the camera may still be tilted or "rotated" around its "direction" vector. The direction can be computed from it's postion and target point.

When the camera is looking down the Y axis (up view) you still need to know what direction is up in the terrain mesh (its Z+ in LHCS) and what direction is down in the terrain mesh (its Z- in LHCS) so that the camera is tilted (roated around its direction) correctly. The method setUpVector modifies an imaginary vector applied to center of the camera and perpendicular it's view direction and pointing up relative to the camera.

The correctly set your camera tilt you need to set it's up direction. Check this for more info:

http://www.cs.brown.edu/stc/summer/view ... ry_31.html

In the UVN synthetic camera coordinates the V is the up vector. The UVN coordinate system is independent of the XYZ world system.

This is the minimum to understand in order to use a camera corectlt and it doesn't imply knowing any maths, just conventions.
Jett
Posts: 4
Joined: Wed Jul 12, 2006 5:23 pm

Post by Jett »

:?
Hmm, now i understanded zeno60's explanation cause it provided code. but yours is a kinda technical, so i couldn't understand it much, now i'm new to using 3d models in programs, i can make them with basic objects. Remember i'm a beginner.

Also, any advice on how to clear the gui enviorment?
Vuen
Posts: 25
Joined: Tue Jul 11, 2006 8:03 am

Post by Vuen »

Yeah dude, all you need to do is make a camera at a high vertical (Y) value that looks down at the origin.

Code: Select all

    camera = scene->addCameraSceneNode(0, vector3df(0,100,0), vector3df(0,0,0));
Done and done. To pan it, just move the camera and target along the XZ plane. Alternatively if you want them to follow your character or your ship or something you can just attach it to whatever you want it to follow.
Jett
Posts: 4
Joined: Wed Jul 12, 2006 5:23 pm

Post by Jett »

Thanks, i wish they could make a wrapper around all of the vector stuff, so it wouldn't be so complicated, and a image or something that shows the x and y's from where you start in the hello world tutorial, cause most of the time i just modify that.

I also tried to make a gui and it was going good, but then when i tried to make it change the gui it got all messed up, and the buttons that were there before were still there.
Vuen
Posts: 25
Joined: Tue Jul 11, 2006 8:03 am

Post by Vuen »

I'm not sure how it could possibly be wrapped any further...
Post Reply