private ActorShapeDesc _CreateShapeDescriptor(Matrix pose) { ActorShapeDesc shapeDesc = null; if (_nodeObject is IFrameMesh) { var mesh = ((IFrameMesh)_nodeObject).Mesh; shapeDesc = mesh.CreateShapeDescriptor(); if (shapeDesc == null) { shapeDesc = mesh.CreateTriangleMeshDescriptor(); } shapeDesc.Name = Name; shapeDesc.LocalPose *= pose; } else if (_nodes.Count == 1) { shapeDesc = _nodes[0]._CreateShapeDescriptor(_nodes[0].LocalPose * pose); } return(shapeDesc); }
public Actor CreateActor(Physic physic, bool dynamic, float density = 0, float mass = 0) { if (physic == null) { throw new ArgumentNullException("physic"); } ActorDesc actorDesc = _CreateActorDescription(dynamic, density, mass); if (_nodeObject is IFrameMesh || _nodes.Count == 1) { ActorShapeDesc shapeDesc = _CreateShapeDescriptor(Matrix.Identity); if (shapeDesc is WheelShapeDesc) { //Matrix pose = Matrix.Identity; //pose.set_Rows(3, shapeDesc.LocalPose.get_Rows(3)); //shapeDesc.LocalPose = pose; //pose.set_Rows(3, actorDesc.GlobalPose.get_Rows(3)); //actorDesc.GlobalPose = pose; actorDesc.GlobalPose = Matrix.RotationZ(-Numerics.PIover2) * actorDesc.GlobalPose; } if (shapeDesc != null) { if (density == 0 && dynamic) { shapeDesc.Mass = 1.0f; } actorDesc.Shapes.Add(shapeDesc); } } else { foreach (var child in _nodes) { ActorShapeDesc shapeDesc = child._CreateShapeDescriptor(child.LocalPose); if (shapeDesc != null) { if (shapeDesc is WheelShapeDesc) { //Matrix pose = Matrix.Identity; //pose.set_Rows(3, shapeDesc.LocalPose.get_Rows(3)); //shapeDesc.LocalPose = pose; shapeDesc.LocalPose = Matrix.RotationZ(-Numerics.PIover2) * shapeDesc.LocalPose; } if (density == 0 && dynamic) { var match = Regex.Match(child._tag, @"__m(?<X>\d+)((\.|_)(?<Y>\d+))?__"); if (match.Success) { shapeDesc.Mass = float.Parse(match.Groups["X"].Value + "." + match.Groups["Y"].Value); } } actorDesc.Shapes.Add(shapeDesc); } } } if (actorDesc.Shapes.Count == 0) { throw new InvalidOperationException("There are any shape present and it is not allowed create a empty actor"); } var actor = physic.CreateActor(actorDesc); this.BindTo(actor); return(actor); }