예제 #1
0
        /// <summary>
        /// These can be specified in several different ways:
        ///
        ///1) actorDesc.density == 0, bodyDesc.mass > 0, bodyDesc.massSpaceInertia.magnitude() > 0
        ///
        ///Here the mass properties are specified explicitly, there is nothing to compute.
        ///
        ///2) actorDesc.density > 0, actorDesc.shapes.size() > 0, bodyDesc.mass == 0, bodyDesc.massSpaceInertia.magnitude() == 0
        ///
        ///Here a density and the shapes are given. From this both the mass and the inertia tensor is computed.
        ///
        ///3) actorDesc.density == 0, actorDesc.shapes.size() > 0, bodyDesc.mass > 0, bodyDesc.massSpaceInertia.magnitude() == 0
        ///
        ///Here a mass and shapes are given. From this the inertia tensor is computed.
        ///
        ///Other combinations of settings are illegal.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="dynamic"></param>
        /// <param name="shapeBuilder"></param>
        /// <param name="density"></param>
        /// <param name="mass"></param>
        /// <returns></returns>
        public Actor CreateActor(Physic physic, bool dynamic, Func <Frame, ActorShapeDesc> shapeBuilder, float density = 0, float mass = 0)
        {
            if (physic != null)
            {
                throw new NullReferenceException("Physics");
            }

            ActorDesc actorDesc = _CreateActorDescription(dynamic, density, mass);

            if (shapeBuilder != null)
            {
                foreach (var child in EnumerateNodesPosOrden())
                {
                    var shapeDesc = shapeBuilder(child);
                    if (shapeDesc != null)
                    {
                        actorDesc.Shapes.Add(shapeDesc);
                    }
                }
            }

            var actor = physic.CreateActor(actorDesc);

            this.BindTo(actor);

            return(actor);
        }
예제 #2
0
        public Actor CreateActor(Physic physic, bool dynamic, ActorShapeDesc[] shapes, float density = 0, float mass = 0)
        {
            if (physic != null)
            {
                throw new ArgumentNullException("physic");
            }

            ActorDesc actorDesc = _CreateActorDescription(dynamic, density, mass);

            foreach (var item in shapes)
            {
                actorDesc.Shapes.Add(item);
            }

            var actor = physic.CreateActor(actorDesc);

            this.BindTo(actor);

            return(actor);
        }
예제 #3
0
        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);
        }