virtual void Point(irr::core::vector3df Vec2,f32 Speed)

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
Fy_Hertz
Posts: 6
Joined: Mon Nov 07, 2005 3:39 pm

virtual void Point(irr::core::vector3df Vec2,f32 Speed)

Post by Fy_Hertz »

Hi guys,
I'm trying to add a new virtual member to the ISceneNode class.

This is the fonction:

Code: Select all

		virtual void Point(irr::core::vector3df Vec2,f32 Speed)
        {
            core::vector3df Vec = this*->getPosition();
            Vec.X+=(Speed*((Vec2.X-Vec.X)/sqrt((Vec2.X-Vec.X)*(Vec2.X-Vec.X)+(Vec2.Z-Vec.Z)*(Vec2.Z-Vec.Z))));
            Vec.Z+=(Speed*((Vec2.Z-Vec.Z)/sqrt((Vec2.X-Vec.X)*(Vec2.X-Vec.X)+(Vec2.Z-Vec.Z)*(Vec2.Z-Vec.Z))));
            Vec.Y+=(Speed*((Vec2.Y-Vec.Y)/sqrt((Vec2.Y-Vec.Y)*(Vec2.Y-Vec.Y)+(Vec2.Z-Vec.Z)*(Vec2.Z-Vec.Z))));
            this*->setPosition(Vec);   
        }
With this fonction the ISceneNode can follow a vector.
When i try to compile my program crash without any error: why ? :roll:

Otherwise, i can use this following fonction witch works correctly.

Code: Select all

void Point(irr::scene::ISceneNode* Node,irr::core::vector3df Vec2,f32 Speed)
{
      core::vector3df Vec = Node->getPosition();
      Vec.X+=(Speed*((Vec2.X-Vec.X)/sqrt((Vec2.X-Vec.X)*(Vec2.X-Vec.X)+(Vec2.Z-Vec.Z)*(Vec2.Z-Vec.Z))));
      Vec.Z+=(Speed*((Vec2.Z-Vec.Z)/sqrt((Vec2.X-Vec.X)*(Vec2.X-Vec.X)+(Vec2.Z-Vec.Z)*(Vec2.Z-Vec.Z))));
      Vec.Y+=(Speed*((Vec2.Y-Vec.Y)/sqrt((Vec2.Y-Vec.Y)*(Vec2.Y-Vec.Y)+(Vec2.Z-Vec.Z)*(Vec2.Z-Vec.Z))));
      Node->setPosition(Vec);   
}

++
"Un seul oiseau est en cage et la liberté est en deuil"
Guest

Post by Guest »

core::vector3df Vec = this*->getPosition();

wtf you do here? this->getPosition
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

it should just be getPosition and setPosition, no need for the this operator. However, when using the this operator, it is a pointer to yourself, so you could do this - (*this).getPosition, or this->getPosition. I'm unsure how this*->getPosition even compiles!
Image
Fy_Hertz
Posts: 6
Joined: Mon Nov 07, 2005 3:39 pm

Post by Fy_Hertz »

Okay, It works now but only if my function isn't virtual.

Actually this:

Code: Select all

virtual void A()
{

}
makes my program crash too !

Why do i can't add virutal fonction ?
"Un seul oiseau est en cage et la liberté est en deuil"
FlyHigh
Posts: 111
Joined: Wed Mar 23, 2005 12:05 am

Post by FlyHigh »

You are linking against the correct (modified) library file and not the standard one arn't you?
Guest

Post by Guest »

PEOPLE!!! why dont you start learning c++ before you start coding games.... god damn it. but well, its your choice (you dont come far with that)
Fy_Hertz
Posts: 6
Joined: Mon Nov 07, 2005 3:39 pm

Post by Fy_Hertz »

heu... well... that's not going to help me :roll:
"Un seul oiseau est en cage et la liberté est en deuil"
Post Reply