Пример #1
0
		/// <summary>
        /// Extract translation from transform matrix.
        /// </summary>
        /// <param name="matrix">Transform matrix. This parameter is passed by reference
        /// to improve performance; no changes will be made to it.</param>
        /// <returns>
        /// Translation offset.
        /// </returns>
        public static Vector3 ExtractTranslationFromMatrix(ref Matrix4x4 matrix) {
            Vector3 translate;
            translate.x = matrix.m03;
            translate.y = matrix.m13;
            translate.z = matrix.m23;
            return translate;
        }
Пример #2
0
 public bool CalculateScaleTimeMatrix(float fromTime, float toTime, float offsetTime, float pivotTime, float frameRate, out Matrix4x4 transform, out bool flipKeys)
 {
     transform = Matrix4x4.identity;
     flipKeys = false;
     float num = !Mathf.Approximately(frameRate, 0f) ? (1f / frameRate) : 0.001f;
     float f = toTime - pivotTime;
     float num3 = fromTime - pivotTime;
     if ((Mathf.Abs(f) - offsetTime) < 0f)
     {
         return false;
     }
     f = (Mathf.Sign(f) != Mathf.Sign(num3)) ? (f + offsetTime) : (f - offsetTime);
     if (Mathf.Approximately(num3, 0f))
     {
         transform.SetTRS(new Vector3(f, 0f, 0f), Quaternion.identity, Vector3.one);
         flipKeys = false;
         return true;
     }
     if (Mathf.Abs(f) < num)
     {
         f = (f >= 0f) ? num : -num;
     }
     float x = f / num3;
     transform.SetTRS(new Vector3(pivotTime, 0f, 0f), Quaternion.identity, Vector3.one);
     transform *= Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(x, 1f, 1f));
     transform *= Matrix4x4.TRS(new Vector3(-pivotTime, 0f), Quaternion.identity, Vector3.one);
     flipKeys = x < 0f;
     return true;
 }
        public static Bounds GetPartColliderBoundsInBasis(this Part part, Matrix4x4 worldToBasisMatrix, int excessiveVerts = 2500)
        {
            Transform[] transforms = part.FindModelComponents<Transform>();
            Bounds bounds = new Bounds();
            for (int i = 0; i < transforms.Length; i++)
            {
                Transform t = transforms[i];

                MeshCollider mc = t.GetComponent<MeshCollider>();
                Mesh m;
                Matrix4x4 matrix = worldToBasisMatrix * t.localToWorldMatrix;

                if (mc == null)
                {
                    BoxCollider bc = t.GetComponent<BoxCollider>();
                    if (bc != null)
                    {
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.min));
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.max));
                    }
                    continue;
                }
                else
                    m = mc.sharedMesh;

                if (m == null)
                    continue;

                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.min));
                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.max));

            }
            return bounds;
        }
Пример #4
0
 public bool CalculateScaleValueMatrix(float fromValue, float toValue, float offsetValue, float pivotValue, out Matrix4x4 transform, out bool flipKeys)
 {
     transform = Matrix4x4.identity;
     flipKeys = false;
     float num = 0.001f;
     float f = toValue - pivotValue;
     float num3 = fromValue - pivotValue;
     if ((Mathf.Abs(f) - offsetValue) < 0f)
     {
         return false;
     }
     f = (Mathf.Sign(f) != Mathf.Sign(num3)) ? (f + offsetValue) : (f - offsetValue);
     if (Mathf.Approximately(num3, 0f))
     {
         transform.SetTRS(new Vector3(0f, f, 0f), Quaternion.identity, Vector3.one);
         flipKeys = false;
         return true;
     }
     if (Mathf.Abs(f) < num)
     {
         f = (f >= 0f) ? num : -num;
     }
     float y = f / num3;
     transform.SetTRS(new Vector3(0f, pivotValue, 0f), Quaternion.identity, Vector3.one);
     transform *= Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, y, 1f));
     transform *= Matrix4x4.TRS(new Vector3(0f, -pivotValue, 0f), Quaternion.identity, Vector3.one);
     flipKeys = y < 0f;
     return true;
 }
Пример #5
0
		/// <summary>
		/// Draw the vessel view.
		/// </summary>
		/// <param name="screen"></param>
		/// <param name="cameraAspect"></param>
		/// <returns></returns>
		public bool RenderView(RenderTexture screen, float cameraAspect)
		{
			// MOARdV TODO: We can make this so the transform isn't updated
			// every frame by using a heuristic to wrap up the code from
			// here ...
			screenTransform = GetViewTransform();
			UpdateViewMatrix();
			//... to here, if it seems too expensive (do we have any real-time
			// timers available to measure this)?  On my system, it's not
			// causing any grief, but I've got a higher end system.

			Vector4 displayPosition = viewDisplayPosition;
			displayPosition.z = Mathf.Min(screen.width - displayPosition.x, displayPosition.z);
			displayPosition.w = Mathf.Min(screen.height - displayPosition.y, displayPosition.w);

			GL.Clear(true, true, backgroundColorValue);

			GL.PushMatrix();

			GL.LoadPixelMatrix(-displayPosition.z * 0.5f, displayPosition.z * 0.5f, -displayPosition.w * 0.5f, displayPosition.w * 0.5f);
			GL.Viewport(new Rect(displayPosition.x, screen.height - displayPosition.y - displayPosition.w, displayPosition.z, displayPosition.w));

			lineMaterial.SetPass(0);
			foreach(Part vesselPart in vessel.parts) {
				RenderPart(vesselPart);
			}
			GL.PopMatrix();
			GL.Viewport(new Rect(0, 0, screen.width, screen.height));

			return true;
		}
Пример #6
0
		public static void DrawScatterBrush(Vector3 point, Vector3 normal, z_BrushSettings settings, Matrix4x4 localToWorldMatrix)
		{
			Vector3 p = localToWorldMatrix.MultiplyPoint3x4(point);
			Vector3 n = localToWorldMatrix.MultiplyVector(normal).normalized;
			
			float r = settings.radius;
			Vector3 a = Vector3.zero;
			Quaternion rotation = Quaternion.LookRotation(normal, Vector3.up);

			for(int i = 0; i < 10; i++)
			{
				a.x = Mathf.Cos(Random.Range(0f, 360f));
				a.y = Mathf.Sin(Random.Range(0f, 360f));
				a = a.normalized * Random.Range(0f, r);

				Vector3 v = localToWorldMatrix.MultiplyPoint3x4(point + rotation * a);

				Handles.DrawLine(v, v  + (n * .5f));

				Handles.CubeCap(i + 2302, v, Quaternion.identity, .01f);
			}

			/// radius
			Handles.DrawWireDisc(p, n, settings.radius);
		}
        public IntakeCrossSectionAdjuster(PartModule intake, Matrix4x4 worldToVesselMatrix)
        {
            this.part = intake.part;
            intakeModule = intake as ModuleResourceIntake;
            intakeTrans = intakeModule.intakeTransform;

            if (!string.IsNullOrEmpty(intakeModule.occludeNode))
                node = intakeModule.node; 
            
            foreach (AttachNode candidateNode in part.attachNodes)
                if (candidateNode.nodeType == AttachNode.NodeType.Stack && Vector3.Dot(candidateNode.position, (part.transform.worldToLocalMatrix * intakeTrans.localToWorldMatrix).MultiplyVector(Vector3.forward)) > 0)
                {
                    if (candidateNode == node)
                        continue;

                    nodeOffsetArea = candidateNode.size;
                    if (nodeOffsetArea == 0)
                        nodeOffsetArea = 0.5;

                    nodeOffsetArea *= 0.625;     //scale it up as needed
                    nodeOffsetArea *= nodeOffsetArea;
                    nodeOffsetArea *= Math.PI;  //calc area;

                    nodeOffsetArea *= -1;        //and the adjustment area
                    break;
                }

            thisToVesselMatrix = worldToVesselMatrix * intakeTrans.localToWorldMatrix;

            vehicleBasisForwardVector = Vector3.forward;
            vehicleBasisForwardVector = thisToVesselMatrix.MultiplyVector(vehicleBasisForwardVector);

            Type intakeType = intake.GetType();
            intakeArea = (float)intakeType.GetField("Area").GetValue(intake);
        }
Пример #8
0
        public static Matrix4x4 ProjectionFromIntrinsicCamera(Matrix4x4 cameraMatrix,
                float projectorWidth, float projectorHeight)
        {
            float fx = cameraMatrix[0, 0];
            float fy = cameraMatrix[1, 1];
            float cx = cameraMatrix[0, 2];
            float cy = cameraMatrix[1, 2];

            float near = 0.1f;
            float far = 100.0f;

            float w = projectorWidth;
            float h = projectorHeight;

            // fx, fy, cx, cy are in pixels
            // input coordinate system is x left, y up, z forward (right handed)
            // project to view volume where x, y in [-1, 1], z in [0, 1], x right, y up, z forward
            // pre-multiply matrix

            // -(2 * fx / w),           0,   -(2 * cx / w - 1),                           0,
            //             0,  2 * fy / h,      2 * cy / h - 1,                           0,
            //             0,           0,  far / (far - near),  -near * far / (far - near),
            //             0,           0,                   -1,                           0
            Matrix4x4 projectionRightHanded = new Matrix4x4() {
                m00 = 2 * fx / w, m01 = 0, m02 = 1 - 2 * cx / w, m03 = 0,
                m10 = 0, m11 = 2 * fy / h, m12 = 1 - 2 * cy / h, m13 = 0,
                m20 = 0, m21 = 0,          m22 = -(far + near) / (far - near), m23 = -2 * far * near / (far - near),
                m30 = 0, m31 = 0,          m32 = -1, m33 = 0
            };
            return Matrix4x4.Scale(new Vector3(-1, 1, 1)) * projectionRightHanded *
                Matrix4x4.Scale(new Vector3(-1, 1, 1));
        }
		/// <summary>
		/// This function returns OpenGL style projection matrix.
		/// </summary>
		/// <returns>
		/// output parametor.
		/// </returns>
		public Matrix4x4 getUnityProjectionMatrix()
		{
			Matrix4x4 mat=new Matrix4x4();
			NyARFrustum.FrustumParam f=this.getFrustum().getFrustumParam(new NyARFrustum.FrustumParam());
			NyARUnityUtil.toCameraFrustumRH(this._ref_param,1,f.near,f.far,ref mat);
			return mat;
		}
Пример #10
0
		public static void DrawBrush(	Vector3 point,
										Vector3 normal,
										z_BrushSettings brushSettings,
										Matrix4x4 matrix,
										Color innerColor,
										Color outerColor)
		{
			PushHandleColor();

			Vector3 p = matrix.MultiplyPoint3x4(point);
			Vector3 n = matrix.MultiplyVector(normal).normalized;
			
			/// radius
			Handles.color = outerColor;
			Handles.DrawWireDisc(p, n, brushSettings.radius);

			/// falloff
			Handles.color = innerColor;
			Handles.DrawWireDisc(p, n, brushSettings.radius * brushSettings.falloff);

			Handles.color = new Color(	Mathf.Abs(n.x),
										Mathf.Abs(n.y),
										Mathf.Abs(n.z),
										1f);

			Handles.DrawLine(p, p + n.normalized * HandleUtility.GetHandleSize(p));

			PopHandleColor();
		}
Пример #11
0
 private void AdjustMidpointHandleColor(Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, Matrix4x4 transform, float alphaFactor)
 {
     float num;
     Vector3 vector = transform.MultiplyPoint(localPos);
     Vector3 lhs = transform.MultiplyVector(localTangent);
     Vector3 rhs = transform.MultiplyVector(localBinormal);
     Vector3 normalized = Vector3.Cross(lhs, rhs).normalized;
     if (Camera.current.isOrthoGraphic)
     {
         num = Vector3.Dot(-Camera.current.transform.forward, normalized);
     }
     else
     {
         Vector3 vector6 = Camera.current.transform.position - vector;
         num = Vector3.Dot(vector6.normalized, normalized);
     }
     if (num < -0.0001f)
     {
         alphaFactor *= 0.2f;
     }
     if (alphaFactor < 1f)
     {
         Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, Handles.color.a * alphaFactor);
     }
 }
Пример #12
0
 private void AdjustEdgeHandleColor(Vector3 handlePos, Vector3 slideDir1, Vector3 slideDir2, Matrix4x4 transform, float alphaFactor)
 {
     bool flag;
     Vector3 inPoint = transform.MultiplyPoint(handlePos);
     Vector3 normalized = transform.MultiplyVector(slideDir1).normalized;
     Vector3 rhs = transform.MultiplyVector(slideDir2).normalized;
     if (Camera.current.isOrthoGraphic)
     {
         flag = (Vector3.Dot(-Camera.current.transform.forward, normalized) < 0f) && (Vector3.Dot(-Camera.current.transform.forward, rhs) < 0f);
     }
     else
     {
         Plane plane = new Plane(normalized, inPoint);
         Plane plane2 = new Plane(rhs, inPoint);
         flag = !plane.GetSide(Camera.current.transform.position) && !plane2.GetSide(Camera.current.transform.position);
     }
     if (flag)
     {
         alphaFactor *= 0.2f;
     }
     if (alphaFactor < 1f)
     {
         Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, Handles.color.a * alphaFactor);
     }
 }
Пример #13
0
 public void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     switch (colorBlindMode)
     {
     case ColorBlindMode.None:
         filterMatrix = Matrix4x4.identity;
         break;
     case ColorBlindMode.Protanopia:
         filterMatrix.SetColumn(0, new Vector4(0.567f, 0.433f, 0.0f, 0.0f));
         filterMatrix.SetColumn(1, new Vector4(0.558f, 0.442f, 0.0f, 0.0f));
         filterMatrix.SetColumn(2, new Vector4(0.0f, 0.242f, 0.758f, 0.0f));
         filterMatrix.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
         break;
     case ColorBlindMode.Deuteranopia:
         filterMatrix.SetColumn(0, new Vector4(0.625f, 0.375f, 0.0f, 0.0f));
         filterMatrix.SetColumn(1, new Vector4(0.7f, 0.3f, 0.0f, 0.0f));
         filterMatrix.SetColumn(2, new Vector4(0.0f, 0.3f, 0.7f, 0.0f));
         filterMatrix.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
         break;
     case ColorBlindMode.Tritanopia:
         filterMatrix.SetColumn(0, new Vector4(0.95f, 0.05f, 0.0f, 0.0f));
         filterMatrix.SetColumn(1, new Vector4(0.0f, 0.433f, 0.567f, 0.0f));
         filterMatrix.SetColumn(2, new Vector4(0.0f, 0.475f, 0.525f, 0.0f));
         filterMatrix.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
         break;
     default:
         break;
     }
     FilterMaterial.SetMatrix("_Filter", filterMatrix);
     Graphics.Blit(source, destination, FilterMaterial);
 }
 public MeshData(MeshFilter meshFilter)
 {
     Transform = meshFilter.transform.localToWorldMatrix;
     Verts = meshFilter.sharedMesh.vertices;
     Normals = meshFilter.sharedMesh.normals;
     Indices = meshFilter.sharedMesh.triangles;
 }
        public IntegratedIntakeEngineCrossSectionAdjuster(PartModule intake, Matrix4x4 worldToVesselMatrix)
        {
            this.part = intake.part;
            intakeModule = intake as ModuleResourceIntake;
            intakeTrans = intakeModule.intakeTransform;
            //ModuleResourceIntake intake = intake;


            /*vehicleBasisForwardVector = Vector3.forward;//intakeTrans.forward;

            foreach(AttachNode node in part.attachNodes)
                if(node.nodeType == AttachNode.NodeType.Stack && Vector3.Dot(node.position, (part.transform.worldToLocalMatrix * intakeTrans.localToWorldMatrix).MultiplyVector(Vector3.forward)) > 0)
                {
                    frontNode = node;
                    break;
                }*/

            thisToVesselMatrix = worldToVesselMatrix * intakeTrans.localToWorldMatrix;

            vehicleBasisForwardVector = Vector3.forward;
            vehicleBasisForwardVector = thisToVesselMatrix.MultiplyVector(vehicleBasisForwardVector);

            Type intakeType = intake.GetType();
            intakeArea = (float)intakeType.GetField("Area").GetValue(intake);
        }
Пример #16
0
        void LateUpdate()
        {
            Camera cam = gameObject.GetComponent<Camera>();
            float left   = scaleFactor * -viewportWidth / 2.0f + eyeHorizOffset;
            float right  = scaleFactor *  viewportWidth / 2.0f + eyeHorizOffset;
            float top    = scaleFactor *  viewportHeight / 2.0f;
            float bottom = scaleFactor * -viewportHeight / 2.0f;
            float near = cam.nearClipPlane;
            float far = cam.farClipPlane;

            float x =  (2.0f * near) / (right - left);
            float y =  (2.0f * near) / (top - bottom);
            float a =  (right + left) / (right - left);
            float b =  (top + bottom) / (top - bottom);
            float c = -(far + near) / (far - near);
            float d = -(2.0f * far * near) / (far - near);
            float e = -1.0f;

            Matrix4x4 m = new Matrix4x4();
            m[0,0] = x;   m[0,1] = 0f;  m[0,2] = a;  m[0,3] = 0f;
            m[1,0] = 0f;  m[1,1] = y;   m[1,2] = b;  m[1,3] = 0f;
            m[2,0] = 0f;  m[2,1] = 0f;  m[2,2] = c;  m[2,3] = d;
            m[3,0] = 0f;  m[3,1] = 0f;  m[3,2] = e;  m[3,3] = 0f;

            cam.projectionMatrix = m;
        }
Пример #17
0
		private static void DrawOrbit(Orbit o, CelestialBody referenceBody, Matrix4x4 screenTransform, int numSegments)
		{
			if (!o.activePatch) {
				return;
			}

			double startTA;
			double endTA;
			double now = Planetarium.GetUniversalTime();
			if (o.patchEndTransition != Orbit.PatchTransitionType.FINAL) {
				startTA = o.TrueAnomalyAtUT(o.StartUT);
				endTA = o.TrueAnomalyAtUT(o.EndUT);
				if (endTA < startTA) {
					endTA += 2.0 * Math.PI;
				}
			} else {
				startTA = o.GetUTforTrueAnomaly(0.0, now);
				endTA = startTA + 2.0 * Math.PI;
			}
			double dTheta = (endTA - startTA) / (double)numSegments;
			double theta = startTA;
			double timeAtTA = o.GetUTforTrueAnomaly(theta, now);
			Vector3 lastVertex = screenTransform.MultiplyPoint3x4(o.getRelativePositionFromTrueAnomaly(theta).xzy + (o.referenceBody.getTruePositionAtUT(timeAtTA)) - (referenceBody.getTruePositionAtUT(timeAtTA)));
			for (int i = 0; i < numSegments; ++i) {
				GL.Vertex3(lastVertex.x, lastVertex.y, 0.0f);
				theta += dTheta;
				timeAtTA = o.GetUTforTrueAnomaly(theta, now);

				Vector3 newVertex = screenTransform.MultiplyPoint3x4(o.getRelativePositionFromTrueAnomaly(theta).xzy + (o.referenceBody.getTruePositionAtUT(timeAtTA)) - (referenceBody.getTruePositionAtUT(timeAtTA)));
				GL.Vertex3(newVertex.x, newVertex.y, 0.0f);

				lastVertex = newVertex;
			}
		}
        public void addPayload(Bounds box, Matrix4x4 boxTm)
        {
            Matrix4x4 m=w2l*boxTm;

            Vector3 p0=box.min, p1=box.max;
            var verts=new Vector3[8];
            for (int i=0; i<8; ++i)
              verts[i]=m.MultiplyPoint3x4(new Vector3(
            (i&1)!=0 ? p1.x : p0.x,
            (i&2)!=0 ? p1.y : p0.y,
            (i&4)!=0 ? p1.z : p0.z));

            addPayloadEdge(verts[0], verts[1]);
            addPayloadEdge(verts[2], verts[3]);
            addPayloadEdge(verts[4], verts[5]);
            addPayloadEdge(verts[6], verts[7]);

            addPayloadEdge(verts[0], verts[2]);
            addPayloadEdge(verts[1], verts[3]);
            addPayloadEdge(verts[4], verts[6]);
            addPayloadEdge(verts[5], verts[7]);

            addPayloadEdge(verts[0], verts[4]);
            addPayloadEdge(verts[1], verts[5]);
            addPayloadEdge(verts[2], verts[6]);
            addPayloadEdge(verts[3], verts[7]);
        }
Пример #19
0
 	public static bool IntersectRayMesh(Ray ray, Mesh mesh, Matrix4x4 matrix, out RaycastHit hit)
 	{
 		var parameters = new object[]{ray,mesh,matrix,null};
 		bool result = (bool)meth_IntersectRayMesh.Invoke(null,parameters);
 		hit = (RaycastHit)parameters[3];
       return result;
    }
        public AirbreathingEngineCrossSectonAdjuster(ModuleEngines engine, Matrix4x4 worldToVesselMatrix)
        {
            vehicleBasisForwardVector = Vector3.forward;
            //for (int i = 0; i < engine.thrustTransforms.Count; i++)
            //    vehicleBasisForwardVector += engine.thrustTransforms[i].forward;

            thisToVesselMatrix = worldToVesselMatrix * engine.thrustTransforms[0].localToWorldMatrix;

            vehicleBasisForwardVector = thisToVesselMatrix.MultiplyVector(vehicleBasisForwardVector);

            vehicleBasisForwardVector.Normalize();
            vehicleBasisForwardVector *= -1f;


            this.engine = engine;
            this.part = engine.part;

            Bounds partBounds = part.GetPartColliderBoundsInBasis(Matrix4x4.identity);
            exitArea = partBounds.extents.x + partBounds.extents.z;
            exitArea *= 0.5;
            exitArea *= exitArea;
            exitArea *= Math.PI;

            exitArea *= -1;     //make this negative to note that it is a removal of area 
        }
        internal void OnPreCull()
        {
            if (HighLogic.LoadedScene != GameScenes.MAINMENU)
            {
                Matrix4x4 bodies = new Matrix4x4();
                int i = 0;
                foreach (CelestialBody cb in shadowList)
                {
                    bodies.SetRow(i, cb.transform.position);
                    bodies[i, 3] = (float)(cb.Radius);
                    i++;
                    if (i == 4)
                        break;
                }
                if (shadowMat != null)
                {
                    shadowMat.SetVector(ShaderProperties._SunPos_PROPERTY, Sun.Instance.sun.transform.position);
                    shadowMat.SetMatrix(ShaderProperties._ShadowBodies_PROPERTY, bodies);
                }

                foreach (Transform child in body.transform)
                {
                    Renderer cr = child.GetComponent<Renderer>();
                    if (cr != null)
                    {
                        cr.sharedMaterial.SetFloat(ShaderProperties._SunRadius_PROPERTY, (float)(Sun.Instance.sun.Radius));
                        cr.sharedMaterial.SetVector(ShaderProperties._SunPos_PROPERTY, Sun.Instance.sun.transform.position);
                        cr.sharedMaterial.SetMatrix(ShaderProperties._ShadowBodies_PROPERTY, bodies);
                    }
                }
            }
        }
Пример #22
0
		/// <summary>
		/// Update the min/max values based on the transformed bounding box.
		/// </summary>
		/// <param name="bounds"></param>
		/// <param name="transform"></param>
		/// <param name="maxPos"></param>
		/// <param name="minPos"></param>
		private void UpdateMinMax(Bounds bounds, Matrix4x4 transform, ref Vector3 maxPos, ref Vector3 minPos)
		{
			var tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.min.x, bounds.min.y, bounds.min.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);

			tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.min.x, bounds.min.y, bounds.max.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);

			tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.min.x, bounds.max.y, bounds.min.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);

			tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.min.x, bounds.max.y, bounds.max.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);

			tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.max.x, bounds.min.y, bounds.min.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);

			tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.max.x, bounds.min.y, bounds.max.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);

			tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.max.x, bounds.max.y, bounds.min.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);

			tmpVec = transform.MultiplyPoint3x4(new Vector3(bounds.max.x, bounds.max.y, bounds.max.z));
			maxPos = Vector3.Max(maxPos, tmpVec);
			minPos = Vector3.Min(minPos, tmpVec);
		}
        public GeometryMesh(MeshData meshData, Transform meshTransform, Matrix4x4 worldToVesselMatrix, GeometryPartModule module)
        {
            Vector3[] untransformedVerts = meshData.vertices;
            int[] triangles = meshData.triangles;
            Bounds meshBounds = meshData.bounds;

            vertices = new Vector3[untransformedVerts.Length];
            this.thisToVesselMatrix = worldToVesselMatrix * meshTransform.localToWorldMatrix;

            for (int i = 0; i < vertices.Length; i++)
            {
                //vertices[i] = thisToVesselMatrix.MultiplyPoint3x4(untransformedVerts[i]);
                Vector3 v = untransformedVerts[i];
                Vector3 vert = Vector3.zero;
                vert.x = thisToVesselMatrix.m00 * v.x + thisToVesselMatrix.m01 * v.y + thisToVesselMatrix.m02 * v.z + thisToVesselMatrix.m03;
                vert.y = thisToVesselMatrix.m10 * v.x + thisToVesselMatrix.m11 * v.y + thisToVesselMatrix.m12 * v.z + thisToVesselMatrix.m13;
                vert.z = thisToVesselMatrix.m20 * v.x + thisToVesselMatrix.m21 * v.y + thisToVesselMatrix.m22 * v.z + thisToVesselMatrix.m23;

                vertices[i] = vert;
            }

            this.triangles = triangles;
            this.meshTransform = meshTransform;

            bounds = TransformBounds(meshBounds, thisToVesselMatrix);

            this.module = module;
            this.part = module.part;

            if (!module.part.isMirrored)
                invertXYZ = 1;
            else
                invertXYZ = -1;
        }
Пример #24
0
 void LateUpdate() {
   cam.aspect = aspectRatio;
   mat = cam.projectionMatrix * cam.worldToCameraMatrix;
   //mat = GL.GetGPUProjectionMatrix(cam.projectionMatrix, false) * cam.worldToCameraMatrix;
   Shader.SetGlobalMatrix(id_matrix, mat);
   Vector3 dir = transform.forward;
   Shader.SetGlobalVector(id_direction, new Vector4(dir.x, dir.y, dir.z, 0f));
 }
Пример #25
0
 /// <summary>
 /// Extract scale from transform matrix.
 /// </summary>
 /// <param name="matrix">Transform matrix. This parameter is passed by reference
 /// to improve performance; no changes will be made to it.</param>
 /// <returns>
 /// Scale vector.
 /// </returns>
 public static Vector3 ExtractScaleFromMatrix(ref Matrix4x4 matrix)
 {
     Vector3 scale;
     scale.x = new Vector4 (matrix.m00, matrix.m10, matrix.m20, matrix.m30).magnitude;
     scale.y = new Vector4 (matrix.m01, matrix.m11, matrix.m21, matrix.m31).magnitude;
     scale.z = new Vector4 (matrix.m02, matrix.m12, matrix.m22, matrix.m32).magnitude;
     return scale;
 }
Пример #26
0
 public static void SetMatrixToIdentity(Matrix4x4 mat)
 {
     for(int x = 0; x < 4; x++){
         for(int y = 0; y < 4; y++){
             mat[x, y] = x == y ? 1 : 0;
         }
     }
 }
Пример #27
0
		public void Reset(float r, Matrix4x4 m, float bOffset, int segs)
		{
			this.radius = r;
			this.matrix = m;
			this.baseOffset = bOffset;
			this.segments = segs;
			this.vertOffset = 0;
		}
Пример #28
0
 public static Matrix4x4 Lerp(Matrix4x4 a_From, Matrix4x4 a_To, float a_Value)
 {
     Matrix4x4 l_Result = new Matrix4x4 ();
     for (int i = 0; i < 16; i = i + 1) {
         l_Result [i] = Mathf.Lerp (a_From [i], a_To [i], a_Value);
     }
     return (l_Result);
 }
Пример #29
0
		// Update is called once per frame
		public void UpdateNode() 
		{
			directionTosun=directionTosun.normalized;

			Quaternion q = Quaternion.FromToRotation(GetDirection(), Z_AXIS);
			m_worldToLocalRotation = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
			
		}
Пример #30
0
	public TextMeshRenderer(LWF lwf, TextContext context) : base(lwf, context)
	{
		m_mesh = new Mesh();
		m_matrix = new Matrix4x4();
		m_renderMatrix = new Matrix4x4();
		m_colorMult = new UnityEngine.Color();
		m_colorAdd = new UnityEngine.Color();
		m_color = new Color32();
	}
Пример #31
0
    static bool Graphics_DrawMesh__Mesh__Matrix4x4__Material__Int32__Camera(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 5)
        {
            UnityEngine.Mesh      arg0 = (UnityEngine.Mesh)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.Matrix4x4 arg1 = (UnityEngine.Matrix4x4)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.Material  arg2 = (UnityEngine.Material)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            System.Int32          arg3 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
            UnityEngine.Camera    arg4 = (UnityEngine.Camera)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.Graphics.DrawMesh(arg0, arg1, arg2, arg3, arg4);
        }

        return(true);
    }
Пример #32
0
    private void UpdateCameraParentPose()
    {
        Interlocked.Exchange(ref updateCameraToWorldMatrix, _cameraToWorldMatrix);

        UnityEngine.Matrix4x4 cameraToWorldMatrix = ConvertFloatArrayToMatrix4x4(updateCameraToWorldMatrix);

        Transform locatableCameraTransform = controller.LocatableCameraRoot.transform;

        // Note: we can't just directly convert the matrix into the rotation/position that Unity expects.
        // We need to convert it. See https://forum.unity.com/threads/locatable-camera-in-unity.398803/
        Vector3    position = cameraToWorldMatrix.MultiplyPoint(Vector3.zero);
        Quaternion rotation = Quaternion.LookRotation(-cameraToWorldMatrix.GetColumn(2), cameraToWorldMatrix.GetColumn(1));

        locatableCameraTransform.position = position;
        locatableCameraTransform.rotation = rotation;
    }
Пример #33
0
        public static float[] ConvertMatrix(UnityEngine.Matrix4x4 matrix)
        {
            UnityEngine.Matrix4x4 flipZ         = UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(1, 1, -1));
            UnityEngine.Matrix4x4 flippedMatrix = flipZ * matrix * flipZ;

            float[] transformArray = new float[16];
            for (int i = 0, count = 0; i < 4; ++i)
            {
                for (int j = 0; j < 4; ++j, ++count)
                {
                    transformArray[count] = flippedMatrix[j, i];
                }
            }

            return(transformArray);
        }
Пример #34
0
 static void CombineInstance_transform(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.CombineInstance _this = (UnityEngine.CombineInstance)vc.csObj;
         var result = _this.transform;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Matrix4x4       arg0  = (UnityEngine.Matrix4x4)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.CombineInstance _this = (UnityEngine.CombineInstance)vc.csObj;
         _this.transform = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
Пример #35
0
 static void Matrix4x4_m12(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.Matrix4x4 _this = (UnityEngine.Matrix4x4)vc.csObj;
         var result = _this.m12;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single         arg0  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.Matrix4x4 _this = (UnityEngine.Matrix4x4)vc.csObj;
         _this.m12 = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
Пример #36
0
 static public int GetGPUProjectionMatrix_s(IntPtr l)
 {
     try{
         UnityEngine.Matrix4x4 a1;
         checkType(l, 1, out a1);
         System.Boolean a2;
         checkType(l, 2, out a2);
         UnityEngine.Matrix4x4 ret = UnityEngine.GL.GetGPUProjectionMatrix(a1, a2);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
    private void ApplyTransformation(out UnityEngine.Matrix4x4 Transformation)
    {
        //Calculating Centroids from both coordinate system

        Accord.Math.Vector3 centroidA = CalculateCentroid(UnitytoAccord(ReadFrameLowerLeft), UnitytoAccord(ReadFrameLowerRight), UnitytoAccord(ReadFrameUpperLeft), UnitytoAccord(ReadFrameUpperRight));
        Accord.Math.Vector3 centroidB = CalculateCentroid(UnitytoAccord(FrameLowerLeft), UnitytoAccord(FrameLowerRight), UnitytoAccord(FrameUpperLeft), UnitytoAccord(FrameUpperRight));

        Matrix3x3 H = CovarianceMatrixStep(UnitytoAccord(ReadFrameLowerLeft) - centroidA, UnitytoAccord(FrameLowerLeft) - centroidB)
                      + CovarianceMatrixStep(UnitytoAccord(ReadFrameLowerRight) - centroidA, UnitytoAccord(FrameLowerRight) - centroidB)
                      + CovarianceMatrixStep(UnitytoAccord(ReadFrameUpperLeft) - centroidA, UnitytoAccord(FrameUpperLeft) - centroidB)
                      + CovarianceMatrixStep(UnitytoAccord(ReadFrameUpperRight) - centroidA, UnitytoAccord(FrameUpperRight) - centroidB);
        Matrix3x3 U;

        Accord.Math.Vector3 E;
        Matrix3x3           V;
        Matrix3x3           R;

        H.SVD(out U, out E, out V);

        R = V * U.Transpose();
        Debug.Log("Row  " + R.GetRow(0));
        Debug.Log("Row  " + R.GetRow(1));
        Debug.Log("Row  " + R.GetRow(2));


        if (R.Determinant < 0)
        {
            V.V02 = (-V.V02);
            V.V12 = (-V.V12);
            V.V22 = (-V.V22);
            R     = V * U.Transpose();
            Debug.LogWarning("Reflection case");
        }
        Accord.Math.Vector3 Translation;
        Translation = (NegativeMatrix(R) * centroidA + centroidB);
        Debug.Log("Translation is" + Translation);
        Transformation = UnityEngine.Matrix4x4.identity;
        Transformation = AccordToUnityMatrix(Transformation, R, Translation);

        Debug.Log("Trans" + Transformation.GetRow(0));
        Debug.Log("Trans" + Transformation.GetRow(1));
        Debug.Log("Trans" + Transformation.GetRow(2));
        Debug.Log("Trans" + Transformation.GetRow(3));

        Transformation.SetTRS(AccordtoUnity(Translation), Quaternion.LookRotation(Transformation.GetColumn(1),
                                                                                  Transformation.GetColumn(2)), UnityEngine.Vector3.one);
    }
Пример #38
0
    private void calibrateHomographyMaths(PointF[] points_kinect, int w, int h)
    {
        Debug.Log("Calbirating homography...");
        var points_sorted = new PointF[4];

        points_sorted[0] = get_closest(points_kinect, new PointF(0, 0));
        points_sorted[1] = get_closest(points_kinect, new PointF(0, h));
        points_sorted[2] = get_closest(points_kinect, new PointF(w, h));
        points_sorted[3] = get_closest(points_kinect, new PointF(w, 0));
        Debug.Log("WWWWW: " + w + " HHHHHH: " + h);
        var points_camera = new PointF[4];

        points_camera[0] = get_camera_point(new Vector3(0.5f, 0, 0.5f) * calibration_artefact);
        points_camera[1] = get_camera_point(new Vector3(0.5f, 0, -0.5f) * calibration_artefact);
        points_camera[2] = get_camera_point(new Vector3(-0.5f, 0, -0.5f) * calibration_artefact);
        points_camera[3] = get_camera_point(new Vector3(-0.5f, 0, 0.5f) * calibration_artefact);

        for (int i = 0; i < 4; i++)
        {
            points_sorted[i] = new PointF(points_sorted[i].X / w, points_sorted[i].Y / h);
        }
        Debug.Log(points_sorted[0] + " " + points_camera[0]);
        Debug.Log(points_sorted[1] + " " + points_camera[1]);
        Debug.Log(points_sorted[2] + " " + points_camera[2]);
        Debug.Log(points_sorted[3] + " " + points_camera[3]);

        Emgu.CV.Matrix <double> homography = new Emgu.CV.Matrix <double>(3, 3);
        CvInvoke.FindHomography(points_camera, points_sorted, homography, Emgu.CV.CvEnum.HomographyMethod.LMEDS);

        Debug.Log(homography[0, 0] + " " + homography[0, 1] + " " + homography[0, 2]);
        Debug.Log(homography[1, 0] + " " + homography[1, 1] + " " + homography[1, 2]);
        Debug.Log(homography[2, 0] + " " + homography[2, 1] + " " + homography[2, 2]);

        UnityEngine.Matrix4x4 m = Matrix4x4.identity;
        m.m00 = (float)homography[0, 0];
        m.m01 = (float)homography[0, 1];
        m.m02 = (float)homography[0, 2];
        m.m10 = (float)homography[1, 0];
        m.m11 = (float)homography[1, 1];
        m.m12 = (float)homography[1, 2];
        m.m20 = (float)homography[2, 0];
        m.m21 = (float)homography[2, 1];
        m.m22 = (float)homography[2, 2];

        this.GetComponent <MeshRenderer>().material.SetMatrix("_Homography", m);
//        this.GetComponent<MeshRenderer>().material.SetVector("_KinectDims", new Vector2(w, h));
    }
Пример #39
0
    private void InitializeMatrices()
    {
        if (_matricesInitialized)
        {
            return;
        }

        _toWorld = UnityEngine.Matrix4x4.TRS(LocalPosition, LocalRotation, LocalScale);
        var parent = Parent;

        if (parent != null)
        {
            _toWorld = parent.ToWorld * _toWorld;
        }
        _toLocal             = _toWorld.inverse;
        _matricesInitialized = true;
    }
Пример #40
0
 void DoEverything()
 {
     OnInitializePhysics();
     for (int i = 0; i < 100; i++)
     {
         OnUpdate();
         for (int j = 0; j < numLinks; j++)
         {
             MultiBodyLinkCollider linkCollider = links[j];
             UnityEngine.Matrix4x4 m            = linkCollider.WorldTransform.ToUnity();
             UnityEngine.Vector3   p            = BSExtensionMethods2.ExtractTranslationFromMatrix(ref m);
             linkPositions[j] = p;
             UnityEngine.Debug.Log("pos " + p.ToString("f3") + " " + j);
         }
     }
     ExitPhysics();
 }
Пример #41
0
        public static Rect Transform(this Rect rect, UnityEngine.Matrix4x4 mat)
        {
            Rect result = rect;

            Vector3[] points = new Vector3[] { new Vector3(rect.xMin, rect.yMin, 0f), new Vector3(rect.xMax, rect.yMax, 0f) };
            for (int i = 0; i < 2; i++)
            {
                points[i] = mat.MultiplyPoint3x4(points[i]);
            }

            result.xMin = points[0].x;
            result.xMax = points[1].x;
            result.yMin = points[0].y;
            result.yMax = points[1].y;

            return(result);
        }
Пример #42
0
        /// <summary>
        /// Renders out the line with an arrow
        /// </summary>
        /// <param name="rStart">Start position</param>
        /// <param name="rEnd">End position</param>
        private void DrawArrow(Vector3 rStart, Vector3 rEnd)
        {
#if UNITY_EDITOR
            bool  lIsSelected = (StartNode.Canvas.SelectedLink == this);
            Color lColor      = (lIsSelected ? NodeEditorStyle.LinkSelectedColor : (IsEnabled ? NodeEditorStyle.LinkColor : NodeEditorStyle.LinkDisabledColor));

            Vector3 lStartTan = rStart + Vector3.right * 30f;
            Vector3 lEndTan   = rEnd + Vector3.left * 30f;

            if (IsEnabled)
            {
                for (int i = 0; i < 2; i++)
                {
                    UnityEditor.Handles.DrawBezier(rStart, rEnd, lStartTan, lEndTan, NodeEditorStyle.LinkShadowColor, null, (i + 1) * 5);
                }
            }

            UnityEditor.Handles.DrawBezier(rStart, rEnd, lStartTan, lEndTan, lColor, null, 2);

            Vector3[] lPoints = UnityEditor.Handles.MakeBezierPoints(rStart, rEnd, lStartTan, lEndTan, 20);

            int     lIndex        = NodeEditorStyle.LinkHeaderIndex;
            Rect    lHeadPosition = new Rect(lPoints[lIndex].x - 16, lPoints[lIndex].y - 16, 32, 32);
            Vector3 lHeadPivot    = new Vector3(lHeadPosition.xMin + 16, lHeadPosition.yMin + 16);

            Vector3 lToEnd = (lPoints[lIndex] - lPoints[lIndex + 2]).normalized;

            Vector2 lDirection = new Vector2(lToEnd.x, lToEnd.y);
            float   lAngle     = Vector2.Angle(Vector2.up, lDirection);
            Vector3 lCross     = Vector3.Cross(Vector2.up, lDirection);
            if (lCross.z > 0)
            {
                lAngle = 360f - lAngle;
            }

            UnityEngine.Matrix4x4 matrixBackup = GUI.matrix;
            GUIUtility.RotateAroundPivot(-lAngle, lHeadPivot);
            GUI.DrawTexture(lHeadPosition, (lIsSelected ? NodeEditorStyle.LinkHeadSelected : (IsEnabled ? NodeEditorStyle.LinkHead : NodeEditorStyle.LinkHeadDisabled)));
            GUI.matrix = matrixBackup;

            if (Actions != null && Actions.Count > 0)
            {
                GUI.DrawTexture(lHeadPosition, (lIsSelected ? NodeEditorStyle.LinkActionSelected : (IsEnabled ? NodeEditorStyle.LinkAction : NodeEditorStyle.LinkActionDisabled)));
            }
#endif
        }
//These are the function I build which need to be used

    public void cube1()
    {
        GL.PushMatrix();
        UnityEngine.Matrix4x4 matrixMove = UnityEngine.Matrix4x4.Translate(new Vector3(-15 + moveStep, 0, 0));
        GL.modelview = GL.modelview * matrixMove;
        GL.Begin(GL.LINES);
        GL.Color(Color.cyan);

        GL.Vertex3(0, 0, 0);
        GL.Vertex3(5, 0, 0);

        GL.Vertex3(5, 0, 0);
        GL.Vertex3(5, 5, 0);

        GL.Vertex3(5, 5, 0);
        GL.Vertex3(0, 5, 0);

        GL.Vertex3(0, 5, 0);
        GL.Vertex3(0, 0, 0);

        GL.Vertex3(0, 5, 0);
        GL.Vertex3(0, 5, 5);

        GL.Vertex3(0, 5, 5);
        GL.Vertex3(0, 0, 5);

        GL.Vertex3(0, 0, 5);
        GL.Vertex3(0, 0, 0);

        GL.Vertex3(5, 5, 0);
        GL.Vertex3(5, 5, 5);

        GL.Vertex3(5, 5, 5);
        GL.Vertex3(5, 0, 5);

        GL.Vertex3(5, 0, 5);
        GL.Vertex3(5, 0, 0);

        GL.Vertex3(0, 5, 5);
        GL.Vertex3(5, 5, 5);

        GL.Vertex3(0, 0, 5);
        GL.Vertex3(5, 0, 5);
        GL.End();
        GL.PopMatrix();
    }
Пример #44
0
 static void Matrix4x4_Item_Int32(JSVCall vc)
 {
     System.Int32 arg0 = (System.Int32)JSApi.getInt32((int)JSApi.GetType.Arg);
     if (vc.bGet)
     {
         UnityEngine.Matrix4x4 _this = (UnityEngine.Matrix4x4)vc.csObj;
         var result = _this[arg0];
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single         arg1  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.Matrix4x4 _this = (UnityEngine.Matrix4x4)vc.csObj;
         _this[arg0] = arg1;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
Пример #45
0
 static public int SetRow(IntPtr l)
 {
     try{
         UnityEngine.Matrix4x4 self = (UnityEngine.Matrix4x4)checkSelf(l);
         System.Int32          a1;
         checkType(l, 2, out a1);
         UnityEngine.Vector4 a2;
         checkType(l, 3, out a2);
         self.SetRow(a1, a2);
         setBack(l, self);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Пример #46
0
    Matrix blend_m4_m4m4(Matrix src, Matrix dst, float srcweight)
    {
        //blend_m4_m4m4(tmat, mat_unit, mat_final, fallOff);
        src.GetTRS(out var dLoc, out var dRot, out var dScale);
        dst.GetTRS(out var sLoc, out var sRot, out var sScale);
        // normされてるのでは
        //mat3_normalized_to_quat

        var fLoc  = lerp(dLoc, sLoc, srcweight);
        var fQuat = slerp(dRot, sRot, srcweight);

        RarePrint($"fQuat : {fQuat}");
        var fSca = lerp(dScale, sScale, srcweight);
        var tmp  = Matrix.TRS(fLoc, fQuat, fSca);

        return(tmp);
    }
Пример #47
0
// fields

// properties

// methods

    static bool GeometryUtility_CalculateFrustumPlanes__Matrix4x4(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.Matrix4x4 arg0 = (UnityEngine.Matrix4x4)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            var arrRet = UnityEngine.GeometryUtility.CalculateFrustumPlanes(arg0);
            for (int i = 0; arrRet != null && i < arrRet.Length; i++)
            {
                JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, arrRet[i]);
                JSApi.moveSaveID2Arr(i);
            }
            JSApi.setArrayS((int)JSApi.SetType.Rval, (arrRet != null ? arrRet.Length : 0), true);
        }

        return(true);
    }
Пример #48
0
    static int set_orientationMatrix(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Tilemaps.Tilemap obj  = (UnityEngine.Tilemaps.Tilemap)o;
            UnityEngine.Matrix4x4        arg0 = StackTraits <UnityEngine.Matrix4x4> .Check(L, 2);

            obj.orientationMatrix = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index orientationMatrix on a nil value"));
        }
    }
Пример #49
0
 static public int TRS_s(IntPtr l)
 {
     try{
         UnityEngine.Vector3 a1;
         checkType(l, 1, out a1);
         UnityEngine.Quaternion a2;
         checkType(l, 2, out a2);
         UnityEngine.Vector3 a3;
         checkType(l, 3, out a3);
         UnityEngine.Matrix4x4 ret = UnityEngine.Matrix4x4.TRS(a1, a2, a3);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Пример #50
0
 static int Perspective(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         float arg0 = (float)LuaDLL.luaL_checknumber(L, 1);
         float arg1 = (float)LuaDLL.luaL_checknumber(L, 2);
         float arg2 = (float)LuaDLL.luaL_checknumber(L, 3);
         float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
         UnityEngine.Matrix4x4 o = UnityEngine.Matrix4x4.Perspective(arg0, arg1, arg2, arg3);
         ToLua.PushValue(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #51
0
 static int SetTRS(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         UnityEngine.Matrix4x4  obj  = (UnityEngine.Matrix4x4)ToLua.CheckObject(L, 1, typeof(UnityEngine.Matrix4x4));
         UnityEngine.Vector3    arg0 = ToLua.ToVector3(L, 2);
         UnityEngine.Quaternion arg1 = ToLua.ToQuaternion(L, 3);
         UnityEngine.Vector3    arg2 = ToLua.ToVector3(L, 4);
         obj.SetTRS(arg0, arg1, arg2);
         ToLua.SetBack(L, 1, obj);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #52
0
    static int set_m33(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Matrix4x4 obj = (UnityEngine.Matrix4x4)o;
            float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
            obj.m33 = arg0;
            ToLua.SetBack(L, 1, obj);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index m33 on a nil value" : e.Message));
        }
    }
Пример #53
0
        public void Cylinder(Vector3 position, Vector3 up, float height, float radius, Color color)
        {
            var tangent = Vector3.Cross(up, Vector3.one).normalized;

            matrix = Matrix4x4.TRS(position, Quaternion.LookRotation(tangent, up), new Vector3(radius, height, radius));
            CircleXZ(Vector3.zero, 1, color);

            if (height > 0)
            {
                CircleXZ(Vector3.up, 1, color);
                Line(new Vector3(1, 0, 0), new Vector3(1, 1, 0), color);
                Line(new Vector3(-1, 0, 0), new Vector3(-1, 1, 0), color);
                Line(new Vector3(0, 0, 1), new Vector3(0, 1, 1), color);
                Line(new Vector3(0, 0, -1), new Vector3(0, 1, -1), color);
            }

            matrix = Matrix4x4.identity;
        }
Пример #54
0
    static int set_worldToLocal(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UIPanel obj = (UIPanel)o;
            UnityEngine.Matrix4x4 arg0 = StackTraits <UnityEngine.Matrix4x4> .Check(L, 2);

            obj.worldToLocal = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index worldToLocal on a nil value"));
        }
    }
    static public void FastSetter(this UnityEngine.Camera o, string propertyName, UnityEngine.Matrix4x4 value)
    {
        switch (propertyName)
        {
        case "worldToCameraMatrix":
            o.worldToCameraMatrix = value; return;

        case "projectionMatrix":
            o.projectionMatrix = value; return;

        case "nonJitteredProjectionMatrix":
            o.nonJitteredProjectionMatrix = value; return;

        case "cullingMatrix":
            o.cullingMatrix = value; return;
        }
        LBoot.LogUtil.Error("UnityEngine.Camera no Setter Found : " + propertyName);
    }
Пример #56
0
    static int TransformPlane(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            UnityEngine.Matrix4x4 obj  = (UnityEngine.Matrix4x4)ToLua.CheckObject(L, 1, typeof(UnityEngine.Matrix4x4));
            UnityEngine.Plane     arg0 = StackTraits <UnityEngine.Plane> .Check(L, 2);

            UnityEngine.Plane o = obj.TransformPlane(arg0);
            ToLua.PushValue(L, o);
            ToLua.SetBack(L, 1, obj);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #57
0
    static int op_Equality(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            UnityEngine.Matrix4x4 arg0 = StackTraits <UnityEngine.Matrix4x4> .To(L, 1);

            UnityEngine.Matrix4x4 arg1 = StackTraits <UnityEngine.Matrix4x4> .To(L, 2);

            bool o = arg0 == arg1;
            LuaDLL.lua_pushboolean(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        private static void DrawCameraPath(Vector3 atPos, Quaternion orient, CinemachineFreeLook vcam)
        {
            Matrix4x4 prevMatrix = Gizmos.matrix;

            Gizmos.matrix = Matrix4x4.TRS(atPos, orient, Vector3.one);

            const int kNumSteps = 20;
            Vector3   currPos   = vcam.GetLocalPositionForCameraFromInput(0f);

            for (int i = 1; i < kNumSteps + 1; ++i)
            {
                float   t       = (float)i / (float)kNumSteps;
                Vector3 nextPos = vcam.GetLocalPositionForCameraFromInput(t);
                Gizmos.DrawLine(currPos, nextPos);
                currPos = nextPos;
            }
            Gizmos.matrix = prevMatrix;
        }
Пример #59
0
    static int SetEditorPreviewTransformMatrix(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 3);
            UnityEngine.Tilemaps.Tilemap obj  = (UnityEngine.Tilemaps.Tilemap)ToLua.CheckObject(L, 1, typeof(UnityEngine.Tilemaps.Tilemap));
            UnityEngine.Vector3Int       arg0 = StackTraits <UnityEngine.Vector3Int> .Check(L, 2);

            UnityEngine.Matrix4x4 arg1 = StackTraits <UnityEngine.Matrix4x4> .Check(L, 3);

            obj.SetEditorPreviewTransformMatrix(arg0, arg1);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #60
0
    static int set_shadowMatrixOverride(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Light     obj  = (UnityEngine.Light)o;
            UnityEngine.Matrix4x4 arg0 = StackTraits <UnityEngine.Matrix4x4> .Check(L, 2);

            obj.shadowMatrixOverride = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index shadowMatrixOverride on a nil value"));
        }
    }