Need some help on some things

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.
cgcgames2
Posts: 24
Joined: Mon Jul 26, 2010 6:29 am

Need some help on some things

Post by cgcgames2 »

I looked though and couldnt find what i needed.

Ill start out with the basic stuff first. I have gone though most of the tuts.

For the most part i learned what i needed. However there is a few things i want to do and im not sure how.

1. I want a camarra that will follow and object. and im not sure if there is one that does that already or if i have to code one eighther way i am not sure where to go to code one and if there is one i dont know what the code is to use it.

2. I want to be able to make the Model rotat when the user presses a key. also when they press the key i want the model to tilt. kinda like a plane so when the key is pressed it banks when its relased it moves back to 0. I couldnt seem to find anything in the tuts that handles this.

anyway if anyone could help on those 2 things it will be great :).

Thanks,
Jordan
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Need some help on some things

Post by Seven »

cgcgames2 wrote:I want a camarra that will follow and object
see below........................
cgcgames2 wrote:2. I want to be able to make the Model rotat when the user presses a key.
you will need to create an eventreceiver and when the correct key is pressed, simply rotate the model as you wish.

Code: Select all

vector3df rotation = model->getRotation();

(when KEY_LEFT) 
{
    rotation.Y += 0.01; 
    model->setRotation(rotation);
}

Last edited by Seven on Sun Oct 17, 2010 2:24 pm, edited 1 time in total.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

// collapsed

this code can be adapted to your needs.


use like this

Code: Select all

camera->setPosition(GetPointInBackAndAbove(node,BACK_OFFSET,UP_OFFSET));
camera->setTarget(node->getPosition());
Last edited by Seven on Tue Oct 19, 2010 1:31 pm, edited 1 time in total.
cgcgames2
Posts: 24
Joined: Mon Jul 26, 2010 6:29 am

Post by cgcgames2 »

:D:D

Thanks Seven. That is alot of help. I have to go to work now but when i get back ill work on the code you gave me and see if i can get it to work :).

cgcgames
cgcgames2
Posts: 24
Joined: Mon Jul 26, 2010 6:29 am

Post by cgcgames2 »

Seven wrote:

Code: Select all

vector3df GetPointInFront(ISceneNode* node, float distance)   
{   
       vector3df p = node->getPosition(); 
       p += distance * GetIrrIn(node); 
       return p;   
}; 

vector3df GetPointInBack(ISceneNode* node,float distance)   
{   
      vector3df p = node->getPosition(); 
      p -= distance * GetIrrIn(node); 
      return p;    
};
 
vector3df GetPointAbove(ISceneNode* node,float distance)      
{   
      vector3df p = node->getPosition(); 
      p += distance * GetIrrUp(node); 
      return p;    
}; 

vector3df GetPointBelow(ISceneNode* node, float distance)      
{   
      vector3df p = node->getPosition(); 
      p -= distance * GetIrrUp(node); 
      return p;    
};
 
vector3df GetPointInFrontAndAbove(ISceneNode* node,float d, float u)    
{    
   vector3df p = GetPointInFront(node,d); 
   p.Y = GetPointAbove(node,u).Y; 
   return p;     
}; 

vector3df GetPointInBackAndAbove(ISceneNode* node,float d, float u)    
{    
   vector3df p = GetPointInBack(node,d); 
   p.Y = GetPointAbove(node,u).Y; 
   return p;     
}; 

vector3df GetIrrIn(ISceneNode* node) 
{ 
         matrix4 mat = node->getRelativeTransformation(); 
         vector3df in(mat[8],mat[9],mat[10]); 
         in.normalize(); 
         return in; 
} 

vector3df GetIrrUp(ISceneNode* node) 
{ 
         matrix4 mat = node->getRelativeTransformation(); 
         vector3df up(mat[4],mat[5],mat[6]); 
         up.normalize(); 
         return up; 
} 

vector3df GetIrrLeft(ISceneNode* node) 
{ 
        matrix4 mat = node->getRelativeTransformation(); 
         vector3df left(mat[0],mat[1],mat[2]); 
         left.normalize(); 
         return left; 
} 




this code can be adapted to your needs.


use like this

Code: Select all

camera->setPosition(GetPointInBackAndAbove(node,BACK_OFFSET,UP_OFFSET));
camera->setTarget(node->getPosition());
not quite sure how to use this code. where does the camarra code have to go.

i get the second part. but where does all the vector3df things go.
cgcgames2
Posts: 24
Joined: Mon Jul 26, 2010 6:29 am

Post by cgcgames2 »

Also. I am having some problems with loading the models. if i use mesh it doesnt seem to be able to move.

but i am not sure how i can load a model as a node. or if thats even possable. is there some way to make a mesh move or somthing?

im not sure. im really new to irrlicht so im still trying to learn its syntax hehe :).

hope you can help with those 2 things.

cgcgames
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

collapsed....
Last edited by Seven on Tue Oct 19, 2010 1:31 pm, edited 1 time in total.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

keep in mind that all of this just answers the questions you asked. You will find out as you work your way through this, that this is not the best method for creating a 3rd person camera (which is what you are attempting) however............this will be a great experience for you to work through so that you understand the camera and nodes so that you will know the next questions to ask :)

if you need any more help let me know.
cgcgames2
Posts: 24
Joined: Mon Jul 26, 2010 6:29 am

Post by cgcgames2 »

Code: Select all

// now that the node is moved to it's new location, put the camera behind and above the sphere.
camera->setPosition(getPointBehindAndAbove(node,100,40));
camera->settarget(node->getPosition()); 
got a problem with that code. saying camera is an undeclared identifyer.

apart form that it looks like it works :). um do you know how to lode a model so i can move it. i thought i might have to use custom scene node but im not sure how that works. the tut didnt really help me much on it XD :).

thanks[/quote]
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

ISceneNodeCamera* camera = smgr->addCameraSceneNode();


or something similar..........
cgcgames2
Posts: 24
Joined: Mon Jul 26, 2010 6:29 am

Post by cgcgames2 »

Code: Select all

camera->setPosition(getPointBehindAndAbove(node,100,40));
the get point behindand above doesnt work. do i need to define somthing for that to work?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

sorry, just typing into this window without a compiler.... it was a typo error. use this instead, camera->setposition(GetPointInBackAndAbove(node,100,40));



take a look at the functions i provided, maybe i should have explained them better.

when you get the 'IN' of a node, it gives you the direction that the node is 'facing'. If you multiply that by some value, it will give you a position that is 'in front' of the node by some amount.

when you get the "LEFT" of a node, it gives you a direction vector that is 90 degrees from the IN of the node.

when you get the 'UP' of a node, it will give you the direction vector that is...well, UP :) of the node.


since all of these return normalized vectors (i.e. all units are less than 1), it is simply a direction that is returned not really a point in space. for example,

vector3df in = GetIrrIn(node);
might return a vector3df that has the values (0.3,1,0.5) which represents the direction that the node is facing.

// now multiply the IN times so distance that you want to move
vector3df point = in * 100; which is really (0.3,1,0.5) * (100,100,100) or (30.0,100.0,50.0)

// you now have a value in 'point' that is really the IN (facing direction) of the node multiplied by some arbitrary value, in this case 100

// if you now add the node's current position and the new point
vector3df newposition = node->getPosition() + point; or (2,2,2) + (30.0,100.0,50.0) or (32,102,52)

//and VIOLA! you have a new position that is exactly 100 units in front of the node.

//now you set the nodes position
node->setPosition(newposition)

and you have moved the node some arbitrary distance (in this case 100) in the direction that the node was facing.



the GetPointInBackAndAbove(node,100,40); just make it easier to do by combining multiple items together.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

cgcgames2 wrote:um do you know how to lode a model so i can move it. i thought i might have to use custom scene node but im not sure how that works. the tut didnt really help me much on it XD :).
thanks
the tuts cover loading models so check through them again. you do not need a custom scenenode to load a model.
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

My guess is that you are operating on the mesh instead of the scene node. Following hello world, you must add the scene node as a mesh:

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("path to my mesh");
        if (!mesh)
        {
                device->drop();
                return 1;
        }
        IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
This code can be applied to a static mesh as well, simply switch from 'IAnimatedMesh' to 'IMesh' and from ''IAnimatedMeshSceneNode" to "ISceneNode". and call "smgr->addMeshSceneNode" rather than "addAnimatedMeshSceneNode".


After that, simply modify the scene node.
E.G:

Code: Select all


vector3df position = node->getPosition();

if(something happens to make the mesh move left)
    position.x -= MOVEMENT_SPEED * DELTA_TIME;

node->setPosition(position);



Hope it helps!
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
cgcgames2
Posts: 24
Joined: Mon Jul 26, 2010 6:29 am

Post by cgcgames2 »

Thanks guys :).

yeah i figured out what i was doing wronge last night with the movment of the mesh.

i didnt relase it was loading the mesh as a node hehe :).

thanks for all your help

cgcgames
Post Reply