Several Questions

Discuss any questions about BEPUphysics or problems encountered.
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Several Questions

Post by lareusoular »

First, sorry for my bad english...

So, my name is Lucas, I'm the creator of the LarX game engine, if you want to see a video of my editor, http://www.youtube.com/watch?v=FGuDtv5H1vk

I'm trying to change my old Physics System to bEPU, but I'm having some problems:

How to make an object IMMOVABLE? Don't apply gravity, just check for collisions... Tried BecomeKinematic() but the object keep falling... And I'm using TeletransportTo to move the Body...
How can I get the Scale values of the Entity? Is there a Vector3 with all the props, or am I going to need to make a class for every Entity? Cause Box has Width,Height and Lenght, instead of one Vector3 of Size.
I need the scale for serializing. The Position and Rotation I'm getting with the Vector3.Transform Method, transforming the World and Orientation Matrix to Vectors..

Ok, that's it for now!

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

Re: Several Questions

Post by Norbo »

The engine is looking good :)
How to make an object IMMOVABLE?
Kinematic entities have infinite inertia, so they are good options for static geometry. Kinematic entities can also move if you directly change their velocity, but gravity/collisions cannot change their velocity. Changing a dynamic entity to a kinematic entity will preserve whatever velocity the dynamic entity had by design. If you set the kinematic entity's LinearVelocity and AngularVelocity to zero, it will stop moving.

While calling BecomeKinematic is one way to make an entity kinematic, you can also create them as kinematic initially. All entities have multiple constructors, some of which take a mass parameter, and some that do not. The ones that do not take a mass parameter will create a kinematic entity.
And I'm using TeletransportTo to move the Body...
I'm not clear on exactly how the TeleportTo is being used here, but be careful. An object will happily allow itself to be teleported through other objects without obeying collisions. This is because TeleportTo is truly teleporting the entity, Star Trek style. If you want to control the motion of an entity, using velocities is the best option. Collisions will correct penetrating velocities as necessary, preventing objects from ignoring each other.

Basically, TeleportTo and setting the position in general is good for when you're actually teleporting with the intent to ignore collisions- otherwise, use velocities.
How can I get the Scale values of the Entity? Is there a Vector3 with all the props, or am I going to need to make a class for every Entity? Cause Box has Width,Height and Lenght, instead of one Vector3 of Size.
Universal local scaling is not available in v0.14.1. Scale would need to be handled on a per-type basis. v0.15.0 includes significant redesigns to most of the engine which will let local scaling be implemented. If it isn't ready for v0.15.0, it will be put into the subsequent version. It won't be ready for some time, though.
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

Thanks for the comment, and for the fast reply!
Norbo wrote:
How to make an object IMMOVABLE?
Kinematic entities have infinite inertia, so they are good options for static geometry. Kinematic entities can also move if you directly change their velocity, but gravity/collisions cannot change their velocity. Changing a dynamic entity to a kinematic entity will preserve whatever velocity the dynamic entity had by design. If you set the kinematic entity's LinearVelocity and AngularVelocity to zero, it will stop moving.
In my editor, for tests, what I want to do is create a plane, and a box above it...
So, I make a box, and I have to make it -1 Position, so I change the Pos.Y to - 1, the code Pos is using is this:
public Vector3 Pos
{
get
{
Vector3 scale; Vector3 pos; Quaternion qua;
Object.WorldTransform.Decompose(out scale, out qua, out pos);
return pos;
}
set
{
Object.TeleportTo(value);
}
}
When I use it, the Box starts moving down, even if the mass is 0.

After, I try to set Kinematic to true, the code is:
public bool Kinematic
{
get { return !Object.IsDynamic; }
set
{
if (value)
{
Object.BecomeKinematic();
Object.LinearVelocity = Vector3.Zero;
Object.AngularVelocity = Vector3.Zero;
}
else
{
Object.BecomeDynamic(Mass);
}
}
}

But the box seems to continue falling, but I cant see it....
And, I create the box with: new Box(Vector3.Zero, 1, 1, 1)

I can change the values of Position and Rotation in Realtime. But, what can I do with the Scale?
My PhysicActor class is kinda like that:
It has an Entity Object:
public Entity Object;
In its constructors, it gets an Entity:
public BepuActorPlayer(Entity Entity...)
{
this.Object = Entity;
}
In the Draw, it pass the parameters to the Actor, that has the model to draw:
Engine.Render.AddModelToDraw(Actor.World, Actor.Model, Actor.Material, Actor.Changes);
Actor.Position = Vector3.Transform(Actor.Position, Object.WorldTransform);
Actor.RotationMatrix = Object.OrientationMatrix;
Actor.VectorRotation = Vector3.Transform(Actor.VectorRotation, Object.OrientationMatrix);
Vector3 scale; Vector3 pos; Quaternion qua;
Object.WorldTransform.Decompose(out scale, out qua, out pos);
Actor.Scale = scale;


Will I have to create several classes, like BoxBepuActorPlayer(Box Box...), TriangleMeshActorPlayer(TriangleMesh Mesh...), just because I can't access the Scale?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Several Questions

Post by Norbo »

In my editor, for tests, what I want to do is create a plane, and a box above it...
But the box seems to continue falling, but I cant see it....
I can't tell exactly what is going wrong; I'd recommend trying some stripped down versions of the configuration in a demo of the BEPUphysicsDemos project. Stripping away all the extra stuff should make it easier to analyze the behavior.
Will I have to create several classes, like BoxBepuActorPlayer(Box Box...), TriangleMeshActorPlayer(TriangleMesh Mesh...), just because I can't access the Scale?
BEPUphysics entities have no concept of "scale" at this time, so you're left with configuring the individual shape properties of each entity. Each entity type has different properties. Boxes have width/length/height, but a sphere just has radius, and a capsule has radius and length, and so on. The TriangleMesh is not an entity and actually does have a full WorldMatrix which can include deformations like scale.

There are a variety of ways to deal with this problem. A descriptive class per entity type is one option, although you will not be able to extract 'scale' from all entities' properties even with special cases.
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

So, I came back :D

And, now, I'm using bEPU, it's working well, at least for now :D

I can make an object Kinematic, but I don't know how to make one thing:
I can get the scale of the object
I can get the rotation of the object

But how can I get the Position(Vector3) of the Object? I'm needing it for serializing...

EDIT: Going to try Matrix.Decompose(), but it doesn't work really well with me...
Ah, and I'm getting the Object Rotation by doing this:
public Vector3 BodyRotation
{
get
{
Vector3 sca; Quaternion rot; Vector3 pos;
Box.WorldTransform.Decompose(out sca, out rot, out pos);
return QuaternionToEuler(rot);
}
}
public Vector3 QuaternionToEuler(Quaternion rotation)
{
float q0 = rotation.W;
float q1 = rotation.Y;
float q2 = rotation.X;
float q3 = rotation.Z;

Vector3 radAngles = new Vector3();
radAngles.Y = (float)Math.Atan2(2 * (q0 * q1 + q2 * q3), 1 - 2 * (Math.Pow(q1, 2) + Math.Pow(q2, 2)));
radAngles.X = (float)Math.Asin(2 * (q0 * q2 - q3 * q1));
radAngles.Z = (float)Math.Atan2(2 * (q0 * q3 + q1 * q2), 1 - 2 * (Math.Pow(q2, 2) + Math.Pow(q3, 2)));

Vector3 angles = new Vector3();
angles.X = MathHelper.ToDegrees(radAngles.X);
angles.Y = MathHelper.ToDegrees(radAngles.Y);
angles.Z = MathHelper.ToDegrees(radAngles.Z);
return radAngles;
}

Is that right?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Several Questions

Post by Norbo »

Entity.CenterPosition :)

The WorldTransform property is actually created directly from the OrientationMatrix and CenterPosition. Referencing those properties directly would be easier than decomposing the matrix.

Edit: There's also an OrientationQuaternion property if you need a quaternion representation.
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

And, how can I set a value for the rotation? Is there a way?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Several Questions

Post by Norbo »

All of those properties can be set.

The properties that are prefixed with Internal are not buffered, which means you will see the result of your set immediately. On the other hand, buffered property sets will be applied at the beginning of the next frame (when the write buffer is flushed).
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

Norbo wrote:All of those properties can be set.

The properties that are prefixed with Internal are not buffered, which means you will see the result of your set immediately. On the other hand, buffered property sets will be applied at the beginning of the next frame (when the write buffer is flushed).
But, for example:
I have a Manipulator on my editor, that adds a value to the Rotation Vector3 of the actor, to rotate it.

In the bEPU Entity class, there is no rotation vector, for position I don't need to decompose the Matrix, but for Rotation I still do...
So, for example:
Actually, my Rotation value is like this:
public Vector3 Rotation
{
get
{
Vector3 sca; Quaternion rot; Vector3 pos;
Entity.WorldTransform.Decompose(out sca, out rot, out pos);
return QuaternionToEuler(rot);
}
set
{

}
}

What should I put in the Set Method?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Several Questions

Post by Norbo »

The triple-angle representation does require some decomposition, but just 'compose' the angles into a Matrix or Quaternion in the same but opposite manner in which you 'decompose' the Matrix or Quaternion into angles.

This requires making some arbitrary choices on your end on how you actually handle the angles. I prefer completely avoiding triple angles :)
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

Norbo wrote:The triple-angle representation does require some decomposition, but just 'compose' the angles into a Matrix or Quaternion in the same but opposite manner in which you 'decompose' the Matrix or Quaternion into angles.

This requires making some arbitrary choices on your end on how you actually handle the angles. I prefer completely avoiding triple angles :)
Hey, I did that, then I entered here again :D
hehe, it's working with Matrix.CreateFromYawPicthRow(value.x, value....)

Thanks for all the help!
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

I'm uploading a video to YouTube, when it's ready I will post here :D
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

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

Re: Several Questions

Post by Norbo »

Neat :)
lareusoular
Posts: 40
Joined: Mon Sep 06, 2010 9:22 pm

Re: Several Questions

Post by lareusoular »

Norbo wrote:Neat :)
Thanks, I'm going to finish the Collision system here, and then I will post my Balad video :D
Post Reply