Page 1 of 1
Rolling a sphere in one specific direction(add angular force
Posted: Fri Mar 02, 2012 7:35 pm
by fredlllll
Yeah i have a sphere and i want to control it with my wasd keys.
but i dont want to add a linear force, but an angular force.
so the sphere itself spins and is not shoved over the floor.
how can i translate a vector3 pointing in one direction to the angular force i want to add?
computing with vectors has been a while >.< so i dont know what to do. maybe someone can help me here.
Re: Rolling a sphere in one specific direction(add angular f
Posted: Fri Mar 02, 2012 9:22 pm
by Norbo
An entity's angular velocity is stored such that the direction of the vector is the axis of rotation and the magnitude of the vector is the speed of rotation (in radians). So if you wanted to perform a full revolution per second around the x axis, the angular velocity would be (6.28, 0, 0).
So, if you want to move linearly in direction X, and you have an Up vector, the angular velocity needed to get there would be parallel to Vector3.Cross(X, Up). If you normalize that and multiply it by your desired angular acceleration, you can add it to the angular velocity to accelerate in that direction.
Re: Rolling a sphere in one specific direction(add angular f
Posted: Fri Mar 02, 2012 9:29 pm
by fredlllll
well but i have a vector3 like (1.3/0.5/0) so how do i use this?
and what method should i use? i use BEPUphysics.Entities.Entity for my physic object
Re: Rolling a sphere in one specific direction(add angular f
Posted: Fri Mar 02, 2012 9:34 pm
by Norbo
well but i have a vector3 like (1.3/0.5/0) so how do i use this?
That depends on what that vector represents and what you want to do with it. If you mean it's a direction of desired linear motion, then take the cross product of it and the up vector (watch out, cross product order matters; if you get a spin going in the opposite direction, flip the order of the parameters). Normalize the result. Scale by angular acceleration. Add to the AngularVelocity.
and what method should i use? i use BEPUphysics.Entities.Entity for my physic object
There's a few options on the entity. The AngularVelocity property is probably the most intuitive to use. AngularMomentum is similar, but it's the velocity scaled by the inertia tensor. So instead of using accelerations, you'd be dealing with torques. Then there's the ApplyAngularImpulse which can do something similar to the AngularMomentum property but has some extra parameters.
I would recommend just using the AngularVelocity.
Re: Rolling a sphere in one specific direction(add angular f
Posted: Fri Mar 02, 2012 11:36 pm
by fredlllll
i hope i can use that. for now im not finished with the levels, so i cant test it
now a little offtopic question
how can i scale this entity? well in this case its a sphere. but it also can be a box or a cylindre or a dynamic or static mesh. is there a way to scale these? cause these steerable spheres should have different sizes(as every other model loaded into this class can have) so im loading a model with radius 5 and create a sphere with radius 5. how can i scale the entity?
Re: Rolling a sphere in one specific direction(add angular f
Posted: Sat Mar 03, 2012 12:10 am
by Norbo
Every entity shape has the relevant scaling properties. A sphere shape can be uniformly 'scaled' by changing the radius. A cylinder has height and radius. A cone has height and radius. A box has width, height, and length. (And so on.)
If you want universal nonuniform scaling, you can create a TransformableShape. Wrapping a shape in a TransformableShape will be tiny, tiny bit slower though. If at all possible, I would recommend just using the most direct shape without wrapping.
Re: Rolling a sphere in one specific direction(add angular f
Posted: Sat Mar 03, 2012 1:12 am
by fredlllll
well i found another way for the scaling thing. thx
as the game is not playable yet i cant test that angular velocity thing. so maybe ill come back ;3 but it should work