コード例 #1
0
        public void Execute(PhysxScene scene)
        {
            if (_newShape == null)
            {
                if (_parent.Disposed || _child.Disposed) return;

                _child.Parent = _parent;

                //we need to remesh the prim and then free the old shapes
                _child.BeginDelayCommands(this);
                scene.MeshingStageImpl.QueueForMeshing(_child.SOPName, _child.Shape, _child.Size, 
                    Meshing.MeshingStage.SCULPT_MESH_LOD, _parent.IsPhysical, null, false,
                        delegate(PhysicsShape meshedShape)
                        {
                            _newShape = meshedShape;
                            scene.QueueCommand(this);
                        }
                    );
            }
            else
            {
                _parent.LinkPrimAsChildSync(_newShape, _child, _localPos, _localRot, false);
                _child.EndDelayCommands();
            }
        }
コード例 #2
0
ファイル: MasslessItem.cs プロジェクト: scastle/Solitude
        public MasslessItem(Texture2D t, PhysicsShape shape, Vector2 position, World w)
            : base(position, w, t.Width, t.Height)
        {
            texture = t;
            body.BodyType = BodyType.Static;
            body.Position = position;

            switch (shape)
            {
                case PhysicsShape.Rectangle:
                    fixture = FixtureFactory.CreateRectangle(
                        texture.Width,
                        texture.Height,
                        0.0f,
                        Vector2.Zero,
                        body);
                    break;
            }

            //fixture.CollisionFilter.IgnoreCollisionWith();

            fixture.OnCollision += new OnCollisionEventHandler(this.OnCollision);
            w.AddBody(body);

            //drawOrigin = new Vector2(texture.Width / 2, texture.Height / 2);
            //drawRectangle = new Rectangle(0, 0, texture.Width, texture.Height);
        }
コード例 #3
0
        public void Execute(PhysxScene scene)
        {
            if (_newShape == null)
            {
                if (_parent.Disposed || _child.Disposed)
                {
                    return;
                }

                _child.Parent = _parent;

                //we need to remesh the prim and then free the old shapes
                _child.BeginDelayCommands(this);
                scene.MeshingStageImpl.QueueForMeshing(_child.SOPName, _child.Shape, _child.Size,
                                                       Meshing.MeshingStage.SCULPT_MESH_LOD, _parent.IsPhysical, null, false,
                                                       delegate(PhysicsShape meshedShape)
                {
                    _newShape = meshedShape;
                    scene.QueueCommand(this);
                }
                                                       );
            }
            else
            {
                _parent.LinkPrimAsChildSync(_newShape, _child, _localPos, _localRot, false);
                _child.EndDelayCommands();
            }
        }
コード例 #4
0
        public void Write(AssetWriter writer)
        {
            Sprites.Write(writer);
            if (SpriteMetaData.HasOutline(writer.Version))
            {
                Outline.Write(writer);
            }
            if (SpriteMetaData.HasPhysicsShape(writer.Version))
            {
                PhysicsShape.Write(writer);
            }
            if (SpriteMetaData.HasBones(writer.Version))
            {
                Bones.Write(writer);
                writer.Write(SpriteID);
            }
            if (SpriteMetaData.HasInternalID(writer.Version))
            {
                writer.Write(InternalID);
            }
            if (SpriteMetaData.HasBones(writer.Version))
            {
                Vertices.Write(writer);
                Indices.Write(writer);
                Edges.Write(writer);
                writer.AlignStream();

                Weights.Write(writer);
                writer.AlignStream();
            }
            if (HasSecondaryTextures(writer.Version))
            {
                SecondaryTextures.Write(writer);
            }
        }
コード例 #5
0
ファイル: Trigger.cs プロジェクト: ModernMAK/BoEG
        private void Awake()
        {
            _collider           = GetComponent <Collider>();
            _collider.isTrigger = true;
            _boxCollider        = null;
            _sphereCollider     = null;
            _capsuleCollider    = null;
            switch (_collider)
            {
            case BoxCollider box:
                _boxCollider = box;
                _shape       = PhysicsShape.Box;
                break;

            case SphereCollider sphere:
                _sphereCollider = sphere;
                _shape          = PhysicsShape.Sphere;
                break;

            case CapsuleCollider capsule:
                _capsuleCollider = capsule;
                _shape           = PhysicsShape.Capsule;
                break;

            default:
                _shape = PhysicsShape.Invalid;
                break;
            }
        }
コード例 #6
0
        /// <summary>
        /// function checks if any collision occured and implements all calculations.
        /// </summary>
        /// <param name="shape"></param>
        internal void CollisionEffect(PhysicsShape shape)
        {
            if (IsCollideWithBottomBorder(shape, ScreenHeight))
            {
                Point point = shape.BottomVertex;
                point.Y            = ScreenHeight;
                shape.BottomVertex = point;
                SetVelocityBorderHit(shape, false);
            }

            if (IsCollideWithLeftBorder(shape, 0))
            {
                Point point = shape.LeftVertex;
                point.X          = 1;
                shape.LeftVertex = point;
                SetVelocityBorderHit(shape, true);
            }

            if (IsCollideWithRightBorder(shape, ScreenWidth))
            {
                Point point = shape.RightVertex;
                point.X           = ScreenWidth - 1;
                shape.RightVertex = point;
                SetVelocityBorderHit(shape, true);
            }
        }
コード例 #7
0
        public MasslessItem(Texture2D t, PhysicsShape shape, Vector2 position, World w)
            : base(position, w, t.Width, t.Height)
        {
            texture       = t;
            body.BodyType = BodyType.Static;
            body.Position = position;

            switch (shape)
            {
            case PhysicsShape.Rectangle:
                fixture = FixtureFactory.CreateRectangle(
                    texture.Width,
                    texture.Height,
                    0.0f,
                    Vector2.Zero,
                    body);
                break;
            }

            //fixture.CollisionFilter.IgnoreCollisionWith();

            fixture.OnCollision += new OnCollisionEventHandler(this.OnCollision);
            w.AddBody(body);

            //drawOrigin = new Vector2(texture.Width / 2, texture.Height / 2);
            //drawRectangle = new Rectangle(0, 0, texture.Width, texture.Height);
        }
コード例 #8
0
 void _shapeCache_OnShapeNeedsFreeing(PhysicsShape shape)
 {
     if (OnShapeNeedsFreeing != null)
     {
         OnShapeNeedsFreeing(shape);
     }
 }
コード例 #9
0
        // CONSTRUCTORS ----------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="Crystallography.WildCardCrystallonEntity"/> class.
        /// </summary>
        /// <param name='pScene'>
        /// The Parent Scene.
        /// </param>
        /// <param name='pGamePhysics'>
        /// Instance of <c>GamePhysics</c>
        /// </param>
        /// <param name='pTextureInfo'>
        /// <see cref="Sce.PlayStation.HighLevel.GameEngine2D.Base.TextureInfo"/>
        /// </param>
        /// <param name='pTileIndex2D'>
        /// <see cref="Sce.PlayStation.HighLevel.GameEngine2D.Base.Vector2i"/>
        /// </param>
        /// <param name='pShape'>
        /// <see cref="Sce.PlayStation.HighLevel.Physics2D.PhysicsShape"/>
        /// </param>
        public WildCardCrystallonEntity(Scene pScene, GamePhysics pGamePhysics, int pId, PhysicsShape pShape)
            : base(pScene, pGamePhysics, pId,
//			      pTextureInfo, pTileIndex2D, 
			      pShape)
        {
            Wild = true;
            Flash ();
        }
コード例 #10
0
 public void AddObject(GameObject gameObject, float mass, PhysicsShape physicsShape)
 {
     RigidBodyControl rbc = new RigidBodyControl(mass, physicsShape);
     gameObject.AddController(rbc);
     world.AddBody(rbc.Body);
     rbc.Body.EnableDebugDraw = true;
     rbc.Body.DebugDraw(debugDraw);
 }
コード例 #11
0
 public EntityType(Trajectory t, Drawable draw, PhysicsShape physS, EntityClass pc, BulletEmitter e = null, GraphicsStyle g = null)
 {
     traj         = t;
     this.draw    = draw;
     this.bounds  = physS;
     this.myClass = pc;
     emitter      = e;
     gs           = g;
 }
コード例 #12
0
        public void AddObject(GameObject gameObject, float mass, PhysicsShape physicsShape)
        {
            RigidBodyControl rbc = new RigidBodyControl(mass, physicsShape);

            gameObject.AddController(rbc);
            world.AddBody(rbc.Body);
            rbc.Body.EnableDebugDraw = true;
            rbc.Body.DebugDraw(debugDraw);
        }
コード例 #13
0
        public YAMLNode ExportYAML(IExportContainer container)
        {
            YAMLMappingNode node = new YAMLMappingNode();

            node.AddSerializedVersion(GetSerializedVersion(container.Version));
            node.Add("sprites", Sprites.ExportYAML(container));
            node.Add("outline", Outline.ExportYAML(container));
            node.Add("physicsShape", PhysicsShape.ExportYAML(container));
            return(node);
        }
コード例 #14
0
ファイル: BulletStyle.cs プロジェクト: SAProgClub/BulletHell
        public BulletStyle MakeStyle(string s, PhysicsShape p, GraphicsStyle sty)
        {
            BulletStyle ans = (t, path, pc) =>
            {
                return(new Bullet(t, path, p.MakeDrawable(sty), p, pc, null));
            };

            savedStyles[s] = ans;
            return(ans);
        }
コード例 #15
0
            private void GenerateBasicShapeAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                Tuple <PhysX.Geometry, ShapeType> result = meshingStage.GenerateBasicPhysXShape(Shape);
                PhysicsShape phyShape = new PhysicsShape(result.Item1, result.Item2, meshHash);

                //basic shapes are not cached

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
コード例 #16
0
ファイル: BulletStyle.cs プロジェクト: SAProgClub/BulletHell
        public BulletStyle MakeStyle(string s, Drawable d, PhysicsShape ps)
        {
            BulletStyle ans = (t, path, pc) =>
            {
                return(new Bullet(t, path, d, ps, pc, null));
            };

            savedStyles[s] = ans;
            return(ans);
        }
コード例 #17
0
        public EntityType ChangeShape(PhysicsShape sh, bool clone = false)
        {
            EntityType ans = this;

            if (clone)
            {
                ans = new EntityType(this);
            }
            ans.Shape = sh;
            return(ans);
        }
        internal static Vec3 CalculateCenterOfMass(PhysicsShape body)
        {
            if ((NativeObject)body == (NativeObject)null)
            {
                return(Vec3.Zero);
            }
            Vec3  zero = Vec3.Zero;
            float num1 = 0.0f;
            int   num2 = body.CapsuleCount();

            for (int index = 0; index < num2; ++index)
            {
                CapsuleData data = new CapsuleData();
                body.GetCapsule(ref data, index);
                Vec3  vec3 = (data.P1 + data.P2) * 0.5f;
                float num3 = data.P1.Distance(data.P2);
                float num4 = (float)((double)data.Radius * (double)data.Radius * 3.14159274101257 * (1.33333337306976 * (double)data.Radius + (double)num3));
                num1 += num4;
                zero += vec3 * num4;
            }
            int num5 = body.SphereCount();

            for (int index = 0; index < num5; ++index)
            {
                SphereData data = new SphereData();
                body.GetSphere(ref data, index);
                float num3 = 4.18879f * data.Radius * data.Radius * data.Radius;
                num1 += num3;
                zero += data.Origin * num3;
            }
            Vec3 vec3_1;

            if ((double)num1 > 0.0)
            {
                vec3_1 = zero / num1;
                if ((double)Math.Abs(vec3_1.x) < 0.00999999977648258)
                {
                    vec3_1.x = 0.0f;
                }
                if ((double)Math.Abs(vec3_1.y) < 0.00999999977648258)
                {
                    vec3_1.y = 0.0f;
                }
                if ((double)Math.Abs(vec3_1.z) < 0.00999999977648258)
                {
                    vec3_1.z = 0.0f;
                }
            }
            else
            {
                vec3_1 = Vec3.Zero;
            }
            return(vec3_1);
        }
コード例 #19
0
            private static PhysicsShape CreatePhysicsShapeFromTrimeshAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.TriangleMeshGeometry triMesh)
            {
                PhysicsShape phyShape;

                phyShape = new PhysicsShape(triMesh, ShapeType.TriMesh, meshHash);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.TriMesh);
                return(phyShape);
            }
コード例 #20
0
 // CONSTRUCTORS ----------------------------------------------------------
 public NodeCrystallonEntity(Scene pScene, GamePhysics pGamePhysics, PhysicsShape pShape = null)
     : base(pScene, pGamePhysics)
 {
     _node = new Node();
     if (pShape != null) {
         _body = _physics.RegisterPhysicsBody(pShape, 0.1f, 0.01f, _node.Position);
     } else {
         _body = null;
     }
     Scheduler.Instance.Schedule(_node, Update, 0, false, 0);
 }
コード例 #21
0
            private static PhysicsShape CreatePhysicsShapeFromConvexSetAndCache(MeshingStage meshingStage, ulong meshHash, List <PhysX.ConvexMeshGeometry> convexes)
            {
                PhysicsShape phyShape;

                phyShape            = new PhysicsShape(convexes, meshHash);
                phyShape.Complexity = convexes.Count;
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.DecomposedConvexHulls);
                return(phyShape);
            }
コード例 #22
0
 // CONSTRUCTORS --------------------------------------------------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="Crystallography.CardCrystallonEntity"/> class.
 /// </summary>
 /// <param name='pScene'>
 /// The Parent Scene.
 /// </param>
 /// <param name='pGamePhysics'>
 /// Instance of <c>GamePhysics</c>
 /// </param>
 /// <param name='pTextureInfo'>
 /// <see cref="Sce.PlayStation.HighLevel.GameEngine2D.Base.TextureInfo"/>
 /// </param>
 /// <param name='pTileIndex2D'>
 /// <see cref="Sce.PlayStation.HighLevel.GameEngine2D.Base.Vector2i"/>
 /// </param>
 /// <param name='pShape'>
 /// <see cref="Sce.PlayStation.HighLevel.Physics2D.PhysicsShape"/>
 /// </param>
 public CardCrystallonEntity(Scene pScene, GamePhysics pGamePhysics, int pId, PhysicsShape pShape)
     : base(pScene, pGamePhysics, pShape)
 {
     id = pId;
     _anim = null;
     GlowSprite = null;
     Scored = false;
     //			_sprite.Scale*=CARD_SCALAR;
     _sprite.Position = new Vector2(-Width/2, -Height/2);
     _keepOnScreenTimer = -1.0f;
     setVelocity(DEFAULT_SPEED, GameScene.Random.NextAngle());
 }
コード例 #23
0
            private static PhysicsShape CreatePhysicsShapeFromSingleConvexAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.ConvexMeshGeometry convex)
            {
                PhysicsShape phyShape;

                phyShape = new PhysicsShape(new List <PhysX.ConvexMeshGeometry> {
                    convex
                }, meshHash, true);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.SingleConvex);
                return(phyShape);
            }
コード例 #24
0
        // CONSTRUCTOR -----------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="Crystallography.GroupCrystallonEntity"/> class.
        /// </summary>
        /// <param name='pScene'>
        /// Instance of the parent scene.
        /// </param>
        /// <param name='pGamePhysics'>
        /// Instance of <c>GamePhysics</c>
        /// </param>
        /// <param name='pShape'>
        /// <see cref="Sce.PlayStation.HighLevel.Physics2D.PhysicsShape"/>
        /// </param>
        /// <param name='pMaxMembers'>
        /// <c>int</c> Maximum allowed population. Probs 3. 0 = no limit.
        /// </param>
        public GroupCrystallonEntity(Scene pScene, GamePhysics pGamePhysics, PhysicsShape pShape = null, 
		                             int pMaxMembers=0, bool pComplete = false)
            : base(pScene, pGamePhysics, pShape)
        {
            _maxMembers = pMaxMembers;
            _numMembers = 0;
            members = new AbstractCrystallonEntity[_maxMembers];
            _pucks = new Node[_maxMembers];
            for (int i=0; i < _maxMembers; i++) {
                AddPuck(i);
            }
            complete = pComplete;
        }
コード例 #25
0
 private void SetVelocityBorderHit(PhysicsShape shape, bool isCollideWithX)
 {
     if (isCollideWithX)
     {
         shape.Velocity.X *= (float)1 - Friction;
         shape.Velocity.X *= -1;
     }
     else
     {
         shape.Velocity.y *= (float)1 - Friction;
         shape.Velocity.y *= -1;
     }
 }
コード例 #26
0
        internal void UnrefShape(PhysicsShape shape, bool dynamic)
        {
            lock (_meshWaitingQueue)
            {
                _meshWaitingQueue.Enqueue(new UnrefShapeItem
                {
                    Shape   = shape,
                    Dynamic = dynamic
                });

                Monitor.Pulse(_meshWaitingQueue);
            }
        }
コード例 #27
0
 internal void EntitiyCollision(List <PhysicsShape> entities, PhysicsShape checkedShape)
 {
     foreach (var s in entities)
     {
         if (!s.Equals(checkedShape))
         {
             if (checkedShape is PhysicsCircle && s is PhysicsCircle)
             {
                 CircleCollision((PhysicsCircle)checkedShape, (PhysicsCircle)s);
             }
         }
     }
 }
コード例 #28
0
        public PrepChildPrimAndLinkCmd(PhysxPrim parent, PhysxPrim child, OpenMetaverse.Vector3 localPos,
            OpenMetaverse.Quaternion localRot)
        {
            Util.ThrowIfNull(parent, "parent");
            Util.ThrowIfNull(child, "child");

            _parent = parent;
            _child = child;
            _localPos = localPos;
            _localRot = localRot;
            _newShape = null;
            _affectedPrims = new List<PhysxPrim> { parent, child };
            _affectedPrims.AddRange(child.ChildShapes.Keys);
        }
コード例 #29
0
        public override PhysicsBody CreateBody(PhysicsShape shape, Vector3D initialPosition, float mass,
                                               float restitution)
        {
            PhysicsBody body = new JitterBody(this, shape, initialPosition, mass, restitution);

            bodies.Add(body);
            if (float.IsNaN(body.Position.X) || float.IsNaN(body.AngularVelocity.X) ||
                float.IsNaN(body.BoundingBox.Min.X) || float.IsNaN(body.BoundingBox.Max.X) ||
                float.IsNaN(body.GetOrientation().X))
            {
                throw new PhysicsBodyIsNotSetUpProperlyMakeSurePositionVelocityAndBoundingBoxAreSet(body);
            }
            return(body);
        }
コード例 #30
0
        static public BlockMissionObject DrawFBXMeshMissionObjectAt(Mission mission, Vec3 pos, string filename)
        {
            // if (prefab == null)

            GameEntity prefab = GameEntity.CreateEmpty(mission.Scene, false);


            prefab.EntityFlags |= EntityFlags.DontSaveToScene;

            //prefab.AddMesh(Mesh.GetFromResource("order_arrow_a"), true);

            //   prefab.SetVisibilityExcludeParents(true);

            if (MeshListByFileName.ContainsKey(filename) == false)
            {
                MeshListByFileName.Add(filename, CreateMesh(filename));
            }
            foreach (var mesh in MeshListByFileName[filename])
            {
                prefab.AddMesh(mesh, false);
            }
            prefab.RecomputeBoundingBox();
            PhysicsShape shape = prefab.GetBodyShape();

            // shape.
            prefab.AddPhysics(1000, new Vec3(0, 0, 0), null, new Vec3(), new Vec3(), PhysicsMaterial.GetFromIndex(0), false, 0);

            GameEntity blockEntity = prefab;


            MatrixFrame identity2 = MatrixFrame.Identity;

            identity2.origin    = pos;
            identity2.origin.x += 7.5f;

            identity2.origin.z = 7.5f;
            identity2.rotation.ApplyScaleLocal(1f);
            MatrixFrame frame2 = identity2;

            blockEntity.SetFrame(ref frame2);
            blockEntity.SetVisibilityExcludeParents(true);
            blockEntity.SetAlpha(1f);
            blockEntity.CreateAndAddScriptComponent("BlockMissionObject");

            BlockMissionObject missionObject = blockEntity.GetFirstScriptOfType <BlockMissionObject>();

            mission.AddActiveMissionObject(missionObject);
            return(missionObject);
        }
コード例 #31
0
        public YAMLNode ExportYAML(IExportContainer container)
        {
            YAMLMappingNode node = new YAMLMappingNode();

            node.AddSerializedVersion(GetSerializedVersion(container.Version));
            node.Add("name", Name);
            node.Add("rect", Rect.ExportYAML(container));
            node.Add("alignment", (int)Alignment);
            node.Add("pivot", Pivot.ExportYAML(container));
            node.Add("border", Border.ExportYAML(container));
            node.Add("outline", Outline.ExportYAML(container));
            node.Add("physicsShape", PhysicsShape.ExportYAML(container));
            node.Add("tessellationDetail", TessellationDetail);
            return(node);
        }
コード例 #32
0
 public Entity(double cTime, Particle pos, Drawable draw, PhysicsShape physS, EntityClass pc, BulletEmitter e = null, GraphicsStyle g = null)
 {
     this.pc      = pc;
     ps           = physS ?? new Point(pos.Dimension);
     CreationTime = cTime;
     creation     = new GameEvent(cTime, this.Create, this.RewindCreate, this.UndoCreate);
     this.pos     = pos;
     d            = draw;
     this.e       = e;
     gs           = g;
     if (pos != null)
     {
         this.Time = CreationTime;
     }
 }
コード例 #33
0
        public bool TryGetShape(ulong shapeHash, out PhysicsShape shape)
        {
            if (this.TryGetActiveShape(shapeHash, out shape))
            {
                return(true);
            }

            if (this.TryGetInactiveShape(shapeHash, out shape))
            {
                this.ReactivateShape(shapeHash, shape);
                return(true);
            }

            shape = null;
            return(false);
        }
コード例 #34
0
 public JitterBody(JitterPhysics physicsManager, PhysicsShape shape, Vector3D initialPosition,
                   float mass, float restitution)
     : base(shape)
 {
     CreateShape();
     RotationMatrix = Matrix.Identity;
     jitterBody     = new RigidBody(jitterShape)
     {
         IsStatic = false,
         Mass     = mass,
         Material = { Restitution = restitution },
         Position = JitterDatatypesMapping.Convert(ref initialPosition),
         Tag      = this
     };
     physicsManager.jitterWorld.AddBody(jitterBody);
 }
コード例 #35
0
        public PrepChildPrimAndLinkCmd(PhysxPrim parent, PhysxPrim child, OpenMetaverse.Vector3 localPos,
                                       OpenMetaverse.Quaternion localRot)
        {
            Util.ThrowIfNull(parent, "parent");
            Util.ThrowIfNull(child, "child");

            _parent        = parent;
            _child         = child;
            _localPos      = localPos;
            _localRot      = localRot;
            _newShape      = null;
            _affectedPrims = new List <PhysxPrim> {
                parent, child
            };
            _affectedPrims.AddRange(child.ChildShapes.Keys);
        }
コード例 #36
0
ファイル: JitterBody.cs プロジェクト: whztt07/DeltaEngine
		public JitterBody(JitterPhysics physicsManager, PhysicsShape shape, Vector3D initialPosition,
			float mass, float restitution)
			: base(shape)
		{
			CreateShape();
			RotationMatrix = Matrix.Identity;
			jitterBody = new RigidBody(jitterShape)
			{
				IsStatic = false,
				Mass = mass,
				Material = { Restitution = restitution },
				Position = JitterDatatypesMapping.Convert(ref initialPosition),
				Tag = this
			};
			physicsManager.jitterWorld.AddBody(jitterBody);
		}
コード例 #37
0
        // CONSTRUCTORS----------------------------------------------------------------------------
        public SpriteTileCrystallonEntity( Scene pScene, GamePhysics pGamePhysics, PhysicsShape pShape = null)
            : base(pScene, pGamePhysics, pShape)
        {
            // SPRITE STUFF
            _orientationIndex = 0;
            _patternIndex = 0;
            //			_sprite = new SpriteTile(pTextureInfo);
            _sprite = new SpriteTile();
            //			_sprite.Scale = _sprite.CalcSizeInPixels();
            _node.AddChild(_sprite);

            // PHYSICS STUFF
            //			if (pShape != null) {
            //				_body = _physics.RegisterPhysicsBody(pShape, 0.1f, 0.01f, _sprite.Position);
            //			} else {
            //				_body = null;
            //			}
            //			Scheduler.Instance.Schedule(_sprite, Update, 0.0f, false);
        }
コード例 #38
0
        public YAMLNode ExportYAML(IExportContainer container)
        {
            YAMLMappingNode node = new YAMLMappingNode();

            node.AddSerializedVersion(ToSerializedVersion(container.ExportVersion));
            node.Add(NameName, Name);
            node.Add(RectName, Rect.ExportYAML(container));
            node.Add(AlignmentName, (int)Alignment);
            node.Add(PivotName, Pivot.ExportYAML(container));
            if (HasBorder(container.ExportVersion))
            {
                node.Add(BorderName, Border.ExportYAML(container));
            }
            if (HasOutline(container.ExportVersion))
            {
                node.Add(OutlineName, Outline.ExportYAML(container));
            }
            if (HasPhysicsShape(container.ExportVersion))
            {
                node.Add(PhysicsShapeName, PhysicsShape.ExportYAML(container));
            }
            if (HasTessellationDetail(container.ExportVersion))
            {
                node.Add(TessellationDetailName, TessellationDetail);
            }
            if (HasBones(container.ExportVersion))
            {
                node.Add(BonesName, Bones.ExportYAML(container));
                node.Add(SpriteIDName, SpriteID);
            }
            if (HasInternalID(container.ExportVersion))
            {
                node.Add(InternalIDName, InternalID);
            }
            if (HasBones(container.ExportVersion))
            {
                node.Add(VerticesName, Vertices.ExportYAML(container));
                node.Add(IndicesName, Indices.ExportYAML(true));
                node.Add(EdgesName, Edges.ExportYAML(container));
                node.Add(WeightsName, Weights.ExportYAML(container));
            }
            return(node);
        }
コード例 #39
0
        public void Execute(PhysxScene scene)
        {
            if (_newPrimaryShape == null)
            {
                if (_actor.Disposed)
                {
                    return;
                }

                _actor.BeginDelayCommands(this);

                Meshing.RemeshActorWorker worker = new Meshing.RemeshActorWorker(scene, _actor, _vdActive || _actor.IsPhysical,
                                                                                 (PhysicsShape rootShape, Dictionary <PhysxPrim, RelatedShapes> childShapes) =>
                {
                    _newPrimaryShape = rootShape;
                    _newChildShapes  = childShapes;

                    scene.QueueCommand(this);
                });

                worker.Remesh();
            }
            else
            {
                try
                {
                    if (_actor.IsPhysical)
                    {
                        if (!_actor.DynamicsPrecheck(_newPrimaryShape, _newChildShapes))
                        {
                            return;
                        }
                    }

                    _actor.RebuildPhysxActorWithNewShape(_newPrimaryShape, _newChildShapes, _vdActive ? false : _actor.IsPhysical, false);
                    _actor.SetVolumeDetectSync(_vdActive);
                }
                finally
                {
                    _actor.EndDelayCommands();
                }
            }
        }
コード例 #40
0
        public void Write(AssetWriter writer)
        {
            writer.Write(Name);
            Rect.Write(writer);
            writer.Write((int)Alignment);
            Pivot.Write(writer);
            if (HasBorder(writer.Version))
            {
                Border.Write(writer);
            }
            if (HasOutline(writer.Version))
            {
                Outline.Write(writer);
            }
            if (HasPhysicsShape(writer.Version))
            {
                PhysicsShape.Write(writer);
            }
            if (HasTessellationDetail(writer.Version))
            {
                writer.Write(TessellationDetail);
            }
            if (HasBones(writer.Version))
            {
                Bones.Write(writer);
                writer.Write(SpriteID);
            }
            if (HasInternalID(writer.Version))
            {
                writer.Write(InternalID);
            }
            if (HasBones(writer.Version))
            {
                Vertices.Write(writer);
                Indices.Write(writer);
                Edges.Write(writer);
                writer.AlignStream();

                Weights.Write(writer);
                writer.AlignStream();
            }
        }
コード例 #41
0
ファイル: ShapeCache.cs プロジェクト: kf6kjg/halcyon
        private void CheckAndDispose(PhysicsShape item, bool dynamic)
        {
            //we want to dispose this object, but ONLY if no one else has a reference to it
            //that includes the opposite inactive list
            if (item.HasRefs)
            {
                return;
            }

            //we can dispose
            if (this.OnShapeNeedsFreeing != null)
            {
                this.OnShapeNeedsFreeing(item);
            }
            else
            {
                //this will happen during shutdown, where we dont want to defer the deletes to the physics thread
                //since it is stopped
                item.Dispose();
            }
        }
コード例 #42
0
ファイル: SetPhysicalityCmd.cs プロジェクト: kf6kjg/halcyon
        public void Execute(PhysxScene scene)
        {
            if (_newPrimaryShape == null)
            {
                if (_actor.Disposed) return;

                _actor.BeginDelayCommands(this);

                Meshing.RemeshActorWorker worker = new Meshing.RemeshActorWorker(scene, _actor, _isPhysical,
                    (PhysicsShape rootShape, Dictionary<PhysxPrim, RelatedShapes> childShapes) => 
                    {
                        _newPrimaryShape = rootShape;
                        _newChildShapes = childShapes;
                        scene.QueueCommand(this);
                    });

                worker.Remesh();
            }
            else
            {
                try
                {
                    if (_isPhysical)
                    {
                        if (!_actor.DynamicsPrecheck(_newPrimaryShape, _newChildShapes))
                        {
                            return;
                        }
                    }

                    _actor.RebuildPhysxActorWithNewShape(_newPrimaryShape, _newChildShapes, _isPhysical, false);
                }
                finally
                {
                    _actor.EndDelayCommands();
                }
            }
        }
コード例 #43
0
    public PhysicalSpriteUV(TextureInfo textureInfo, PhysicsScene physicsScene, bool circle = false)
        : base(textureInfo)
    {
        // Texture Setup
            Quad.S = TextureInfo.TextureSizef;
            Pivot = new Vector2(TextureInfo.Texture.Width / 2f, TextureInfo.Texture.Height / 2f );

            // Physics Setup (get the indicies we will be using
            PhysicsScene = physicsScene;
            ShapeIndex = PhysicsScene.NumShape;
            BodyIndex = PhysicsScene.NumBody;
            JointIndex = -1;

            // Create shapes (will want to let the programmer pass in things like friction and rotation at some point, AND SPECIFY CIRCLE OR SQUARE SHAPE)
            PhysicsShape shape;
            if(!circle)
            {
                shape = new PhysicsShape(new Vector2(textureInfo.Texture.Width/2, textureInfo.Texture.Height/2));
            }
            else
            {
                shape = new PhysicsShape(textureInfo.Texture.Width/2);
            }

            // Why 100?
            PhysicsBody body = new PhysicsBody(shape, 100);
            body.ShapeIndex = (uint)ShapeIndex;

            PhysicsScene.sceneShapes[ShapeIndex] = shape;
            PhysicsScene.sceneBodies[BodyIndex] = body;
            //PhysicsScene.sceneBodies[BodyIndex].Rotation = 0.1f;
            //PhysicsScene.sceneBodies[BodyIndex].AirFriction = 0.01f;

            PhysicsScene.NumShape++;
            PhysicsScene.NumBody++;
    }
コード例 #44
0
ファイル: MeshingStage.cs プロジェクト: kf6kjg/halcyon
 void _shapeCache_OnShapeNeedsFreeing(PhysicsShape shape)
 {
     if (OnShapeNeedsFreeing != null)
     {
         OnShapeNeedsFreeing(shape);
     }
 }
コード例 #45
0
ファイル: MeshingStage.cs プロジェクト: kf6kjg/halcyon
        internal void UnrefShape(PhysicsShape shape, bool dynamic)
        {
            lock (_meshWaitingQueue)
            {
                _meshWaitingQueue.Enqueue(new UnrefShapeItem
                {
                    Shape = shape,
                    Dynamic = dynamic
                });

                Monitor.Pulse(_meshWaitingQueue);
            }
        }
コード例 #46
0
ファイル: BulkCreateObjectCmd.cs プロジェクト: kf6kjg/halcyon
        public void Execute(PhysxScene scene)
        {
            bool isPhysical = (_flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0;

            if (_rootHasVdSet)
            {
                isPhysical = false;
            }

            if (_newPrimaryShape == null)
            {
                bool first = true;
                foreach (BulkShapeData shape in _shapes)
                {
                    BulkShapeData thisShape = shape;
                    if (first)
                    {
                        _primaryShapeData = thisShape;
                        PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, shape.Material, shape.PhysicsProperties);
                        _rootHasVdSet = properties.VolumeDetectActive;

                        if (_rootHasVdSet)
                        {
                            isPhysical = false;
                        }

                        scene.MeshingStageImpl.QueueForMeshing(String.Empty, shape.Pbs, shape.Size, Meshing.MeshingStage.SCULPT_MESH_LOD, 
                            isPhysical || _rootHasVdSet, shape.SerializedShapes, 
                            (_flags & PhysxScene.AddPrimShapeFlags.FromCrossing) == PhysicsScene.AddPrimShapeFlags.FromCrossing,
                                delegate(PhysicsShape meshedShape)
                                {
                                    _newPrimaryShape = meshedShape;
                                    _meshedShapes.Add(thisShape, meshedShape);
                                    if (++_meshedSoFar == _totalNumShapes)
                                    {
                                        scene.QueueCommand(this);
                                    }
                                }
                            );

                        first = false;
                    }
                    else
                    {
                        scene.MeshingStageImpl.QueueForMeshing(String.Empty, shape.Pbs, shape.Size, Meshing.MeshingStage.SCULPT_MESH_LOD, 
                            isPhysical || _rootHasVdSet, shape.SerializedShapes,
                            (_flags & PhysxScene.AddPrimShapeFlags.FromCrossing) == PhysicsScene.AddPrimShapeFlags.FromCrossing,
                                delegate(PhysicsShape meshedShape)
                                {
                                    _meshedShapes.Add(thisShape, meshedShape);
                                    if (++_meshedSoFar == _totalNumShapes)
                                    {
                                        scene.QueueCommand(this);
                                    }
                                }
                            );
                    }
                }
            }
            else
            {
                OpenMetaverse.Vector3 rootVelocity = OpenMetaverse.Vector3.Zero;
                OpenMetaverse.Vector3 rootAngularVelocity = OpenMetaverse.Vector3.Zero;

                //we have all the shapes for the parent and all children, time to construct the group
                bool first = true;
                PhysxPrim rootPrim = null;

                CollisionGroupFlag collisionGroup = (_flags & PhysicsScene.AddPrimShapeFlags.Phantom) == 0 ? CollisionGroupFlag.Normal : CollisionGroupFlag.PhysicalPhantom;
                foreach (BulkShapeData shape in _shapes)
                {
                    if (first)
                    {
                        bool kinematicStatic;

                        PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, shape.Material, shape.PhysicsProperties);

                        PhysX.RigidActor actor = PhysxActorFactory.CreateProperInitialActor(_newPrimaryShape, scene, shape.Position, shape.Rotation, _flags, out kinematicStatic,
                            properties.PhysxMaterial);

                        rootPrim = new PhysxPrim(scene, shape.Pbs, shape.Position, shape.Rotation, _newPrimaryShape, actor, 
                            isPhysical, properties, collisionGroup);

                        scene.AddPrimSync(rootPrim, isPhysical, kinematicStatic);

                        shape.OutActor = rootPrim;

                        rootVelocity = shape.Velocity;
                        rootAngularVelocity = shape.AngularVelocity;

                        first = false;
                    }
                    else
                    {
                        PhysicsShape phyShape = _meshedShapes[shape];

                        PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, shape.Material, shape.PhysicsProperties);

                        PhysxPrim childPrim = new PhysxPrim(rootPrim, scene, shape.Pbs, shape.Position, shape.Rotation, phyShape, 
                            null, isPhysical, properties, collisionGroup);
                        rootPrim.LinkPrimAsChildSync(phyShape, childPrim, shape.Position, shape.Rotation, true);

                        shape.OutActor = childPrim;
                    }
                }

                rootPrim.UpdateMassAndInertia();

                if (_rootHasVdSet)
                {
                    rootPrim.SetVolumeDetectSync(_rootHasVdSet);
                }

                if ((_flags & PhysicsScene.AddPrimShapeFlags.StartSuspended) != 0)
                {
                    rootPrim.SuspendPhysicsSync(_primaryShapeData.ObjectReceivedOn);
                }

                rootPrim.DynamicsPostcheck();

                rootPrim.SetInitialVelocities(rootVelocity, rootAngularVelocity);

                if ((_flags & PhysicsScene.AddPrimShapeFlags.Interpolate) != 0)
                {
                    rootPrim.SuspendPhysicsSync(_primaryShapeData.ObjectReceivedOn);
                    rootPrim.ResumePhysicsSync(true);
                }

                FinishedEvent.Set();
            }
        }
コード例 #47
0
 // METHODS ------------------------------------------------------------------------------------------------
 //        public PhysicsBody addCardPhysics(Vector2 position) {
 //            this.SceneBodies[this.NumBody] = new PhysicsBody(SceneShapes[0],0.1f);
 //            this.SceneBodies[this.NumBody].ShapeIndex = 0;
 //            this.sceneBodies[this.NumBody].ColFriction = 0.01f;
 //            this.SceneBodies[this.NumBody].Position = position / PtoM;
 //            this.NumBody++;
 //            return SceneBodies[this.NumBody-1];
 //        }
 public void RegisterPhysicsShape( PhysicsShape pShape )
 {
     this.SceneShapes[numShape] = new PhysicsShape( pShape );
     this.NumShape++;
 }
コード例 #48
0
 public PhysicsBody RegisterPhysicsBody(PhysicsShape pShape, float pMass, float pColFriction, Vector2 pPosition)
 {
     //			if (!Array.Exists<PhysicsShape>(SceneShapes, pShape)) {
     int i = NumShape-1;
     while(i>=0) {
         if(SceneShapes[i] == pShape) {
             break;
         }
         i--;
     }
     if( i == -1) { // REQUESTED SceneShape COULD NOT BE FOUND IN REGISTRY, SO REGISTER IT
         RegisterPhysicsShape( pShape );
         i = NumShape-1;
     }
     this.SceneBodies[this.NumBody] = new PhysicsBody( pShape, pMass );
     this.SceneBodies[this.NumBody].ShapeIndex = (uint)i;
     this.SceneBodies[this.NumBody].ColFriction = pColFriction;
     this.SceneBodies[this.NumBody].Position = pPosition / PtoM;
     this.NumBody++;
     return SceneBodies[this.NumBody-1];
 }
コード例 #49
0
ファイル: MeshingStage.cs プロジェクト: kf6kjg/halcyon
        internal bool TryGetCachedShape(ulong meshHash, OpenSim.Framework.PrimitiveBaseShape shape, bool isDynamic, out PhysicsShape phyShape)
        {
            ShapeCache cache = FindCorrespondingCache(ShapeDeterminer.FindBestShape(shape, isDynamic));
            if (cache != null)
            {
                return cache.TryGetShape(meshHash, out phyShape);
            }

            phyShape = null;
            return false;
        }
コード例 #50
0
            private static PhysicsShape CreatePhysicsShapeFromConvexSetAndCache(MeshingStage meshingStage, ulong meshHash, List<PhysX.ConvexMeshGeometry> convexes)
            {
                PhysicsShape phyShape;
                phyShape = new PhysicsShape(convexes, meshHash);
                phyShape.Complexity = convexes.Count;
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.DecomposedConvexHulls);
                return phyShape;
            }
コード例 #51
0
            private void GenerateTrimeshAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                PhysicsShape phyShape;
                PhysX.TriangleMeshGeometry triMesh = meshingStage.GeneratePhysXTrimeshShape(PrimName, Shape, Size, MeshingStage.SCULPT_MESH_LOD, IsDynamic);

                if (triMesh == null)
                {
                    //meshing  or one of its prereq steps failed, generate a bounding box
                    PhysX.Geometry geom = meshingStage.GeneratePhysXBoxShape(Shape);
                    //basic shapes are not cached
                    phyShape = new PhysicsShape(geom, ShapeType.PrimitiveBox, meshHash);
                }
                else
                {
                    phyShape = CreatePhysicsShapeFromTrimeshAndCache(meshingStage, meshHash, triMesh);
                }

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
コード例 #52
0
ファイル: CreateObjectCmd.cs プロジェクト: kf6kjg/halcyon
        public void Execute(PhysxScene scene)
        {
            if (Shape == null)
            {
                PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);
                _hasVdSet = properties.VolumeDetectActive;

                scene.MeshingStageImpl.QueueForMeshing(_primName, _pbs, _size, _lod, 
                    (_flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0 || _hasVdSet, 
                    _serializedPhysicsShapes,
                    (_flags & PhysxScene.AddPrimShapeFlags.FromCrossing) == PhysicsScene.AddPrimShapeFlags.FromCrossing,
                        delegate(PhysicsShape meshedShape)
                        {
                            Shape = meshedShape;
                            scene.QueueCommand(this);
                        }
                    );
            }
            else
            {
                bool isPhysical = (_flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0;
                if (_hasVdSet)
                {
                    isPhysical = false;
                }

                CollisionGroupFlag collisionGroup = (_flags & PhysicsScene.AddPrimShapeFlags.Phantom) == 0 ? CollisionGroupFlag.Normal : CollisionGroupFlag.PhysicalPhantom;
                if (_parent == null)
                {
                    bool kinematicStatic;

                    PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);

                    Actor = PhysxActorFactory.CreateProperInitialActor(Shape, scene, _position, _rotation, _flags, out kinematicStatic, properties.PhysxMaterial);

                    FinalPrim = new PhysxPrim(scene, _pbs, _position, _rotation, Shape, Actor, isPhysical, properties, collisionGroup);
                    scene.AddPrimSync(FinalPrim, isPhysical, kinematicStatic);
                }
                else
                {
                    PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);

                    FinalPrim = new PhysxPrim(_parent, scene, _pbs, _position, _rotation, Shape, null, isPhysical, properties, collisionGroup);
                    _parent.LinkPrimAsChildSync(Shape, FinalPrim, _position, _rotation, false);
                }

                if (_hasVdSet)
                {
                    FinalPrim.SetVolumeDetectSync(true);
                }

                if ((_flags & PhysicsScene.AddPrimShapeFlags.StartSuspended) != 0)
                {
                    FinalPrim.SuspendPhysicsSync(_interpolateTime);
                }

                FinalPrim.DynamicsPostcheck();

                FinalPrim.SetInitialVelocities(_velocity, _angularVelocity);

                if ((_flags & PhysicsScene.AddPrimShapeFlags.Interpolate) != 0)
                {
                    FinalPrim.SuspendPhysicsSync(_interpolateTime);
                    FinalPrim.ResumePhysicsSync(true);
                }

                this.FinshedEvent.Set();
            }
        }
コード例 #53
0
ファイル: SetPhysicalityCmd.cs プロジェクト: kf6kjg/halcyon
 public SetPhysicalityCmd(PhysxPrim actor, bool isPhysical)
 {
     _isPhysical = isPhysical;
     _actor = actor;
     _newPrimaryShape = null;
 }
コード例 #54
0
            private static PhysicsShape CreatePhysicsShapeFromTrimeshAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.TriangleMeshGeometry triMesh)
            {
                PhysicsShape phyShape;
                phyShape = new PhysicsShape(triMesh, ShapeType.TriMesh, meshHash);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.TriMesh);
                return phyShape;
            }
コード例 #55
0
ファイル: MeshingStage.cs プロジェクト: kf6kjg/halcyon
 internal void UncacheShape(ulong meshHash, PhysicsShape shape, ShapeType shapeType)
 {
     ShapeCache cache = FindCorrespondingCache(shapeType);
     cache.RemoveShape(meshHash, shape);
 }
コード例 #56
0
            private void GenerateBasicShapeAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                Tuple<PhysX.Geometry, ShapeType> result = meshingStage.GenerateBasicPhysXShape(Shape);
                PhysicsShape phyShape = new PhysicsShape(result.Item1, result.Item2, meshHash);

                //basic shapes are not cached

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
コード例 #57
0
            private static PhysicsShape CreatePhysicsShapeFromSingleConvexAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.ConvexMeshGeometry convex)
            {
                PhysicsShape phyShape;
                phyShape = new PhysicsShape(new List<PhysX.ConvexMeshGeometry> { convex }, meshHash, true);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.SingleConvex);
                return phyShape;
            }
コード例 #58
0
ファイル: MeshingStage.cs プロジェクト: kf6kjg/halcyon
 internal void CacheShape(ulong meshHash, PhysicsShape phyShape, ShapeType bestFitShape)
 {
     ShapeCache cache = FindCorrespondingCache(bestFitShape);
     cache.AddShape(meshHash, phyShape);
 }
コード例 #59
0
 // CONSTRUCTORS --------------------------------------------------------
 public CubeCrystallonEntity(Scene pScene, GamePhysics pGamePhysics, PhysicsShape pShape = null )
     : base(pScene, pGamePhysics, pShape, 3, true)
 {
     //			setVelocity(DEFAULT_SPEED, GameScene.Random.NextAngle());
 }
コード例 #60
0
            private void GenerateConvexSetAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                PhysicsShape phyShape;

                //we need to mesh this object into convex hulls appropriate for dynamic objects
                List<PhysX.ConvexMeshGeometry> convexes = meshingStage.GenerateComplexPhysXShape(meshHash, PrimName, Shape, Size, MeshingStage.SCULPT_MESH_LOD, IsDynamic);

                if (convexes == null)
                {
                    //meshing  or one of its prereq steps failed, generate a bounding box
                    PhysX.Geometry geom = meshingStage.GeneratePhysXBoxShape(Shape);
                    //basic shapes are not cached
                    phyShape = new PhysicsShape(geom, ShapeType.PrimitiveBox, meshHash);
                }
                else
                {
                    phyShape = CreatePhysicsShapeFromConvexSetAndCache(meshingStage, meshHash, convexes);
                }

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }