protected override void OnRender() { Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0); Device.BeginScene(); Device.SetTransform(TransformState.View, Freelook.View); foreach (CollisionObject colObj in PhysicsContext.World.CollisionObjectArray) { if (colObj.CollisionShape.ShapeType == BroadphaseNativeType.SoftBodyShape) { if (IsDebugDrawEnabled) { continue; } Device.Material = softBodyMaterial; Device.SetTransform(TransformState.World, Matrix.Identity); MeshFactory.RenderSoftBody(colObj as SoftBody); } else { RigidBody body = colObj as RigidBody; Device.SetTransform(TransformState.World, body.MotionState.WorldTransform); RenderWithMaterial(body); } } DebugDrawWorld(); Fps.OnRender(FramesPerSecond); Device.EndScene(); Device.Present(); }
protected override void OnRender() { Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0); Device.BeginScene(); Device.SetTransform(TransformState.View, Freelook.View); foreach (RigidBody body in PhysicsContext.World.CollisionObjectArray) { Device.SetTransform(TransformState.World, body.WorldTransform); RenderWithMaterial(body); if (Physics.HasDistanceResult) { Device.Material = ActiveMaterial; Device.SetTransform(TransformState.World, Matrix.Identity); PositionColored[] vertices = new PositionColored[2]; vertices[0] = new PositionColored(Physics.distanceFrom, -1); vertices[1] = new PositionColored(Physics.distanceTo, -1); Device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices); } } DebugDrawWorld(); Fps.Text = string.Format( "Move using mouse and WASD+shift\n" + "F3 - Toggle debug\n" + "F11 - Toggle fullscreen\n" + "Distance: {0}", Physics.distance.ToString("0.00")); Fps.OnRender(FramesPerSecond); Device.EndScene(); Device.Present(); }
protected override void OnRender() { Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0); Device.BeginScene(); foreach (RigidBody body in PhysicsContext.World.CollisionObjectArray) { Device.SetTransform(TransformState.World, body.MotionState.WorldTransform); RenderWithMaterial(body); } DebugDrawWorld(); Fps.OnRender(FramesPerSecond); Device.EndScene(); Device.Present(); }
protected override void OnRender() { Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0); Device.BeginScene(); Matrix trans = Physics.vehicle.ChassisWorldTransform; Vector4 pos = trans.get_Rows(3); Vector3 pos2 = new Vector3(pos.X, pos.Y, pos.Z); // Set View matrix based on view mode if (ViewMode == 1) { Matrix view = Matrix.LookAtLH(new Vector3(30, 20, 30), pos2, Vector3.UnitY); Device.SetTransform(TransformState.View, view); } else if (ViewMode == 2) { Freelook.SetEyeTarget(pos2 + new Vector3(30, 10, 0), pos2); Device.SetTransform(TransformState.View, Freelook.View); } Device.Material = wheelMaterial; int i; for (i = 0; i < Physics.vehicle.NumWheels; i++) { //synchronize the wheels with the (interpolated) chassis worldtransform //Physics.vehicle.UpdateWheelTransform(i, true); //draw wheels (cylinders) trans = Matrix.RotationY((float)Math.PI / 2); trans *= Physics.vehicle.GetWheelInfo(i).WorldTransform; Device.SetTransform(TransformState.World, trans); wheel.DrawSubset(0); } DebugDrawWorld(); foreach (RigidBody body in PhysicsContext.World.CollisionObjectArray) { if (body.CollisionShape.ShapeType == BroadphaseNativeType.TerrainShape && ground.Equals(body.UserObject)) { Device.SetTransform(TransformState.World, Matrix.Identity); Device.Material = GroundMaterial; groundMesh.DrawSubset(0); continue; } if (chassis.Equals(body.UserObject)) { Device.SetTransform(TransformState.World, body.WorldTransform); Device.Material = bodyMaterial; MeshFactory.Render(body); continue; } Device.SetTransform(TransformState.World, body.MotionState.WorldTransform); RenderWithMaterial(body); } Fps.OnRender(FramesPerSecond); Device.EndScene(); Device.Present(); }