Beispiel #1
0
		public void QMult( ref Quat c, Quat a, Quat b )
		{
			c.R = a.R*b.R - a.I*b.I - a.J*b.J - a.K*b.K;
			c.I = a.R*b.I + a.I*b.R + a.J*b.K - a.K*b.J;
			c.J = a.R*b.J + a.J*b.R + a.K*b.I - a.I*b.K;
			c.K = a.R*b.K + a.K*b.R + a.I*b.J - a.J*b.I;
		}
Beispiel #2
0
		public void QAdd( ref Quat a, Quat b )
		{
			a.R += b.R;
			a.I += b.I;
			a.J += b.J;
			a.K += b.K;
		}
Beispiel #3
0
		public void QSqr( ref Quat b, Quat a )
		{
			b.R = a.R*a.R - a.I*a.I - a.J*a.J - a.K*a.K;
			b.I = 2.0f*a.R*a.I;
			b.J = 2.0f*a.R*a.J;
			b.K = 2.0f*a.R*a.K;
		}
Beispiel #4
0
		public float Eval( float x, float y, float z )
		{
			var q = new Quat();
			var tmp = new Quat();

			var i = 0;

			q.R = x;
			q.I = y;
			q.J = z;
			q.K = 0;

			for ( i = 30; i > 0; i-- )
			{
				QSqr( ref tmp, q );
				QMult( ref q, this.emio, tmp );
				QAdd( ref q, this.c );

				if ( q.R*q.R + q.I*q.I + q.J*q.J + q.K*q.K > 8.0 )
				{
					break;
				}
			}

			return (float)i;
		}
Beispiel #5
0
		public static void ToODE( Quat value, out Ode.dQuaternion result )
		{
			result.X = value.X;
			result.Y = value.Y;
			result.Z = value.Z;
			result.W = value.W;
		}
Beispiel #6
0
 public SkyBox(int id, MessageBus bus)
 {
     Id = id;
     Bus = bus;
     Position = new Vect3(0, 0, 0);
     Rotation = new Quat(Math.Sqrt(0.5), 0, 0, Math.Sqrt(0.5));
 }
Beispiel #7
0
	public Quat(Quat q)
	{
		this.x = q.x;
	    this.y = q.y;
		this.z = q.z;
		this.w = q.w;
	}
Beispiel #8
0
        public void SetForceFireRotationLookTo( Vec3 lookTo )
        {
            setForceFireRotation = true;

            Vec3 diff = lookTo - Position;
            //Vec3 diff = lookTo - GetFirePosition( false );

            forceFireRotation = Quat.FromDirectionZAxisUp( diff );
        }
Beispiel #9
0
 public override void PhysX_GetDrivePosition( out Vec3 position, out Quat rotation )
 {
     if( nativeJoint == IntPtr.Zero )
     {
         position = Vec3.Zero;
         rotation = Quat.Identity;
         return;
     }
     PhysXNativeWrapper.PhysXNativeD6Joint.GetDrivePosition( nativeJoint, out position, out rotation );
 }
        public void SetLookDirection(Vec3 pos)
        {
            Vec2 diff = pos.ToVec2() - Position.ToVec2();

            if (diff == Vec2.Zero)
                return;

            Radian dir = MathFunctions.ATan16(diff.Y, diff.X);

            float halfAngle = dir * 0.5f;
            Quat rot = new Quat(new Vec3(0, 0, MathFunctions.Sin16(halfAngle)), MathFunctions.Cos16(halfAngle));
            Rotation = rot;
        }
        public SpringWheel(Bone bone, Unit unit, float size, float stiffness, float damping)
        {
            this.bone = bone;
            this.size = size;
            this.stiffness = stiffness;
            this.damping = damping;
            this.unit = unit;
            originalBonePosition = bone.Position;
            originalBoneRotation = bone.Rotation;

            mesh = new MapObjectAttachedMesh();
            mesh.MeshName = "Types/Units/AwesomeAircraft/AwesomeAircraftWheel.mesh";
            mesh.ScaleOffset = new Vec3(1, 1, 1);
            mesh.RotationOffset = Quat.Identity;
            mesh.PositionOffset = bone.GetDerivedPosition();
            unit.Attach(mesh);
        }
Beispiel #12
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="globalReal"></param>
		/// <param name="globalImag"></param>
		/// <param name="globalTheta"></param>
		public Julia( float globalReal, float globalImag, float globalTheta )
		{
			oc = new Quat();
			oc.R = globalReal;
			oc.I = globalImag;
			oc.J = oc.K = 0.0f;

			eio = new Quat();
			eio.R = Utility.Cos( globalTheta );
			eio.I = Utility.Sin( globalTheta );
			eio.J = eio.K = 0;

            emio = new Quat();
            emio.R = Utility.Cos( -globalTheta );
            emio.I = Utility.Sin( -globalTheta );
            emio.J = eio.K = 0;

			QMult( ref c, eio, oc );
		}
Beispiel #13
0
		public Julia( float globalReal, float globalImag, float globalTheta )
		{
			this.globalReal = globalReal;
			this.globalImag = globalImag;
			this.globalTheta = globalTheta;

			this.oc = new Quat();
			this.oc.R = globalReal;
			this.oc.I = globalImag;
			this.oc.J = this.oc.K = 0.0f;

			this.eio = new Quat();
			this.eio.R = Utility.Cos( globalTheta );
			this.eio.I = Utility.Sin( globalTheta );
			this.eio.J = this.eio.K = 0;

			this.emio = new Quat();
			this.emio.R = Utility.Cos( -globalTheta );
			this.emio.I = Utility.Sin( -globalTheta );
			this.emio.J = this.emio.K = 0;

			QMult( ref this.c, this.eio, this.oc );
		}
Beispiel #14
0
 public unsafe static extern IntPtr /*PhysXShape*/ CreateCapsuleShape(IntPtr /*PhysXBody*/ body, ref Vec3 position,
                                                                      ref Quat rotation, float radius, float halfHeight, int materialCount, IntPtr *materials, float mass, int contactGroup);
Beispiel #15
0
		public void UpdateRotation( bool allowUpdateOldRotation )
		{
			float halfAngle = horizontalDirectionForUpdateRotation * .5f;
			Quat rot = new Quat( new Vec3( 0, 0, MathFunctions.Sin( halfAngle ) ),
				MathFunctions.Cos( halfAngle ) );

			const float epsilon = .001f;

			//update Rotation
			if( !Rotation.Equals( rot, epsilon ) )
				Rotation = rot;

			//update OldRotation
			if( allowUpdateOldRotation )
			{
				//disable updating OldRotation property for TPSArcade demo and for PlatformerDemo
				bool updateOldRotation = true;
				if( Intellect != null && PlayerIntellect.Instance == Intellect )
				{
					if( GameMap.Instance != null && (
						GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
						GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ) )
					{
						updateOldRotation = false;
					}
				}
				if( updateOldRotation )
					OldRotation = rot;
			}
		}
Beispiel #16
0
 protected abstract Quat LimitRotation(Quat rotation);
Beispiel #17
0
    /// Map the zero rotation point to the current rotation
    public void SetDefaultLocalRotation()
    {
        Quat localRot = new Quat(transform.localRotation.x, transform.localRotation.y, transform.localRotation.z, transform.localRotation.w);

        defaultLocalRotation = localRot;
    }
Beispiel #18
0
 public KsAnimKeyframe(Quat rotation, Vec3 transition, Vec3 scale)
 {
     Rotation   = rotation;
     Transition = transition;
     Scale      = scale;
 }
Beispiel #19
0
        public Quat ComputeRotation(Vector3 direction, float rotationSpeed, float deltaTime)
        {
            var newRot = Quat.Slerp(Quat.Euler(transform.rotation), Quat.LookRotation(direction), Mathf.Clamp(rotationSpeed * deltaTime, 0, 1.3f));

            return(newRot);
        }
Beispiel #20
0
 public unsafe static extern void SetKinematicTarget(IntPtr /*PhysXBody*/ pBody, ref Vec3 pos, ref Quat rot);
Beispiel #21
0
 public unsafe static extern int OverlapOBBShapes(IntPtr /*PhysXScene*/ scene, ref Vec3 origin, ref Vec3 halfExtents,
                                                  ref Quat rotation, uint contactGroupMask);
Beispiel #22
0
 public unsafe static extern void SetGlobalPose(IntPtr /*PhysXBody*/ body, ref Vec3 globalPosition,
                                                ref Quat globalRotation);
Beispiel #23
0
 public unsafe static extern void SetMassAndInertia(IntPtr /*PhysXBody*/ body,
                                                    [MarshalAs(UnmanagedType.U1)] bool autoCenterOfMass, ref Vec3 manualMassLocalPosition,
                                                    ref Quat manualMassLocalRotation, ref Vec3 inertiaTensorFactor);
Beispiel #24
0
 public unsafe static extern void GetGlobalPoseLinearAngularVelocities(IntPtr /*PhysXBody*/ body,
                                                                       out Vec3 globalPosition, out Quat globalRotation, out Vec3 linearVelocity,
                                                                       out Vec3 angularVelocity);
Beispiel #25
0
 public unsafe static extern IntPtr /*PhysXShape*/ CreateHeightFieldShape(IntPtr /*PhysXBody*/ body, ref Vec3 position,
                                                                          ref Quat rotation, int sampleCountX, int sampleCountY, IntPtr samples, ref Vec3 samplesScale, float thickness,
                                                                          int materialCount, IntPtr *materials, int contactGroup);
Beispiel #26
0
 public unsafe static extern IntPtr /*PhysXShape*/ CreateTriangleMeshShape(IntPtr /*PhysXBody*/ body, ref Vec3 position,
                                                                           ref Quat rotation, IntPtr /*PxTriangleMesh*/ pxTriangleMesh, int materialCount, IntPtr *materials, float mass,
                                                                           int contactGroup);
Beispiel #27
0
	static public Matrix3x3 Rotate(Vector3 rotation)
	{
		Quat x = new Quat(new Vector3d2(1,0,0), rotation.x * MathUtility.Deg2Rad );
		Quat y = new Quat(new Vector3d2(0,1,0), rotation.y * MathUtility.Deg2Rad );
		Quat z = new Quat(new Vector3d2(0,0,1), rotation.z * MathUtility.Deg2Rad );
		
		return (z*y*x).ToMatrix3x3();
	}
Beispiel #28
0
 public unsafe static extern void GetGlobalPose(IntPtr /*PhysXJoint*/ joint, out Vec3 globalPosition,
                                                out Quat globalRotation);
Beispiel #29
0
        protected Quat ComputeRotation(Vector3 direction, float rotationSpeed, float deltaTime)
        {
            var newRot = (mAlignWithForwardDirection) ? Quat.Slerp(Quat.Euler(transform.rotation), Quat.LookRotation(direction), rotationSpeed * deltaTime) : Quat.Euler(transform.rotation);

            return(newRot);
        }
Beispiel #30
0
 public unsafe static extern void SetDrivePosition(IntPtr /*PhysXD6Joint*/ joint, ref Vec3 position, ref Quat rotation);
Beispiel #31
0
        protected override void CreateBullet(Mode mode)
        {
            //only missiles for missilelauncher
            if (mode.typeMode.BulletType as Missile2Type == null)
            {
                return;
            }

            Missile2 obj = (Missile2)Entities.Instance.Create(mode.typeMode.BulletType, Parent);

            obj.SourceUnit = GetParentUnitHavingIntellect();
            obj.Position   = GetFirePosition(mode.typeMode);

            //Correcting position at a shot in very near object (when the point of a shot inside object).
            {
                Vec3 startPos = Position;
                if (AttachedMapObjectParent != null)
                {
                    startPos = AttachedMapObjectParent.Position;
                }

                Ray ray = new Ray(startPos, obj.Position - startPos);
                if (ray.Direction != Vec3.Zero)
                {
                    RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(
                        ray, (int)ContactGroup.CastOnlyContact);

                    foreach (RayCastResult result in piercingResult)
                    {
                        MapObject mapObject = MapSystemWorld.GetMapObjectByBody(result.Shape.Body);

                        if (mapObject != null)
                        {
                            if (mapObject == this)
                            {
                                continue;
                            }
                            if (mapObject == this.AttachedMapObjectParent)
                            {
                                continue;
                            }
                        }

                        obj.Position = result.Position - ray.Direction * .01f;
                        break;
                    }
                }
            }

            Quat   rot             = GetFireRotation(mode.typeMode);
            Radian dispersionAngle = mode.typeMode.DispersionAngle;

            if (dispersionAngle != 0)
            {
                EngineRandom random = World.Instance.Random;

                float halfDir;

                halfDir = random.NextFloatCenter() * dispersionAngle * .5f;
                rot    *= new Quat(new Vec3(0, 0, MathFunctions.Sin(halfDir)),
                                   MathFunctions.Cos(halfDir));
                halfDir = random.NextFloatCenter() * dispersionAngle * .5f;
                rot    *= new Quat(new Vec3(0, MathFunctions.Sin(halfDir), 0),
                                   MathFunctions.Cos(halfDir));
                halfDir = random.NextFloatCenter() * dispersionAngle * .5f;
                rot    *= new Quat(new Vec3(MathFunctions.Sin(halfDir), 0, 0),
                                   MathFunctions.Cos(halfDir));
            }
            obj.Rotation = rot;

            obj.PostCreate();

            //set damage coefficient
            float coef = obj.DamageCoefficient;
            Unit  unit = GetParentUnitHavingIntellect();

            if (unit != null && unit.BigDamageInfluence != null)
            {
                coef *= unit.BigDamageInfluence.Type.Coefficient;
            }
            obj.DamageCoefficient = coef;

            foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
            {
                MapObjectAttachedMesh attachedMesh = attachedObject as MapObjectAttachedMesh;
                if (attachedMesh == null)
                {
                    continue;
                }

                if (attachedMesh.Alias.Equals("Missile"))
                {
                    if (!attachedMesh.Visible)
                    {
                        continue;
                    }
                    else
                    {
                        attachedMesh.Visible = false;
                        break;
                    }
                }
            }
        }
Beispiel #32
0
 public unsafe static extern void GetDrivePosition(IntPtr /*PhysXD6Joint*/ joint, out Vec3 position, out Quat rotation);
Beispiel #33
0
    // Use this for initialization
    void Start()
    {
        Quaternion relZ = Quaternion.Inverse(JointZ.parent.rotation) *
                          JointZ.rotation;

        Quaternion tZ, sZ;

        Quat.TwistSwingZ(relZ, out tZ, out sZ);

        float angle; Vector3 axis;

        relZ.ToAngleAxis(out angle, out axis);
        //Debug.Log(angle);
        //Debug.Log(axis);

        Quaternion twistZ = Quat.Normalize(new Quaternion(0, 0, relZ.z, relZ.w));
        Quaternion swingZ = relZ * Quaternion.Inverse(twistZ);

        swingZ.ToAngleAxis(out angle, out axis);
        axis = JointZ.TransformDirection(axis);
        Debug.DrawLine(JointZ.position, JointZ.position + axis, Color.blue, 60);
        Debug.Log(angle);
        Debug.Log(axis.ToString("F4"));
        //JointZ.Rotate(axis, -angle);


        Quaternion relY = Quaternion.Inverse(JointY.parent.rotation) *
                          JointY.rotation;

        relY.ToAngleAxis(out angle, out axis);
        //Debug.Log(angle);
        //Debug.Log(axis);

        Quaternion tY, sY;

        Quat.TwistSwingY(relY, out tY, out sY);

        Quaternion twistY = Quat.Normalize(new Quaternion(0, relY.y, 0, relY.w));
        Quaternion swingY = relY * Quaternion.Inverse(twistY);

        swingY.ToAngleAxis(out angle, out axis);
        axis = JointY.TransformDirection(axis);
        Debug.DrawLine(JointY.position, JointY.position + axis, Color.green, 60);
        Debug.Log(angle);
        Debug.Log(axis.ToString("F4"));
        //JointY.Rotate(axis, -angle);


        Quaternion relX = Quaternion.Inverse(JointX.parent.rotation) *
                          JointX.rotation;

        relX.ToAngleAxis(out angle, out axis);
        //Debug.Log(angle);
        //Debug.Log(axis);


        Quaternion tX, sX;

        Quat.TwistSwingX(relX, out tX, out sX);

        Quaternion twistX = Quat.Normalize(new Quaternion(relX.x, 0, 0, relX.w));
        Quaternion swingX = relX * Quaternion.Inverse(twistX);

        swingX.ToAngleAxis(out angle, out axis);
        axis = JointX.TransformDirection(axis);
        Debug.DrawLine(JointX.position, JointX.position + axis, Color.red, 60);
        Debug.Log(angle);
        Debug.Log(axis.ToString("F4"));
        //JointX.Rotate(axis, -angle);
    }
Beispiel #34
0
 public unsafe static extern int OverlapCapsuleShapes(IntPtr /*PhysXScene*/ scene, ref Vec3 origin, ref Quat rotation,
                                                      float radius, float halfHeight, uint contactGroupMask);
Beispiel #35
0
    public void Update()
    {
        Color colIntersect = Color.HSV(0, 0.8f, 1);
        Color colTest      = Color.HSV(0, 0.6f, 1);
        Color colObj       = Color.HSV(0.05f, 0.7f, 1);
        Color active       = new Color(1, 1, 1, 0.7f);
        Color notActive    = new Color(1, 1, 1, 1);

        // Plane and Ray
        bool planeRayActive = UI.AffordanceBegin("PlaneRay", ref posePlaneRay, new Bounds(Vec3.One * 0.4f));

        boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), planeRayActive ? active:notActive);

        Plane ground    = new Plane(Vec3.Zero, new Vec3(1, 2, 0));
        Ray   groundRay = new Ray(Vec3.Zero + new Vec3(0, 0.2f, 0), Vec3.AngleXZ(Time.Totalf * 90, -2).Normalized());

        Lines.Add(groundRay.position, groundRay.position + groundRay.direction * 0.1f, new Color32(255, 0, 0, 255), 2 * Units.mm2m);
        planeMesh.Draw(material, Matrix.TRS(Vec3.Zero, Quat.LookDir(ground.normal), 0.25f), colObj);
        if (groundRay.Intersect(ground, out Vec3 groundAt))
        {
            sphereMesh.Draw(material, Matrix.TS(groundAt, 0.02f), colIntersect);
        }

        UI.AffordanceEnd();

        if (Tests.IsTesting)
        {
            Renderer.Screenshot(posePlaneRay.position + new Vec3(0.0f, 0.3f, 0.15f), posePlaneRay.position + Vec3.Up * 0.1f, 400, 400, "../../../docs/img/screenshots/RayIntersectPlane.jpg");
        }

        // Line and Plane
        bool linePlaneActive = UI.AffordanceBegin("LinePlane", ref poseLinePlane, new Bounds(Vec3.One * 0.4f));

        boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), linePlaneActive ? active : notActive);

        Plane groundLinePlane = new Plane(Vec3.Zero, new Vec3(1, 2, 0));
        Ray   groundLineRay   = new Ray(Vec3.Zero + new Vec3(0, 0.25f, 0), Vec3.AngleXZ(Time.Totalf * 90, -2).Normalized());
        Vec3  groundLineP1    = groundLineRay.position + groundLineRay.direction * (SKMath.Cos(Time.Totalf * 3) + 1) * 0.2f;
        Vec3  groundLineP2    = groundLineRay.position + groundLineRay.direction * ((SKMath.Cos(Time.Totalf * 3) + 1) * 0.2f + 0.1f);

        Lines.Add(groundLineP1, groundLineP2, colTest, 2 * Units.mm2m);
        sphereMesh.Draw(material, Matrix.TS(groundLineP1, 0.01f), colTest);
        sphereMesh.Draw(material, Matrix.TS(groundLineP2, 0.01f), colTest);
        bool groundLineIntersects = groundLinePlane.Intersect(groundLineP1, groundLineP2, out Vec3 groundLineAt);

        planeMesh.Draw(material, Matrix.TRS(Vec3.Zero, Quat.LookDir(groundLinePlane.normal), 0.25f), groundLineIntersects? colIntersect : colObj);
        if (groundLineIntersects)
        {
            sphereMesh.Draw(material, Matrix.TS(groundLineAt, 0.02f), colIntersect);
        }

        UI.AffordanceEnd();

        if (Tests.IsTesting)
        {
            Renderer.Screenshot(poseLinePlane.position + new Vec3(0.0f, 0.3f, 0.15f), poseLinePlane.position + Vec3.Up * 0.1f, 400, 400, "../../../docs/img/screenshots/LineIntersectPlane.jpg");
        }

        // Sphere and Ray
        bool sphereRayActive = UI.AffordanceBegin("SphereRay", ref poseSphereRay, new Bounds(Vec3.One * 0.4f));

        boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), sphereRayActive ? active : notActive);

        Sphere sphere    = new Sphere(Vec3.Zero, 0.25f);
        Vec3   sphereDir = Vec3.AngleXZ(Time.Totalf * 90, SKMath.Cos(Time.Totalf * 3) * 1.5f + 0.1f).Normalized();
        Ray    sphereRay = new Ray(sphere.center - sphereDir * 0.35f, sphereDir);

        Lines.Add(sphereRay.position, sphereRay.position + sphereRay.direction * 0.1f, colTest, 2 * Units.mm2m);
        if (sphereRay.Intersect(sphere, out Vec3 sphereAt))
        {
            sphereMesh.Draw(material, Matrix.TS(sphereAt, 0.02f), colIntersect);
        }
        sphereMesh.Draw(material, Matrix.TS(sphere.center, 0.25f), colObj);

        UI.AffordanceEnd();

        if (Tests.IsTesting)
        {
            Renderer.Screenshot(poseSphereRay.position + new Vec3(0.0f, 0.3f, 0.15f), poseSphereRay.position, 400, 400, "../../../docs/img/screenshots/RayIntersectSphere.jpg");
        }

        // Bounds and Ray
        bool boundsRayActive = UI.AffordanceBegin("BoundsRay", ref poseBoundsRay, new Bounds(Vec3.One * 0.4f));

        boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), boundsRayActive ? active : notActive);

        Bounds bounds    = new Bounds(Vec3.Zero, Vec3.One * 0.25f);
        Vec3   boundsDir = Vec3.AngleXZ(Time.Totalf * 90, SKMath.Cos(Time.Totalf * 3) * 1.5f).Normalized();
        Ray    boundsRay = new Ray(bounds.center - boundsDir * 0.35f, boundsDir);

        Lines.Add(boundsRay.position, boundsRay.position + boundsRay.direction * 0.1f, colTest, 2 * Units.mm2m);
        if (boundsRay.Intersect(bounds, out Vec3 boundsAt))
        {
            sphereMesh.Draw(material, Matrix.TS(boundsAt, 0.02f), colIntersect);
        }
        cubeMesh.Draw(material, Matrix.TS(bounds.center, 0.25f), colObj);

        UI.AffordanceEnd();

        if (Tests.IsTesting)
        {
            Renderer.Screenshot(poseBoundsRay.position + new Vec3(0.0f, 0.3f, 0.15f), poseBoundsRay.position, 400, 400, "../../../docs/img/screenshots/RayIntersectBounds.jpg");
        }

        // Bounds and Line
        bool boundsLineActive = UI.AffordanceBegin("BoundsLine", ref poseBoundsLine, new Bounds(Vec3.One * 0.4f));

        boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), boundsLineActive ? active : notActive);

        Bounds boundsLine   = new Bounds(Vec3.Zero, Vec3.One * 0.25f);
        Vec3   boundsLineP1 = boundsLine.center + Vec3.AngleXZ(Time.Totalf * 45, SKMath.Cos(Time.Totalf * 3)) * 0.35f;
        Vec3   boundsLineP2 = boundsLine.center + Vec3.AngleXZ(Time.Totalf * 90, SKMath.Cos(Time.Totalf * 6)) * SKMath.Cos(Time.Totalf) * 0.35f;

        Lines.Add(boundsLineP1, boundsLineP2, colTest, 2 * Units.mm2m);
        sphereMesh.Draw(material, Matrix.TS(boundsLineP1, 0.01f), colTest);
        sphereMesh.Draw(material, Matrix.TS(boundsLineP2, 0.01f), colTest);
        cubeMesh.Draw(material, Matrix.TS(boundsLine.center, 0.25f),
                      boundsLine.Contains(boundsLineP1, boundsLineP2) ? colIntersect : colObj);

        UI.AffordanceEnd();

        if (Tests.IsTesting)
        {
            Renderer.Screenshot(poseBoundsLine.position + new Vec3(0.0f, 0.3f, 0.15f), poseBoundsLine.position, 400, 400, "../../../docs/img/screenshots/LineIntersectBounds.jpg");
        }

        // Cross product
        bool crossActive = UI.AffordanceBegin("Cross", ref poseCross, new Bounds(Vec3.One * 0.4f));

        boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), crossActive ? active : notActive);

        Vec3 crossStart = Vec3.Zero;
        //Vec3 right      = Vec3.Cross(Vec3.Forward, Vec3.Up); // These are the same!
        Vec3 right = Vec3.PerpendicularRight(Vec3.Forward, Vec3.Up);

        Lines.Add(crossStart, crossStart + Vec3.Up * 0.1f, new Color32(255, 255, 255, 255), 2 * Units.mm2m);
        Lines.Add(crossStart, crossStart + Vec3.Forward * 0.1f, new Color32(255, 255, 255, 255), 2 * Units.mm2m);
        Lines.Add(crossStart, crossStart + right * 0.1f, new Color32(0, 255, 0, 255), 2 * Units.mm2m);
        Text.Add("Up", Matrix.TRS(crossStart + Vec3.Up * 0.1f, Quat.LookDir(-Vec3.Forward), 1), TextAlign.XCenter | TextAlign.YBottom);
        Text.Add("Fwd", Matrix.TRS(crossStart + Vec3.Forward * 0.1f, Quat.LookDir(-Vec3.Forward), 1), TextAlign.XCenter | TextAlign.YBottom);
        Text.Add("Vec3.Cross(Fwd,Up)", Matrix.TRS(crossStart + right * 0.1f, Quat.LookDir(-Vec3.Forward), 1), TextAlign.XCenter | TextAlign.YBottom);

        UI.AffordanceEnd();

        if (Tests.IsTesting)
        {
            Renderer.Screenshot(poseCross.position + new Vec3(0.075f, 0.1f, 0.15f), poseCross.position + new Vec3(0.075f, 0, 0), 400, 400, "../../../docs/img/screenshots/CrossProduct.jpg");
        }
    }
 /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnSetTransform(ref Vec3,ref Quat,ref Vec3)"/>.</summary>
 protected override void OnSetTransform(ref Vec3 pos, ref Quat rot, ref Vec3 scl)
 {
     base.OnSetTransform(ref pos, ref rot, ref scl);
     UpdatePhysicsModel();
 }
Beispiel #37
0
 //Limits rotation to a single degree of freedom (along axis)
 protected static Quat Limit1DOF(Quat rotation, Vec3 axis)
 {
     return(Quat.RotateFromTo(rotation * axis, axis) * rotation);
 }
Beispiel #38
0
        void TickMove()
        {
            //path find control
            {
                if( pathFindWaitTime != 0 )
                {
                    pathFindWaitTime -= TickDelta;
                    if( pathFindWaitTime < 0 )
                        pathFindWaitTime = 0;
                }

                if( pathFoundedToPosition != MovePosition.ToVec2() && pathFindWaitTime == 0 )
                    path.Clear();

                if( path.Count == 0 )
                {
                    if( pathFindWaitTime == 0 )
                    {
                        if( DoPathFind() )
                        {
                            pathFoundedToPosition = MovePosition.ToVec2();
                            pathFindWaitTime = .5f;
                        }
                        else
                        {
                            pathFindWaitTime = 1.0f;
                        }
                    }
                }
            }

            if( path.Count == 0 )
                return;

            //line movement to path[ 0 ]
            {
                Vec2 destPoint = path[ 0 ];

                Vec2 diff = destPoint - Position.ToVec2();

                if( diff == Vec2.Zero )
                {
                    path.RemoveAt( 0 );
                    return;
                }

                Radian dir = MathFunctions.ATan16( diff.Y, diff.X );

                float halfAngle = dir * 0.5f;
                Quat rot = new Quat( new Vec3( 0, 0, MathFunctions.Sin16( halfAngle ) ),
                    MathFunctions.Cos16( halfAngle ) );
                Rotation = rot;

                Vec2 dirVector = diff.GetNormalizeFast();
                Vec2 dirStep = dirVector * ( Type.MaxVelocity * TickDelta );

                Vec2 newPos = Position.ToVec2() + dirStep;

                if( Math.Abs( diff.X ) <= Math.Abs( dirStep.X ) && Math.Abs( diff.Y ) <= Math.Abs( dirStep.Y ) )
                {
                    //unit at point
                    newPos = path[ 0 ];
                    path.RemoveAt( 0 );
                }

                GridPathFindSystem.Instance.RemoveObjectFromMotionMap( this );

                bool free;
                {
                    float radius = Type.Radius;
                    Rect targetRect = new Rect( newPos - new Vec2( radius, radius ), newPos + new Vec2( radius, radius ) );

                    free = GridPathFindSystem.Instance.IsFreeInMapMotion( targetRect );
                }

                GridPathFindSystem.Instance.AddObjectToMotionMap( this );

                if( free )
                {
                    float newZ = GridPathFindSystem.Instance.GetMotionMapHeight( newPos ) + Type.Height * .5f;
                    Position = new Vec3( newPos.X, newPos.Y, newZ );
                }
                else
                    path.Clear();
            }
        }
Beispiel #39
0
 public unsafe static extern IntPtr /*PhysXJoint*/ Create(IntPtr /*PhysXBody*/ body0, ref Vec3 localPosition0,
                                                          ref Quat localRotation0, IntPtr /*PhysXBody*/ body1, ref Vec3 localPosition1, ref Quat localRotation1);
Beispiel #40
0
 public unsafe static extern IntPtr /*PhysXShape*/ CreateBoxShape(IntPtr /*PhysXBody*/ body, ref Vec3 position,
                                                                  ref Quat rotation, ref Vec3 halfDimension, int materialCount, IntPtr *materials, float mass, int contactGroup);
 /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnSetTransform(ref Vec3,ref Quat,ref Vec3)"/>.</summary>
 protected override void OnSetTransform( ref Vec3 pos, ref Quat rot, ref Vec3 scl )
 {
     base.OnSetTransform( ref pos, ref rot, ref scl );
     if( region != null )
         UpdateRegionTransform();
 }
Beispiel #42
0
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnSetTransform(ref Vec3,ref Quat,ref Vec3)"/>.</summary>
        protected override void OnSetTransform( ref Vec3 pos, ref Quat rot, ref Vec3 scl )
        {
            base.OnSetTransform( ref pos, ref rot, ref scl );

            if( region != null )
                region.SetTransform( Position, Rotation, InfluenceRegionScale );
        }
        //
        protected override void OnAttach()
        {
            base.OnAttach();

            //World serialized data
            {
                if( World.Instance.GetCustomSerializationValue( "remainingTimeForCreateEnemy" ) != null )
                {
                    remainingTimeForCreateEnemy = (float)World.Instance.GetCustomSerializationValue(
                        "remainingTimeForCreateEnemy" );
                }

                if( World.Instance.GetCustomSerializationValue( "gameTime" ) != null )
                    gameTime = (float)World.Instance.GetCustomSerializationValue( "gameTime" );

                if( World.Instance.GetCustomSerializationValue( "level" ) != null )
                    level = (int)World.Instance.GetCustomSerializationValue( "level" );

                if( World.Instance.GetCustomSerializationValue( "remainingCount" ) != null )
                    remainingCount = (int)World.Instance.GetCustomSerializationValue( "remainingCount" );

                if( World.Instance.GetCustomSerializationValue( "remainingCreateCount" ) != null )
                {
                    remainingCreateCount = (int)World.Instance.GetCustomSerializationValue(
                        "remainingCreateCount" );
                }

                if( World.Instance.GetCustomSerializationValue( "createInterval" ) != null )
                {
                    createInterval = (float)World.Instance.GetCustomSerializationValue(
                        "createInterval" );
                }
            }

            GameGuiObject placard = Entities.Instance.GetByName( "Placard_Game" ) as GameGuiObject;
            placard.Damage += GamePlacard_Damage;

            //find enemy spawn points
            foreach( Entity entity in Map.Instance.Children )
            {
                MapObject point = entity as MapObject;

                if( !string.IsNullOrEmpty( entity.TextUserData ) )
                {
                    if( point != null && point.Type.Name == "HelperPoint" )
                        enemySpawnPoints.Add( point );
                }
            }

            screenFont = FontManager.Instance.LoadFont( "Default", .05f );

            if( level == 0 )//for world serialization
                level = 1;

            //get turret start position
            Turret turret = (Turret)Entities.Instance.GetByName( "Turret_Game" );
            if( turret != null )
            {
                turretCreatePosition = turret.Position;
                turretCreateRotation = turret.Rotation;
            }

            UpdateVictoryObjects( false );

            //for world serialization
            foreach( Entity entity in Map.Instance.Children )
            {
                if( entity.IsSetDeleted )
                    continue;

                Unit unit = entity as Unit;
                if( unit == null )
                    continue;

                if( unit is PlayerCharacter )
                    continue;

                if( ( unit.Intellect as AI ) != null || unit is Aircraft )
                {
                    unit.ViewRadius = 300;
                    unit.Destroying += EnemyUnitDestroying;
                    unit.Tick += EnemyUnitTick;
                }
            }

            //for world serialization
            if( gameTime != 0 )
                MainPlayerUnitSubscribeToDestroying();

            //for world serialization
            if( gameTime >= 8 )
                GameMusic.MusicPlay( "Sounds/Music/Action.ogg", true );

            Map.Instance.Tick += Map_Tick;
        }
Beispiel #44
0
        protected override void OnSetTransform( ref Vec3 pos, ref Quat rot, ref Vec3 scl )
        {
            base.OnSetTransform( ref pos, ref rot, ref scl );

            //server side
            if( EntitySystemWorld.Instance.IsServer() )
            {
                //send new position to clients
                Server_SendPositionToClients( EntitySystemWorld.Instance.RemoteEntityWorlds );
            }
        }
Beispiel #45
0
		protected override void OnSetTransform( ref Vec3 pos, ref Quat rot, ref Vec3 scl )
		{
			base.OnSetTransform( ref pos, ref rot, ref scl );

			if( PhysicsModel != null )
			{
				foreach( Body body in PhysicsModel.Bodies )
					body.Sleeping = false;
			}
		}
Beispiel #46
0
        void Server_SendPositionsToAllClients( bool updateAll )
        {
            const float positionEpsilon = .005f;
            const float rotationEpsilon = .001f;
            const float scaleEpsilon = .001f;

            bool positionUpdated = updateAll ||
                !Position.Equals( ref server_sentPositionToClients, positionEpsilon );
            bool rotationUpdated = updateAll ||
                !Rotation.Equals( ref server_sentRotationToClients, rotationEpsilon );
            bool scaleUpdated = updateAll ||
                !Scale.Equals( ref server_sentScaleToClients, scaleEpsilon );

            if( positionUpdated || rotationUpdated || scaleUpdated )
            {
                SendDataWriter writer = BeginNetworkMessage( typeof( Dynamic ),
                    (ushort)NetworkMessages.PositionsToClient );

                writer.Write( positionUpdated );
                if( positionUpdated )
                {
                    writer.Write( Position );
                    server_sentPositionToClients = Position;
                }

                writer.Write( rotationUpdated );
                if( rotationUpdated )
                {
                    writer.Write( Rotation, 16 );
                    server_sentRotationToClients = Rotation;
                }

                writer.Write( scaleUpdated );
                if( scaleUpdated )
                {
                    writer.Write( Scale );
                    server_sentScaleToClients = Scale;
                }

                EndNetworkMessage();
            }
        }
Beispiel #47
0
 public static bool IsUnused(Quat var)
 {
     return IsUnused(var.W);
 }
Beispiel #48
0
        void GetFireParameters( out Vec3 pos, out Quat rot, out float speed )
        {
            Camera camera = RendererWorld.Instance.DefaultCamera;

            pos = catapult.Position + new Vec3( 0, 0, .7f );

            Radian verticalAngle = new Degree( 30 ).InRadians();

            rot = Quat.Identity;
            speed = 0;

            if( catapultFiring )
            {
                Ray startRay = camera.GetCameraToViewportRay( catapultFiringMouseStartPosition );
                Ray ray = camera.GetCameraToViewportRay( MousePosition );

                Plane plane = Plane.FromPointAndNormal( pos, Vec3.ZAxis );

                Vec3 startRayPos;
                if( !plane.RayIntersection( startRay, out startRayPos ) )
                {
                    //must never happen
                }

                Vec3 rayPos;
                if( !plane.RayIntersection( ray, out rayPos ) )
                {
                    //must never happen
                }

                Vec2 diff = rayPos.ToVec2() - startRayPos.ToVec2();

                Radian horizonalAngle = MathFunctions.ATan( diff.Y, diff.X ) + MathFunctions.PI;

                SphereDir dir = new SphereDir( horizonalAngle, verticalAngle );
                rot = Quat.FromDirectionZAxisUp( dir.GetVector() );

                float distance = diff.Length();

                //3 meters clamp
                MathFunctions.Clamp( ref distance, .001f, 3 );

                speed = distance * 10;
            }
        }
Beispiel #49
0
 public unsafe static extern IntPtr /*PhysXBody*/ CreateBody(IntPtr /*PhysXScene*/ pScene,
                                                             [MarshalAs(UnmanagedType.U1)] bool isStatic, ref Vec3 globalPosition, ref Quat globalRotation);
Beispiel #50
0
 public FakeVirtualBone(Float3 solverPosition, Quat solverRotation)
 {
     this.solverPosition = readPosition = solverPosition;
     this.solverRotation = readRotation = solverRotation;
 }
Beispiel #51
0
        protected override void OnSetTransform( ref Vec3 pos, ref Quat rot, ref Vec3 scl )
        {
            base.OnSetTransform( ref pos, ref rot, ref scl );

            if( IsPostCreated )
            {
                if( EntitySystemWorld.Instance.IsServer() )
                {
                    if( Type.NetworkType == EntityNetworkTypes.Synchronized )
                        Server_SendPositionToAllClients();
                }
            }
        }
Beispiel #52
0
    public void Update()
    {
        Hierarchy.Push(Matrix.T(0, 0, -0.3f));

        UI.WindowBegin("Alignment", ref alignWindow, new Vec2(20, 0) * U.cm);
        Vec2 size = new Vec2(5 * U.cm, UI.LineHeight);

        if (UI.Radio("Left", alignX == TextAlign.XLeft, size))
        {
            alignX = TextAlign.XLeft;
        }
        UI.SameLine();
        if (UI.Radio("CenterX", alignX == TextAlign.XCenter, size))
        {
            alignX = TextAlign.XCenter;
        }
        UI.SameLine();
        if (UI.Radio("Right", alignX == TextAlign.XRight, size))
        {
            alignX = TextAlign.XRight;
        }
        if (UI.Radio("Top", alignY == TextAlign.YTop, size))
        {
            alignY = TextAlign.YTop;
        }
        UI.SameLine();
        if (UI.Radio("CenterY", alignY == TextAlign.YCenter, size))
        {
            alignY = TextAlign.YCenter;
        }
        UI.SameLine();
        if (UI.Radio("Bottom", alignY == TextAlign.YBottom, size))
        {
            alignY = TextAlign.YBottom;
        }
        UI.WindowEnd();

        Hierarchy.Push(Matrix.T(0.1f, 0, 0));
        Text.Add("X Center", Matrix.TR(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XCenter | TextAlign.YCenter, alignX | alignY);
        Text.Add("X Left", Matrix.TR(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XLeft | TextAlign.YCenter, alignX | alignY);
        Text.Add("X Right", Matrix.TR(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XRight | TextAlign.YCenter, alignX | alignY);
        Lines.Add(new Vec3(0, .05f, 0), new Vec3(0, .25f, 0), Color32.White, 0.001f);
        Hierarchy.Pop();

        Hierarchy.Push(Matrix.T(-0.1f, 0, 0));
        Text.Add("Y Center", Matrix.TR(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YCenter | TextAlign.XCenter, alignX | alignY);
        Lines.Add(new Vec3(-0.05f, .1f, 0), new Vec3(.05f, .1f, 0), Color32.White, 0.001f);

        Text.Add("Y Top", Matrix.TR(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YTop | TextAlign.XCenter, alignX | alignY);
        Lines.Add(new Vec3(-0.05f, .15f, 0), new Vec3(.05f, .15f, 0), Color32.White, 0.001f);

        Text.Add("Y Bottom", Matrix.TR(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YBottom | TextAlign.XCenter, alignX | alignY);
        Lines.Add(new Vec3(-0.05f, .2f, 0), new Vec3(.05f, .2f, 0), Color32.White, 0.001f);
        Hierarchy.Pop();

        Hierarchy.Push(Matrix.T(0, -0.1f, 0));
        if (Tests.IsTesting)
        {
            Renderer.Screenshot(Hierarchy.ToWorld(new Vec3(0, 0, 0.09f)), Hierarchy.ToWorld(Vec3.Zero), 600, 300, "../../../docs/img/screenshots/BasicText.jpg");
        }
        /// :CodeSample: Text.MakeStyle Font.FromFile Text.Add
        /// Then it's pretty trivial to just draw some text on the screen! Just call
        /// Text.Add on update. If you don't have a TextStyle available, calling it
        /// without one will just fall back on the default style.
        // Text with an explicit text style
        Text.Add(
            "Here's\nSome\nMulti-line\nText!!",
            Matrix.TR(new Vec3(0.1f, 0, 0), Quat.LookDir(0, 0, 1)),
            style);
        // Text using the default text style
        Text.Add(
            "Here's\nSome\nMulti-line\nText!!",
            Matrix.TR(new Vec3(-0.1f, 0, 0), Quat.LookDir(0, 0, 1)));
        /// :End:

        Hierarchy.Push(Matrix.T(0, -0.2f, 0));
        Text.Add(
            "Here's Some Multi-line Text!!",
            Matrix.TR(new Vec3(0, 0.0f, 0), Quat.LookDir(0, 0, 1)),
            new Vec2(SKMath.Cos(Time.Totalf) * 10 + 11, 20) * U.cm,
            TextFit.Clip,
            style, TextAlign.Center, alignX | alignY);
        Hierarchy.Pop();

        Hierarchy.Pop();

        Hierarchy.Pop();
    }
        void TickMove()
        {
            //path find control
            {
                if (pathFindWaitTime != 0)
                {
                    pathFindWaitTime -= TickDelta;
                    if (pathFindWaitTime < 0)
                        pathFindWaitTime = 0;
                }

                // If a path has not been found to the target and the time to wait is zero
                if (pathFoundedToPosition != MovePosition.ToVec2() && pathFindWaitTime == 0)
                    path.Clear();

                // If we don't have a path
                if (path.Count == 0)
                {
                    if (pathFindWaitTime == 0)
                    {
                        // Find a path to move position
                        if (DoPathFind())
                        {
                            pathFoundedToPosition = MovePosition.ToVec2();
                            pathFindWaitTime = .5f;
                        }
                        else
                        {
                            // If a path has not been found, re-try in 1 second
                            pathFindWaitTime = 1.0f;
                        }
                    }
                }
            }

            if (path.Count == 0)
                return;

            //line movement to path[ 0 ]
            {
                Vec2 destPoint = path[0];
                // The difference between the first point in the path and this object's current position
                Vec2 diff = destPoint - Position.ToVec2();

                if (diff == Vec2.Zero)
                {
                    path.RemoveAt(0);
                    return;
                }

                Radian dir = MathFunctions.ATan16(diff.Y, diff.X);

                float halfAngle = dir * 0.5f;
                Quat rot = new Quat(new Vec3(0, 0, MathFunctions.Sin16(halfAngle)),
                    MathFunctions.Cos16(halfAngle));
                // Rotate the object
                Rotation = rot;
                // Normalise the difference vector
                Vec2 dirVector = diff.GetNormalizeFast();
                // The difference vector multiplied by the velocity per 1/30 second
                Vec2 dirStep = dirVector * (Type.MaxVelocity * TickDelta);
                // Calculate the object's new position
                Vec2 newPos = Position.ToVec2() + dirStep;
                // If the first point in the path is less than the direction step
                if (Math.Abs(diff.X) <= Math.Abs(dirStep.X) && Math.Abs(diff.Y) <= Math.Abs(dirStep.Y))
                {
                    // then move to the first position in the path
                    //unit at point
                    newPos = path[0];
                    path.RemoveAt(0);
                }

                GridPathFindSystem.Instance.RemoveObjectFromMotionMap(this);

                bool free;
                {
                    float radius = Type.Radius;
                    Rect targetRect = new Rect(newPos - new Vec2(radius, radius), newPos + new Vec2(radius, radius));

                    free = GridPathFindSystem.Instance.IsFreeInMapMotion(targetRect);
                }

                GridPathFindSystem.Instance.AddObjectToMotionMap(this);

                if (free)
                {
                    float newZ = GridPathFindSystem.Instance.GetMotionMapHeight(newPos) + Type.Height * .5f;
                    // Set the object's position
                    Position = new Vec3(newPos.X, newPos.Y, newZ);
                }
                else
                    path.Clear();
            }
        }
Beispiel #54
0
        //

        protected override void OnAttach()
        {
            base.OnAttach();

            //World serialized data
            {
                if (World.Instance.GetCustomSerializationValue("remainingTimeForCreateEnemy") != null)
                {
                    remainingTimeForCreateEnemy = (float)World.Instance.GetCustomSerializationValue(
                        "remainingTimeForCreateEnemy");
                }

                if (World.Instance.GetCustomSerializationValue("gameTime") != null)
                {
                    gameTime = (float)World.Instance.GetCustomSerializationValue("gameTime");
                }

                if (World.Instance.GetCustomSerializationValue("level") != null)
                {
                    level = (int)World.Instance.GetCustomSerializationValue("level");
                }

                if (World.Instance.GetCustomSerializationValue("remainingCount") != null)
                {
                    remainingCount = (int)World.Instance.GetCustomSerializationValue("remainingCount");
                }

                if (World.Instance.GetCustomSerializationValue("remainingCreateCount") != null)
                {
                    remainingCreateCount = (int)World.Instance.GetCustomSerializationValue(
                        "remainingCreateCount");
                }

                if (World.Instance.GetCustomSerializationValue("createInterval") != null)
                {
                    createInterval = (float)World.Instance.GetCustomSerializationValue(
                        "createInterval");
                }
            }

            GameGuiObject billboard = Entities.Instance.GetByName("HangingBillboard_Game") as GameGuiObject;

            billboard.Damage += GameBillboard_Damage;

            //find enemy spawn points
            foreach (Entity entity in Map.Instance.Children)
            {
                MapObject point = entity as MapObject;

                if (!string.IsNullOrEmpty(entity.TextUserData))
                {
                    if (point != null && point.Type.Name == "HelperPoint")
                    {
                        enemySpawnPoints.Add(point);
                    }
                }
            }

            screenFont = FontManager.Instance.LoadFont("Default", .05f);

            if (level == 0)             //for world serialization
            {
                level = 1;
            }

            //get turret start position
            Turret turret = (Turret)Entities.Instance.GetByName("Turret_Game");

            if (turret != null)
            {
                turretCreatePosition = turret.Position;
                turretCreateRotation = turret.Rotation;
            }

            UpdateVictoryObjects(false);

            //for world serialization
            foreach (Entity entity in Map.Instance.Children)
            {
                if (entity.IsSetForDeletion)
                {
                    continue;
                }

                Unit unit = entity as Unit;
                if (unit == null)
                {
                    continue;
                }

                if (unit is PlayerCharacter)
                {
                    continue;
                }

                if ((unit.Intellect as AI) != null || unit is Aircraft)
                {
                    unit.ViewRadius  = 300;
                    unit.Destroying += EnemyUnitDestroying;
                    unit.Tick       += EnemyUnitTick;
                }
            }

            //for world serialization
            if (gameTime != 0)
            {
                MainPlayerUnitSubscribeToDestroying();
            }

            //for world serialization
            if (gameTime >= 8)
            {
                GameMusic.MusicPlay("Sounds/Music/Action.ogg", true);
            }

            Map.Instance.Tick += Map_Tick;
        }
Beispiel #55
0
        /// <summary>Overridden from <see cref="Engine.MapSystem.MapObject.OnSetTransform(ref Vec3,ref Quat,ref Vec3)"/>.</summary>
        protected override void OnSetTransform(ref Vec3 pos, ref Quat rot, ref Vec3 scl)
        {
            base.OnSetTransform(ref pos, ref rot, ref scl);

            UpdateAttachedObjects();
        }
Beispiel #56
0
        public void Quat4()
        {
            FQuat fq  = FQuat.Euler(( Fix64 )45, ( Fix64 )(-23), ( Fix64 )(-48.88));
            FQuat fq2 = FQuat.Euler(( Fix64 )23, ( Fix64 )(-78), ( Fix64 )(-132.43f));
            Quat  q   = Quat.Euler(45, -23, -48.88f);
            Quat  q2  = Quat.Euler(23, -78, -132.43f);
            FVec3 fv  = new FVec3(12.5f, 9, 8);
            FVec3 fv2 = new FVec3(1, 0, 0);
            Vec3  v   = new Vec3(12.5f, 9, 8);
            Vec3  v2  = new Vec3(1, 0, 0);

            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            this._output.WriteLine(fq2.ToString());
            this._output.WriteLine(q2.ToString());
            Fix64 fa = FQuat.Angle(fq, fq2);
            float a  = Quat.Angle(q, q2);

            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.AngleAxis(( Fix64 )(-123.324), fv);
            q  = Quat.AngleAxis(-123.324f, v);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fa = FQuat.Dot(fq, fq2);
            a  = Quat.Dot(q, q2);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            fq = FQuat.FromToRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.FromToRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Lerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Lerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.Normalize(fq);
            q.Normalize();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.Inverse();
            q = Quat.Inverse(q);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fv = FQuat.Orthogonal(fv);
            v  = Quat.Orthogonal(v);
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = FQuat.Slerp(fq, fq2, ( Fix64 )0.66);
            q  = Quat.Slerp(q, q2, 0.66f);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq = FQuat.LookRotation(FVec3.Normalize(fv), fv2);
            q  = Quat.LookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.ToAngleAxis(out fa, out fv);
            q.ToAngleAxis(out a, out v);
            this._output.WriteLine(fa.ToString());
            this._output.WriteLine(a.ToString());
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fq = fq.Conjugate();
            q  = q.Conjugate();
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
            fq.SetLookRotation(FVec3.Normalize(fv), fv2);
            q.SetLookRotation(Vec3.Normalize(v), v2);
            this._output.WriteLine(fq.ToString());
            this._output.WriteLine(q.ToString());
        }
Beispiel #57
0
        protected override void OnSetTransform( ref Vec3 pos, ref Quat rot, ref Vec3 scl )
        {
            base.OnSetTransform( ref pos, ref rot, ref scl );

            //server side
            if( IsPostCreated )
            {
                if( EntitySystemWorld.Instance.IsServer() )
                {
                    if( Server_EnableSynchronizationPositionsToClients &&
                        Type.NetworkType == EntityNetworkTypes.Synchronized )
                    {
                        if( AttachedMapObjectParent == null )//no update for attached MapObjects
                        {
                            if( PhysicsModel != null )
                                Server_SendBodiesPositionsToAllClients( false );
                            else
                                Server_SendPositionsToAllClients( false );
                        }
                    }
                }
            }
        }
Beispiel #58
0
    public void Update(float time_delta)
    {
        // ui
        _Time         += time_delta;
        _TimeText.Text = string.Format("{0:F2}", _Time);

        _SpeedText.Text = string.Format("{0:F1}", _Velocity.Length);

        // car
        entity.Position += _Velocity * time_delta;
        if (_Velocity.SquaredLength / time_delta > 0.01f)
        {
            Vec3 drag  = _Velocity * DragConstant;
            Vec3 accel = drag / Mass;
            if ((accel * time_delta).SquaredLength > _Velocity.SquaredLength)
            {
                _Velocity = new Vec3(0, 0, 0);
            }
            else
            {
                _Velocity += accel * time_delta;
            }
        }
        else
        {
            _Velocity = new Vec3(0, 0, 0);
        }

        Vec3 dir = new Vec3(Mathf.Sin(_Yaw), 0, Mathf.Cos(_Yaw));

        if (_Velocity.Length > 0.1)
        {
            Vec3  dir_vel = dir * _Velocity.Length;
            float t       = Mathf.Min(time_delta * 5, 1);
            _Velocity = _Velocity * (1 - t) + dir_vel * t;
        }

        float roll_angle = getRoll(dir, _Velocity);
        var   roll       = new Quat(new Vec3(0, 0, 1), roll_angle);

        Mesh.Rotation = new Quat(new Vec3(0, 1, 0), _Yaw) * roll;
        Mesh.Position = entity.Position;
        float camera_yaw = _Yaw;

        if (_Velocity.Length > 0.01f)
        {
            camera_yaw = Mathf.Atan2(_Velocity.x, _Velocity.z);
        }
        entity.Rotation = new Quat(new Vec3(0, 1, 0), camera_yaw);

        if (IsKeyDown('d'))
        {
            _Yaw -= time_delta;
        }
        if (IsKeyDown('a'))
        {
            _Yaw += time_delta;
        }
        if (IsKeyDown('w'))
        {
            Vec3 force = new Vec3();
            force.x = Mathf.Sin(_Yaw) * Force;
            force.z = Mathf.Cos(_Yaw) * Force;
            Vec3 accel = force / Mass;
            _Velocity += accel * time_delta;
        }

        // particles
        if (_Velocity.Length < 3)
        {
            _LeftParticlesEmitter.IsAutoemit  = false;
            _RightParticlesEmitter.IsAutoemit = false;
        }
        else
        {
            _LeftParticlesEmitter.IsAutoemit  = roll_angle < -0.1f;
            _RightParticlesEmitter.IsAutoemit = roll_angle > 0.1f;
        }
    }
Beispiel #59
0
 public Sphere(Vect3 position, Quat rotation, double radius)
 {
     Position = position;
     Rotation = rotation;
     Radius = radius;
 }
Beispiel #60
0
    public void Update()
    {
        Tests.Screenshot("PBRBalls.jpg", 1024, 1024, new Vec3(0, 0, -0.1f), new Vec3(0, 0, -1));

        Hierarchy.Push(Matrix.T(0, 0, -1));

        if (!Tests.IsTesting)
        {
            UI.HandleBegin("Model", ref modelPose, pbrModel.Bounds * .2f);
            pbrModel.Draw(Matrix.TRS(Vec3.Zero, Quat.FromAngles(0, 180, 0), 0.2f));
            UI.HandleEnd();
        }

        for (int y = 0; y < materialGrid; y++)
        {
            for (int x = 0; x < materialGrid; x++)
            {
                Renderer.Add(sphereMesh, pbrMaterials[x + y * materialGrid], Matrix.TS(new Vec3(x - materialGrid / 2.0f + 0.5f, y - materialGrid / 2.0f + 0.5f, -1) / 4.0f, 0.2f));
            }
        }
        Text.Add("Metallic -->", Matrix.TRS(new Vec3(0, materialGrid / 8.0f + 0.2f, -0.25f), Quat.FromAngles(0, 180, 0), 4));
        Text.Add("Roughness -->", Matrix.TRS(new Vec3(materialGrid / -8.0f - 0.2f, 0, -0.25f), Quat.FromAngles(0, 180, -90), 4));
        Hierarchy.Pop();
    }