Page 1 of 1

need help with basic physics / vectors.

Posted: Sat Jul 14, 2007 7:52 am
by marrabld
Hi, I have worked through most of the examples and I'm now trying to add a little more to them [C#].

I can make an object, move it around the map, rotate it etc. What I would now like to do is actually give it a velocity. ie kick a ball.

So my question is how do i get the get the scenemanager to keep drawing the position based on a velocity (ie push one button then keep the ball moving) cos at the moment I have to hold the button down.

I am basically hacking example 4 at the moment. i would like to basically build a billiards type game eventually.

I am a physics graduate, so i have the physics and maths concepts. I am trying to learn the programing concepts.

I have tried things like;

node.position.X = node.position.X + vel * time

where vel is just some velocity i define.

but i cant get hold of the timer in the eventhandler.
and it doesn't let me multiply node.position.X with a float (or int etc).

and even if I could get that to work, I don't want to just draw the ball once in its new calculated position, I want ts position to be continually updated after receiving only one event.

any help or direction on where to get it would be appreciated.

Posted: Sun Jul 15, 2007 2:57 am
by Cardinal4
I'm guessing

Code: Select all

node.position.X = node.position.X + vel * time
gives a compiler error? C# has something against modifying members of a property, since ISceneNode.Position is implemented using get/set property, hence you cant modify Position.X or its members directly.

Try this instead:

Code: Select all

node.position = new Vector3D(node.position.X + vel * time, node.position.Y, node.position.Z);

For letting the node continously moving, put the animation code somewhere where it will get executed every frame, like in animateNode() of a ISceneNodeAnimator, or around the SceneManager.DrawAll() in the while(device.Run()) loop (though that would be really messy code if all your animation's in the main render loop).

And putting your animation code in your own custom ISceneNodeAnimator will also solve your problem of being unable to get the time, since the animateNode(ISceneNode theNode, int timeMs) passes the current time in as a parameter.

Alternatively you could just create a static class to store a reference to IrrlichtDevice.Timer, so you can access the time anywhere in your code.

I don't use Irrlicht.Net, but I hope that was helpful. :)

Posted: Sun Jul 15, 2007 4:20 am
by marrabld
Mate, worked a treat. Thanks heaps!

the node.postion.x thing was a silly mistake on reflection.

:oops: