Ejemplo n.º 1
0
        void SpawnObject()
        {
            var cache = GetSubsystem <ResourceCache>();

            Node boxNode = scene.CreateChild("Sphere");

            boxNode.Position = CameraNode.Position;
            boxNode.Rotation = CameraNode.Rotation;
            boxNode.SetScale(bulletSize[sizeCount]);
            StaticModel boxObject = boxNode.CreateComponent <StaticModel>();

            boxObject.Model = cache.Get <Model>("Models/Sphere.mdl");
            boxObject.SetMaterial(cache.Get <Material>("Materials/StoneSmall.xml"));
            boxObject.CastShadows = true;

            RigidBody body = boxNode.CreateComponent <RigidBody>();

            body.Mass            = bulletMass[massCount];
            body.RollingFriction = 0.15f;
            CollisionShape shape = boxNode.CreateComponent <CollisionShape>();

            shape.SetSphere(1.0f, Vector3.Zero, Quaternion.Identity);

            float objectVelocity = bulletSpeed[speedCount];

            // Set initial velocity for the RigidBody based on camera forward vector. Add also a slight up component
            // to overcome gravity better
            body.SetLinearVelocity(CameraNode.Rotation * new Vector3(0.0f, bulletArc, 1.0f) * objectVelocity);
        }
Ejemplo n.º 2
0
        void InitWheel(string name, Vector3 offset, out Node wheelNode, out uint wheelNodeId)
        {
            // Note: do not parent the wheel to the hull scene node. Instead create it on the root level and let the physics
            // constraint keep it together
            wheelNode          = Scene.CreateChild(name);
            wheelNode.Position = Node.LocalToWorld(offset);
            wheelNode.Rotation = Node.Rotation * (offset.X >= 0.0 ? new Quaternion(0.0f, 0.0f, -90.0f) : new Quaternion(0.0f, 0.0f, 90.0f));
            wheelNode.Scale    = new Vector3(0.8f, 0.5f, 0.8f);
            // Remember the ID for serialization
            wheelNodeId = wheelNode.ID;

            StaticModel    wheelObject     = wheelNode.CreateComponent <StaticModel>();
            RigidBody      wheelBody       = wheelNode.CreateComponent <RigidBody>();
            CollisionShape wheelShape      = wheelNode.CreateComponent <CollisionShape>();
            Constraint     wheelConstraint = wheelNode.CreateComponent <Constraint>();

            wheelObject.Model = (Application.ResourceCache.GetModel("Models/Cylinder.mdl"));
            wheelObject.SetMaterial(Application.ResourceCache.GetMaterial("Materials/Stone.xml"));
            wheelObject.CastShadows = true;
            wheelShape.SetSphere(1.0f, Vector3.Zero, Quaternion.Identity);
            wheelBody.Friction             = (1.0f);
            wheelBody.Mass                 = 1.0f;
            wheelBody.LinearDamping        = 0.2f;  // Some air resistance
            wheelBody.AngularDamping       = 0.75f; // Could also use rolling friction
            wheelBody.CollisionLayer       = 1;
            wheelConstraint.ConstraintType = ConstraintType.Hinge;
            wheelConstraint.OtherBody      = GetComponent <RigidBody>();                              // Connect to the hull body
            wheelConstraint.SetWorldPosition(wheelNode.Position);                                     // Set constraint's both ends at wheel's location
            wheelConstraint.SetAxis(Vector3.UnitY);                                                   // Wheel rotates around its local Y-axis
            wheelConstraint.SetOtherAxis(offset.X >= 0.0 ? Vector3.UnitX : new Vector3(-1f, 0f, 0f)); // Wheel's hull axis points either left or right
            wheelConstraint.LowLimit         = new Vector2(-180.0f, 0.0f);                            // Let the wheel rotate freely around the axis
            wheelConstraint.HighLimit        = new Vector2(180.0f, 0.0f);
            wheelConstraint.DisableCollision = true;                                                  // Let the wheel intersect the vehicle hull
        }
Ejemplo n.º 3
0
 public override void SetTo(CollisionShape shapeComponent)
 {
     shapeComponent.SetSphere(diameter, position, rotation);
 }