Beispiel #1
0
        public static DetectCollision getDetectCollision(TV_COLLISIONRESULT collResult)
        {
            DetectCollision ret = null;
            if (collResult.eCollidedObjectType == CONST_TV_OBJECT_TYPE.TV_OBJECT_LANDSCAPE)
            {
                ret = new LandscapeDetectCollision(collResult);
            }
            else if (collResult.eCollidedObjectType == CONST_TV_OBJECT_TYPE.TV_OBJECT_ACTOR)
            {
                ret = new ActorDetectCollision(collResult);
            }
            else
            {
                throw new NullReferenceException("Not valid collResult!");
            }

            return ret;
        }
Beispiel #2
0
        public IModel MousePick(int x, int y)
        {
            DxVBLibA.D3DVECTOR dxo = new DxVBLibA.D3DVECTOR();
            DxVBLibA.D3DVECTOR dxd = new DxVBLibA.D3DVECTOR();
            Engine.Gl.MousePickVector(x, y, ref dxo, ref dxd);
            TV_COLLISIONRESULT cr = new TV_COLLISIONRESULT();

            if (Engine.TV3DScene.AdvancedCollision(ref dxo, ref dxd, ref cr, 0, CONST_TV_TESTTYPE.TV_TESTTYPE_ACCURATETESTING, true))
            {
                // TODO: don't loop through, a userdata field?
                foreach (IModel m in Models.Values)
                {
                    if (
                        (cr.collidedobjecttype == 1 && (m is IActor) && m.ID == cr.entityid) ||
                        (cr.collidedobjecttype != 1 && !(m is IActor) && m.ID == cr.MeshID)
                        )
                    {
                        return(m);
                    }
                }
            }
            return(null);
        }
 public ActorDetectCollision(TV_COLLISIONRESULT collResult)
 {
     this.collResult = collResult;
 }
Beispiel #4
0
		public IModel MousePick( int x, int y ) {
			DxVBLibA.D3DVECTOR dxo = new DxVBLibA.D3DVECTOR();
			DxVBLibA.D3DVECTOR dxd = new DxVBLibA.D3DVECTOR();
			Engine.Gl.MousePickVector( x, y, ref dxo, ref dxd );
			TV_COLLISIONRESULT cr = new TV_COLLISIONRESULT();
			if ( Engine.TV3DScene.AdvancedCollision( ref dxo, ref dxd, ref cr, 0, CONST_TV_TESTTYPE.TV_TESTTYPE_ACCURATETESTING, true) ) {
				// TODO: don't loop through, a userdata field?
				foreach ( IModel m in Models.Values ) {
					if (
						(cr.collidedobjecttype == 1 && (m is IActor) && m.ID == cr.entityid)
						|| (cr.collidedobjecttype != 1 && !(m is IActor) && m.ID == cr.MeshID)
					) {
						return m;
					}
				}
			}
			return null;
		}
 public LandscapeDetectCollision(TV_COLLISIONRESULT collResult)
 {
     this.collResult = collResult;
 }
Beispiel #6
0
        public override void Update(GameTime time)
        {
            TV_COLLISIONRESULT collResult = new TV_COLLISIONRESULT();
            if (mouseEvent.Click() &&
                Game.Scene.MousePickEx(inputManager.MouseAbsX, inputManager.MouseAbsY, ref collResult) &&
                !windowService.clickInWindowArea())
            {
                try
                {
                    controlService.turnToTargetDirection(playerService.getStatistics(), CollisionFactory.getDetectCollision(collResult));
                    targetPos = collResult.vCollisionImpact;
                }
                catch
                {

                }
            }
            if (controlService.goToTarget(playerService.getStatistics(), targetPos))
            {
                animationService.changeAnimation(CharacterAnimationState.RUN, CharacterName.PLAYER);
            }
            else
            {
                animationService.changeAnimation(CharacterAnimationState.IDLE, CharacterName.PLAYER);
            }
            base.Update(time);
        }
Beispiel #7
0
        private void PutObjectOnGround()
        {
            if (selectedObject != null)
            {
                TV_3DVECTOR min = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR max = core.Globals.Vector3(0, 0, 0);
                selectedObject.GetMesh().GetBoundingBox(ref min, ref max);

                TV_3DVECTOR center = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR centerLow = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR start1 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR start2 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR start3 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR start4 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR start5 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR end1 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR end2 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR end3 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR end4 = core.Globals.Vector3(0, 0, 0);
                TV_3DVECTOR end5 = core.Globals.Vector3(0, 0, 0);

                core.MathLibrary.TVVec3Lerp(ref center, min, max, 0.5f);
                centerLow = center;
                centerLow.y = min.y;
                start1 = min;
                start2 = max; start2.y = min.y;
                start3.x = max.x; start3.y = min.y; start3.z = min.z;
                start4.x = min.x; start4.y = min.y; start4.z = max.z;
                start5 = center; start5.y = min.y;

                end1 = start1;
                end2 = start2;
                end3 = start3;
                end4 = start4;
                end5 = start5;
                end1.y -= 100000;
                end2.y -= 100000;
                end3.y -= 100000;
                end4.y -= 100000;
                end5.y -= 100000;

                TV_COLLISIONRESULT coll1 = new TV_COLLISIONRESULT();
                TV_COLLISIONRESULT coll2 = new TV_COLLISIONRESULT();
                TV_COLLISIONRESULT coll3 = new TV_COLLISIONRESULT();
                TV_COLLISIONRESULT coll4 = new TV_COLLISIONRESULT();
                TV_COLLISIONRESULT coll5 = new TV_COLLISIONRESULT();

                core.Scene.AdvancedCollision(start1, end1, ref coll1);
                core.Scene.AdvancedCollision(start2, end2, ref coll2);
                core.Scene.AdvancedCollision(start3, end3, ref coll3);
                core.Scene.AdvancedCollision(start4, end4, ref coll4);
                core.Scene.AdvancedCollision(start5, end5, ref coll5);

                if (coll1.bHasCollided || coll2.bHasCollided ||
                    coll3.bHasCollided || coll4.bHasCollided || coll5.bHasCollided)
                {
                    TV_3DVECTOR newPos = selectedObject.GetMesh().GetPosition();

                    List<float> array = new List<float>();

                    if (coll1.bHasCollided)
                        array.Add(coll1.vCollisionImpact.y);
                    if (coll2.bHasCollided)
                        array.Add(coll2.vCollisionImpact.y);
                    if (coll3.bHasCollided)
                        array.Add(coll3.vCollisionImpact.y);
                    if (coll4.bHasCollided)
                        array.Add(coll4.vCollisionImpact.y);
                    if (coll5.bHasCollided)
                        array.Add(coll5.vCollisionImpact.y);

                    array.Sort();
                    newPos.y = array[array.Count - 1] + (max.y - min.y) / 2;

                    selectedObject.Position = new VECTOR3D(newPos.x, newPos.y, newPos.z);
                    selectedObject.Update();

                    Thread.Sleep(200);
                }
            }
        }