I have been writing a level editor for our games. It now supports adding objects with multiple components (i.e. 2+ physics bodys) so I can for instance add a fan that has 2 dynamic bodys, one for the fan blade and another for the bases body, Now in the editor I can rotate the object and any other components will rotate around correctly so even thou it can be made of 10 physics bodys it can be rotated as one piece... now that has all worked fine so far but now I am having a problem with getting it to work with rotating the revolute joint that spins the fan around...
How would you go about this as I am not sure this is the best way.
This is the code I currently use to constuct the fan.
in_ is the prefix I use for variable that have been passed into the build function.
Code: Select all
Bodys.Add(new Box(new Vector3(0, 2, 0), 2f, 4f, 2f, 50));
Bodys[0].mass = 0;//Settings.Mass;
Bodys[0].dynamicFriction = 1.0f;
Bodys[0].staticFriction = 1.0f;
InitialPartStats.Add(new EntityPartStat(new Vector3(0, 0, 0), Quaternion.Identity));
Bodys.Add(new Box(new Vector3(0, 2, 1.2f), 0.5f, 4f, 0.1f, 5));
//Bodys[1].mass = 0;
Bodys[1].dynamicFriction = 1.0f;
Bodys[1].staticFriction = 1.0f;
InitialPartStats.Add(new EntityPartStat(new Vector3(0, 0, 1.2f), Quaternion.Identity));
RevoluteJoint axisJoint = new RevoluteJoint(Bodys[0], Bodys[1], (Bodys[0].centerPosition + Bodys[1].centerPosition) / 2, Vector3.Forward);
axisJoint.motor.isActive = true;
axisJoint.motor.settings.velocityMotor.goalVelocity = 30;
axisJoint.motor.settings.maximumForce = 200;
Constrants.Add(axisJoint);
Position = in_Position; //NOTE THIS IS THE PROPERTY FROM BELOW
for (int i = 0; i < Bodys.Count; i++)
{
if (!(g_LevelEditor.GET.GetEditorState != EditorStateType.EDITING && Settings.RenderOnlyInDebug))
g_EntityManager.GET.space.add(Bodys[i]);
Bodys[i].tag = this;
Bodys[i].internalCenterPosition = in_Position + InitialPartStats[i].StartingPosition;
Bodys[i].internalOrientationQuaternion = in_Rotation + InitialPartStats[i].StartingRotation;
Bodys[i].isActive = !Settings.StartAsleep;
}
for (int i = 0; i < Constrants.Count; i++)
g_EntityManager.GET.space.add(Constrants[i]);
Code: Select all
public Vector3 Position
{
get { return Bodys[0].internalCenterPosition; }
set
{
Vector3 OldPos = Bodys[0].internalCenterPosition;
Bodys[0].internalCenterPosition = value;
for (int i = 1; i < Bodys.Count; i++)
{
Vector3 Diff = Bodys[i].internalCenterPosition - OldPos;
Bodys[i].internalCenterPosition = value + Diff;
}
}
}
public Quaternion Rotation
{
get { return Bodys[0].internalOrientationQuaternion; }
set
{
Bodys[0].internalOrientationQuaternion = value;
for (int i = 1; i < Bodys.Count; i++)
{
Bodys[i].internalCenterPosition = Bodys[0].internalCenterPosition + Vector3.Transform(InitialPartStats[i].StartingPosition, Matrix.CreateFromQuaternion(Bodys[0].internalOrientationQuaternion));
Bodys[i].internalOrientationQuaternion = Bodys[0].internalOrientationQuaternion * InitialPartStats[i].StartingRotation;
}
}
}
Anyway I hope you can help me it you have the time
I have been trying to get multi-object rotation to work for a few days now...
Also please take a look at a screenshot of a few very early development images.
(Note: Its all programmer art at the moment, but that will change soon as we have just hired 2 artists and a sound guy)
Screenshot at this link...
http://www.2point0studios.com/images/GamePreview.jpg
Thanks again for your help!