Some questions

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
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Some questions

Post by thetaf »

Hi ! Another irrlicht user here with some questions waiting for answers! :D

Question 1 :
I have the following code for my hero's movement :

Code: Select all

 
void move(ISceneNode* node,const vector3df<f32>& add)
{
        node->setPosition(node->getPosition() + add);
}
 
if(keys[up])
        move(hero,vector3df(0,0,10.0f * elapsed);
 
if(keys[down])
        move(hero,vector3df(0,0,-(10.0f * elapsed));
 
 
But there is a big problem with it : my hero doesn't follow a straight path relative to its current rotation :(
Can anyone tell me what's wrong with it?

Question 2 :
Which is the best way to fire a projectile at a specified target so that it will produce smooth movement ?

Thanks for any help!
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Some questions

Post by serengeor »

But there is a big problem with it : my hero doesn't follow a straight path relative to its current rotation
Can anyone tell me what's wrong with it?
Why would he?
You didn't make him follow it and he didn't bother to do so on its own :D
Question 2 :
Which is the best way to fire a projectile at a specified target so that it will produce smooth movement ?
Get a start point, end point. Subtract end point from start point and normalize the new vector. You'll have a direction in which your projectile should go. Then you just multiply that direction vector by velocity and delta time.
Or you can use irrlicht's 'fly straight' animator.
Working on game: Marrbles (Currently stopped).
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Re: Some questions

Post by blAaarg »

Answer 1:

Look into rotationToDirection() and use its return vector scaled before sending it as the second parameter to move().
I don't recall if you'll need to normalize it first.

Answer 2:

Subtract the shooter's position from the target's position. (Otherwise, you'll shoot backwards). Then call move() on the projectile the same way you did to the hero. What the projectile does when it hits or misses is up to you.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Some questions

Post by thetaf »

Thanks both of you.
Look into rotationToDirection() and use its return vector scaled before sending it as the second parameter to move().
I don't recall if you'll need to normalize it first.
Oh my god , thank you , that's exactly what i wanted and works as expected !!! :D


As for question 2 :
Get a start point, end point. Subtract end point from start point and normalize the new vector. You'll have a direction in which your projectile should go. Then you just multiply that direction vector by velocity and delta time.
Or you can use irrlicht's 'fly straight' animator.
Subtract the shooter's position from the target's position. (Otherwise, you'll shoot backwards). Then call move() on the projectile the same way you did to the hero. What the projectile does when it hits or misses is up to you.

So if i get it right , its just :

When adding the projectile to my array :

Code: Select all

 
vector3df<f32> source = hero->getPosition();
vector3df<f32> destination = source - target->getPosition();
destination = destination.normalize();
 
 
Then in update code of the projectile array:

Code: Select all

 
source += (destination * velocity) * elapsed;
 
?
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Re: Some questions

Post by blAaarg »

No, sorry. What I meant by "subtract...from" was:

Code: Select all

vector3df<f32> destination = target->getPosition() - source;  // the shooter is the 'source'
not

Code: Select all

vector3df<f32> destination = source - target->getPosition();
Although, I would not have chosen the name 'source' to represent the position of a moving projectile :wink: , as long as your update code has access to 'source', I do believe that should work. :)

Hopefully, I understood that correctly and that helps.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Some questions

Post by thetaf »

Thanks for making it clear.

My hero can't use his gear yet , so i haven't tested the above code.... but i will do so after im done
with the controls!
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Some questions

Post by thetaf »

By the way , im facing another issue.
I can't get the directx drivers to work but the opengl.I think its because of codeblock's compiler , because i can use fine all drivers with ms vc :? .

Any idea how to fix this :?:
Brainsaw
Posts: 1242
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: Some questions

Post by Brainsaw »

The default codeblocks project does only include the OpenGL driver. There is a tutorial on the wiki (http://irrlicht3d.org/wiki/index.php?n= ... 9WithMinGW) on how to compile Irrlicht with DirectX using MinGW.
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Some questions

Post by thetaf »

Thank you!
It took me some time :oops: but got it to work :D
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Some questions

Post by thetaf »

I have another problem.Im making a zelda tile game clone to 3d ;but when im generating the world i get this :
Image

The tile texture is this :
Image

And the code is this :

Code: Select all

 
void generateDungeon(int sx,int sy,int sz,int tileSize)
{
        vector3df scale = vector3df(tileSize,tileSize,tileSize);
 
        /*
                [][][][][][][]
                [][][][][][][]
                [][][][][][][]
                [][][][][][][]
                [][][][][][][]
        */
 
        for(int i = 0;i<sy;i++)
        {
                int h = i * tileSize;
 
                for(int j = 0;j<sx;j++)
                {
                        int w = j * tileSize;
 
                        for(int k = 0;k<sz;k++)
                        {
                                ISceneNode* tile = smgr->addCubeSceneNode();
                                setTexture(tile,"test.bmp");
                                setLighting(tile,false);
                                setScale(tile,scale);
                                setPosition(tile,vector3df(k * tileSize,height , w));
                        }
                }
        }
}
 
What am i doing wrong the dungeon is rendered like this :?: :cry:
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Some questions

Post by serengeor »

You didn't read carefully how cube is created :P

Code: Select all

virtual IMeshSceneNode *        addCubeSceneNode (f32 size=10.0f, ISceneNode *parent=0, s32 id=-1, const core::vector3df &position=core::vector3df(0, 0, 0), const core::vector3df &rotation=core::vector3df(0, 0, 0), const core::vector3df &scale=core::vector3df(1.0f, 1.0f, 1.0f))=0
///Adds a cube scene node.
When you skipped the first default parameter it created a cube of size 10, then you scaled it 10 times so the cube size is now 100.
Working on game: Marrbles (Currently stopped).
thetaf
Posts: 12
Joined: Sun Mar 27, 2011 4:50 pm

Re: Some questions

Post by thetaf »

serengeor wrote:You didn't read carefully how cube is created :P

Code: Select all

virtual IMeshSceneNode *        addCubeSceneNode (f32 size=10.0f, ISceneNode *parent=0, s32 id=-1, const core::vector3df &position=core::vector3df(0, 0, 0), const core::vector3df &rotation=core::vector3df(0, 0, 0), const core::vector3df &scale=core::vector3df(1.0f, 1.0f, 1.0f))=0
///Adds a cube scene node.
:oops: :oops:
serengeor wrote: When you skipped the first default parameter it created a cube of size 10, then you scaled it 10 times so the cube size is now 100.

It worked by passing 1.0f to the addCubeSceneNode function :D
Post Reply