HELP: get position after rotate an entity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

HELP: get position after rotate an entity

Post by JusTiCe8 »

Hi everyone,

I have this:
Image
(The evil Euler angles strike back :P )

A cylinder, use as a cannon barrel, on the top of it (initial position), there is a sphere, just put at cylinder.Position.Y + Sphere.radius (= A) and a weldjoint between them.
Rotating the barrel up/down before firing the first sphere is ok (entity move with it and go away when joint is inactivated + impulse applied).

My issue is how do I get the right location of a second sphere to put it on the same spot (B) with rotated barrel (let say angle alpha like on pic) ?

I'm a bit lost between XNA stuff to do the job (according to what I've seen so far, using quaternion and/or using Vector3.Transform method would do the job) and BEPU, which doesn't have the same methods (I guess another way has been chosen in BEPUutilities class). I don't know how to use Barrel.OrientationMatrix in this case.

The initial impulse use in fact thruster code from the demo and it's work just fine: linear impulse is on the expected direction. But I don't know how to do it for spawning a new sphere in the right location, knowing there are in fact two angles (on Z and on Y, as cannon has two degree of freedom), I guess doing the job with one is almost the same on the other.

Any help would be greatly appreciated, and please note I'm not asking for a ready-to-use answer, I would like even more to get just good clues and some exercises to do myself and try to reach the solution.

Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: HELP: get position after rotate an entity

Post by Norbo »

Something like barrel.Position + barrel.OrientationMatrix.Up * (barrelHeight * 0.5) would work.

That is equivalent to barrel.Position + Matrix3x3.Transform(Vector3.Up, barrel.OrientationMatrix) * (barrelHeight * 0.5). Rotation matrices have the nice property that you can directly pull the three main axes out of their components, bypassing all the operations it would take to transform a vector.
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: HELP: get position after rotate an entity

Post by JusTiCe8 »

Norbo wrote:Something like barrel.Position + barrel.OrientationMatrix.Up * (barrelHeight * 0.5) would work.

That is equivalent to barrel.Position + Matrix3x3.Transform(Vector3.Up, barrel.OrientationMatrix) * (barrelHeight * 0.5). Rotation matrices have the nice property that you can directly pull the three main axes out of their components, bypassing all the operations it would take to transform a vector.
Thanks a lot, it almost did it :).

What's work in my case is:

Code: Select all

Barrel.Position + Barrel.OrientationMatrix.Up * (4.5f) 
with 4.5 = barrel height/2 + sphere radius.

Is there any way to get entity size related data for base shapes ? Or do we have to manage the data ourselves (for example: stored in entity tag, not very the best way but still better than global variables I guess) ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: HELP: get position after rotate an entity

Post by Norbo »

If you have a reference to a CollisionShape and you know it's a e.g. BoxShape, you could cast it to a BoxShape and then read its dimensions. Same goes for the other types. If you want a slightly more general and approximate representation of a shape's size, you could use EntityShape.GetBoundingBox.

If you're wondering how to get the Shape associated with an entity, it's stored in the Entity.CollisionInformation.Shape property.
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: HELP: get position after rotate an entity

Post by JusTiCe8 »

ok thanks ;).
Post Reply