Game Development Community

Have fun with JigLibX.

by b2fxna · in Torque X 3D · 12/10/2009 (11:49 pm) · 23 replies

Step by step:
1) In VS new project Starter Game 3D.
2) Check out JigLibX from svn: http://jiglibx.codeplex.com/SourceControl/ListDownloadableCommits.aspx
3) Add JiglibX project to current solution. ( it comes with a dll project, a game project, a heightmap processor, just add the dll project only, the game project is a good reference for integration)
4) Right click upgrade JigLibX if needed ( to 3.1 )
5) In the game add reference, select project, point to JiglibX.
6) Add these 2 files to Game project: J3DRigidComponent.cs, JRigidCollisionManager.cs
7) In game data: levelData.txscene change this:
- RigidManager:
Before: <RigidManager type="GarageGames.Torque.T3D.RigidCollision.RigidCollisionManager" name="RigidManager" />

After: <RigidManager type="JigLibX.Rigid.JRigidCollisionManager" name="RigidManager" />
- Terrain:
Before:
<Components>
<SceneComponent type="GarageGames.Torque.T3D.T3DSceneComponent"/>
<RigidComponent type="GarageGames.Torque.T3D.T3DRigidComponent">
.... collision shape....
</RigidComponent>
</Components>
After:
<Components>
<SceneComponent type="GarageGames.Torque.T3D.T3DSceneComponent">
<SceneGroup>Terrain</SceneGroup>
</SceneComponent>
<TerrainCollision type="JigLibX.Rigid.J3DRigidTerrainComponent">
<SceneGroupName>Terrain</SceneGroupName>
<RigidManager nameRef="RigidManager"/>
</TerrainCollision>
</Components>
8) in Game.cs in BeginRun add 2 func at the last line:
protected override void BeginRun() {
...
TestSimpleBall();
TestSimpleVehicle();
}
9) Here the 2 function:
void TestSimpleBall()
{
JRigidCollisionManager rigidManager =
TorqueObjectDatabase.Instance.FindObject<JRigidCollisionManager>("RigidManager");

TorqueObject ball = new TorqueObject();
ball.Name ="Ball";
T3DSceneComponent ballScene = new T3DSceneComponent();
ballScene.SceneGroup = "Ball";
ballScene.Position = new Vector3(1024, 1024, 400);
ball.Components.AddComponent(ballScene);
T3DSphere ballShape = new T3DSphere();
ballShape.Radius = 1.0f;
ballShape.SceneGroupName = "Ball";
SimpleMaterial material = new SimpleMaterial();
material.TextureFilename = @"dataskiesfront";
ballShape.Material = material;
ball.Components.AddComponent(ballShape);

J3DRigidSphereComponent ballPhysics = new J3DRigidSphereComponent();
ballPhysics.RigidManager = rigidManager;
ballPhysics.Radius = ballShape.Radius;
ballPhysics.SceneGroupName = "Ball";

ball.Components.AddComponent(ballPhysics);

TorqueObjectDatabase.Instance.Register(ball);
}

void TestSimpleVehicle()
{
JRigidCollisionManager rigidManager =
TorqueObjectDatabase.Instance.FindObject<JRigidCollisionManager>("RigidManager");
SimpleMaterial material = new SimpleMaterial();
material.TextureFilename = @"dataskiesfront";

String name = "body";
TorqueObject body = new TorqueObject();
body.Name = name;
T3DSceneComponent bodyScene = new T3DSceneComponent();
bodyScene.SceneGroup = name;
bodyScene.Position = new Vector3(1024, 1024, 300);
body.Components.AddComponent(bodyScene);

T3DBox bodyShape = new T3DBox();
bodyShape.SceneGroupName = name;
bodyShape.Size = new Vector3(1.0f, 1.0f, 1.0f);
bodyShape.Material = material;
body.Components.AddComponent(bodyShape);

J3DRigidVehicleComponent physics = new J3DRigidVehicleComponent();
physics.SceneGroupName = name;
physics.RigidManager = rigidManager;
body.Components.AddComponent(physics);
TorqueObjectDatabase.Instance.Register(body);

//-----------------------------------------------

name = "brWheel";
TorqueObject brWheel = new TorqueObject();
brWheel.Name = name;
T3DSceneComponent brWheelSceneComponent = new T3DSceneComponent();
brWheelSceneComponent.SceneGroup = name;
brWheel.Components.AddComponent(brWheelSceneComponent);

T3DSphere brWheelBody = new T3DSphere();
brWheelBody.Material = material;
brWheelBody.SceneGroupName = name;
brWheelBody.Radius = 0.4f;
brWheel.Components.AddComponent(brWheelBody);
TorqueObjectDatabase.Instance.Register(brWheel);

//-----------------------------------------------
name = "frWheel";
TorqueObject frWheel = new TorqueObject();
frWheel.Name = name;
T3DSceneComponent frWheelSceneComponent = new T3DSceneComponent();
frWheelSceneComponent.SceneGroup = name;
frWheel.Components.AddComponent(frWheelSceneComponent);

T3DSphere frWheelBody = new T3DSphere();
frWheelBody.Material = material;
frWheelBody.SceneGroupName = name;
frWheelBody.Radius = 0.4f;
frWheel.Components.AddComponent(frWheelBody);
TorqueObjectDatabase.Instance.Register(frWheel);

//-----------------------------------------------
name = "blWheel";
TorqueObject blWheel = new TorqueObject();
blWheel.Name = name;
T3DSceneComponent blWheelSceneComponent = new T3DSceneComponent();
blWheelSceneComponent.SceneGroup = name;
blWheel.Components.AddComponent(blWheelSceneComponent);

T3DSphere blWheelBody = new T3DSphere();
blWheelBody.Material = material;
blWheelBody.SceneGroupName = name;
blWheelBody.Radius = 0.4f;
blWheel.Components.AddComponent(blWheelBody);
TorqueObjectDatabase.Instance.Register(blWheel);

//-----------------------------------------------
name = "flWheel";
TorqueObject flWheel = new TorqueObject();
flWheel.Name = name;
T3DSceneComponent flWheelSceneComponent = new T3DSceneComponent();
flWheelSceneComponent.SceneGroup = name;
flWheel.Components.AddComponent(flWheelSceneComponent);

T3DSphere flWheelBody = new T3DSphere();
flWheelBody.Material = material;
flWheelBody.SceneGroupName = name;
flWheelBody.Radius = 0.4f;
flWheel.Components.AddComponent(flWheelBody);
TorqueObjectDatabase.Instance.Register(flWheel);

physics.BRWheel = brWheelSceneComponent;
physics.FRWheel = frWheelSceneComponent;
physics.BLWheel = blWheelSceneComponent;
physics.FLWheel = flWheelSceneComponent;
}
10)in FreeCameraComponent add this to protected virtual void _SetupInputMap()
// V:Gas B:Brake N:Left M:Right
_inputMap.BindMove(keyboardId, (int)Keys.V, MoveMapTypes.TriggerDigital, 0);
_inputMap.BindMove(keyboardId, (int)Keys.B, MoveMapTypes.TriggerDigital, 1);
_inputMap.BindMove(keyboardId, (int)Keys.N, MoveMapTypes.StickDigitalLeft, 2);
_inputMap.BindMove(keyboardId, (int)Keys.M, MoveMapTypes.StickDigitalRight, 2);
11) in FreeCamera add Gas and Turn.
public float Gas = 0;
public float Turn = 0;

public void ProcessTick(Move move, float elapsed)
{
if (move == null)
return;

Gas = move.Triggers[0].Value - move.Triggers[1].Value;
Turn = -move.Sticks[2].X;

That is it. Run the game now and you can enjoy JiblibX.

Files:
Game.cs _http_://www.mediafire.com/?zyjzndxattn
J3DRigidComponent.cs _http_://www.mediafire.com/?tnlgvbojw2z
JRigidManager.cs _http_://www.mediafire.com/?jmzmgvy4jyd
level _http_://www.mediafire.com/?d3zmnm4nzw4
Page«First 1 2 Next»
#21
08/01/2010 (12:09 pm)
I would also add that I do not believe that TX is thread safe (I hope I am saying that correctly) I think it sometimes spins off threads as well. I'd hate to have threads bumping.
#22
08/15/2010 (5:43 am)
I just looked at this again and yea I'd like to have some sort of physics like jiglibx, as long as it didn't impact the performance too much.
#23
02/17/2011 (2:59 pm)
Hello Henry,

The link no longer works (I know I repeat myself :p). Does the file is still available?
Page«First 1 2 Next»