Terrain placement ?'s

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
jfisher446
Posts: 11
Joined: Mon Mar 14, 2011 10:48 am

Terrain placement ?'s

Post by jfisher446 »

So I came across Irrlicht 12 hours ago and have been non-stop since. It seems to be exactly everything I've been looking for to get started...however, there's one issue. I'm placing terrain to get a feel of what I can do and what I'm shooting for is a Simcity-ish sort of look. Turns out I'm just not 'getting' and can't really find any information regarding positions. I've used 3ds Max and 3d programs before but when setting positions for the terrain and the camera I'm just plugging random numbers in until I get what I want.
Anyone able to direct me to some reading that would help me understand? This is my first time programming 3D and even working with floats but I think I've got the floats down.
Exactly what I'm not getting is here:

Code: Select all

	   scene::ITerrainSceneNode* terrain2 = smgr->addTerrainSceneNode(
                "terrain-heightmap.bmp",
                0,                                      // parent node
                -1,                                     // node id
                vector3df(0.f, 100.f, 250.f),         // position
                vector3df(0.f, 0.f, 0.f),         // rotation
                vector3df(1.f, 1.f, 1.f),      // scale
                SColor ( 255, 255, 255, 255 ),   // vertexColor
                5,                                      // maxLOD
                ETPS_17,                         // patchSize
                5                                       // smoothFactor
                );
and here:

Code: Select all

		scene::ICameraSceneNode* camera =
                smgr->addCameraSceneNode(0,
				vector3df(200.f,200.f,200.f),
				vector3df(10.f,0.f,0.f),
				-1,
				true);
Specifically where the vector3df's are called for...currently random numbers I worked in, but I'm shooting to learn how to tile and/or zoom in enough to where the terrain will fill the screen, then be scrollable, and getting the correct angle on it (to be a NSEW defaults and also user rotatable.)
I don't need the code, just an explanation or a good link. Thanks a lot.
pe_ank
Posts: 13
Joined: Wed May 26, 2010 5:11 pm

Post by pe_ank »

yupz...you've been set up the position of terrain and the camera node, but you didn't set up the target position/ target node. so i guess the camera is pointing to somewhere else, not your terrain, forgive me if i'm wrong besides i'm just a newbie either.
just read the irrlicht documentation, or try the tutorial first.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

http://irrlicht.sourceforge.net/docu/cl ... _node.html

The constructor.
http://irrlicht.sourceforge.net/docu/cl ... 6abefebc6f

You'll want to be able to move and rotate the camera later on, which is not easy to code to make it behave the way you want it to. I'm also making a simulation game, and this is what I have for my camera code. It's not very efficient, and there might be some issues with very small texture coordinates getting truncated due to the many operations, but it's the best I could come up with.

(PS: And you might want to switch rotz with rotx and z with x... I think I set up my game on the "wrong" axis. :shock:)

(PPS: I always send -z to this function instead of z)

(PPPS: You need to reset the camera position by calling camera->setUpVector. The camera up direction is set to (0, -1, 0).)

(PPPPS: When constructing, my initial camera values are all 0 since they change every frame anyway. My camera field of view is 60 degrees. Don't forget to set that, too, via "camera->setFOV(fov);".)

Code: Select all

/* ----------------------------------------------------------------------------
support function by rogerborg
*/
void IrrRotateVectorAroundAxis (vector3df & vector, const vector3df & axis, f32 radians) {
 quaternion MrQuaternion;
 matrix4 MrMatrix;
 (void)MrQuaternion.fromAngleAxis(radians, axis);
 MrMatrix = MrQuaternion.getMatrix();
 MrMatrix.rotateVect(vector);
}

/* ----------------------------------------------------------------------------
 Set the camera to the desired rotx/roty/rotz/x/y/z values.
*/

void IrrSetCamera ( irr::scene::ICameraSceneNode* camera,
                               float rotx, float roty, float rotz,
                               float x, float y , float z) {

    camera->setTarget (vector3df(0, 0, 0));
    camera->setPosition (vector3df(0,0,1));

    // Work out the 3 axes for the camera.
    vector3df forward = (camera->getTarget() - camera->getPosition()).normalize();
    vector3df up = camera->getUpVector();
    vector3df right = forward.crossProduct(up);
    core::vector3df pos = camera->getPosition();
    pos += x * right + y * up;
    camera->setPosition(pos);
    camera->setTarget (pos + forward);
    camera->setUpVector (up);


    forward = (camera->getTarget() - camera->getPosition()).normalize();
    up = camera->getUpVector ();
    right = forward.crossProduct (up);
    pos = camera->getPosition ();
    IrrRotateVectorAroundAxis (up, forward, rotz);
    camera->setPosition (pos);
    camera->setTarget (pos + forward);
    camera->setUpVector (up);


    forward = (camera->getTarget() - camera->getPosition()).normalize();
    up = camera->getUpVector ();
    right = forward.crossProduct (up);
    pos = camera->getPosition ();
    IrrRotateVectorAroundAxis (forward, up, rotx);
    camera->setPosition (pos);
    camera->setTarget (pos + forward);
    camera->setUpVector(up);


    forward = (camera->getTarget() - camera->getPosition()).normalize();
    up = camera->getUpVector ();
    right = forward.crossProduct (up);
    pos = camera->getPosition ();
    IrrRotateVectorAroundAxis (forward, right, roty);
    IrrRotateVectorAroundAxis (up, right, roty);
    camera->setPosition (pos);
    camera->setTarget (pos + forward);
    camera->setUpVector (up);


    forward = (camera->getTarget() - camera->getPosition()).normalize();
    pos = camera->getPosition();
    pos += z * forward;
    camera->setPosition (pos);
    camera->setTarget (pos + forward);
 }
Post Reply