// Use this for initialization public override void XStart() { if (!isInit) { Collider = transform.GetComponent <BoxCollider>(); position = Collider.center; rotation = Collider.transform.rotation; if (transform.GetComponent <Rigidbody>() != null) { rigid = transform.GetComponent <Rigidbody>(); mass = rigid.mass; } entity = new BEPUphysics.Entities.Prefabs.Box(position.ToBEPU(), 2 * Collider.bounds.extents.x, 2 * Collider.bounds.extents.y, 2 * Collider.bounds.extents.z, mass); entity.position = transform.position.ToBEPU(); entity.Orientation = rotation.ToBEPU(); entity.LinearDamping = damping; entity.AngularDamping = angdamping; PhysicsManagerBehavior.Space.Add(entity); oldpos = entity.Position.FromBEPU(); Collider.enabled = false; this.enabled = false; isInit = true; } }
/// <summary> /// Creates a BaseModel. /// </summary> /// <param name="model">The Model to use. Cannot be null.</param> /// <param name="glass">If true, the model is rendered as glass.</param> /// <param name="mobile">True if the model is dynamic, false if kinetic. Null means /// kinetic but moves via velocity.</param> /// <param name="origin">The position of the model. Use Vector3.Zero if mobile is false.</param> public BaseModel(ModelDelegate modelDelegate, bool glass, bool? mobile, Vector3 origin) { UseCustomAlpha = false; this.modelDelegate = modelDelegate; Transform = Matrix.Identity; RenderAsGlass = glass; Origin = origin; OriginalOrientation = Quaternion.Identity; //this.ignoreLight = ignoreLight; Vector3[] verts; int[] indices; TriangleMesh.GetVerticesAndIndicesFromModel(Model, out verts, out indices); Model.Tag = this; if(mobile.HasValue) { if(mobile.Value) { // If it's mobile, it's a box! if(Model == Resources.boxModel || Model == Resources.blueBoxModel || Model == Resources.blackBoxModel) { Ent = new BEPUphysics.Entities.Prefabs.Box(Origin, 1.45f, 2.05f, 1.25f, 7); // originally 1.4x2x1.2 Ent.ActivityInformation.IsAlwaysActive = true; Ent.Material = boxMaterial; //Ent.CollisionInformation.CollisionRules.Group = dynamicGroup; Ent.CollisionInformation.CollisionRules.Group = noSolverGroupB; } else { // unless it's not a box. Ent = new BEPUphysics.Entities.Prefabs.Box(Origin, 0.592f, 1.193f, 2f, 0.05f); Ent.Material = machineMaterial; Ent.CollisionInformation.CollisionRules.Group = machineGroup; } } else { // If false, it never moves. Ent = new MobileMesh(verts, indices, AffineTransform.Identity, MobileMeshSolidity.DoubleSided); //Transform = mesh.WorldTransform.Matrix; Ent.Material = machineMaterial; // Make it slippery. Ent.CollisionInformation.CollisionRules.Group = kinematicGroup; //Transform = Ent.WorldTransform; //Ent.Position = Origin; IsTerrain = true; } } else { // If null, it is kinematic, but does move. (no longer true) //Ent = new MobileMesh(verts, indices, AffineTransform.Identity, solid ? MobileMeshSolidity.Solid : MobileMeshSolidity.Counterclockwise); Ent = new MobileMesh(verts, indices, AffineTransform.Identity, MobileMeshSolidity.DoubleSided, 30); Ent.CollisionInformation.CollisionRules.Group = machineGroup; //Ent.IsAffectedByGravity = false; Transform = Matrix.CreateTranslation(-Ent.Position); Ent.Position += Origin; Ent.Material = machineMaterial; // Make it slippery. Ent.CollisionInformation.Tag = this; } //foreach(ModelMesh mesh in internalModel.Meshes) // foreach(BasicEffect effect in mesh.Effects) // effect.EnableDefaultLighting(); //if(Ent != null) //{ OriginalOrientation = Ent.Orientation; Ent.Tag = this; //} //if(Mesh != null) // Mesh.Tag = this; }