TransformPoint() public method

public TransformPoint ( Vector3 point ) : Vector3
point Vector3
return Vector3
Ejemplo n.º 1
0
	    /// <summary>
	    /// construct a new bsp tree from unity mesh
	    /// </summary>
	    /// <param name="mesh">unity mesh</param>
	    /// <param name="meshTransform">transformation</param>
	    /// <param name="id">id of the mesh</param>
	    public void Construct(Mesh mesh, Transform meshTransform, int id)
        {
            // cache mesh data
            var trianglesNum = mesh.triangles.Length;
            var meshTriangles = mesh.triangles;
            var meshVertices = mesh.vertices;
            var meshNormals = mesh.normals;
            var meshUV = mesh.uv;

            Polygons = new List<CSGPolygon>(trianglesNum/3);

            for (int i = 0; i < trianglesNum; i+=3)
            {
                var id0 = meshTriangles[i];
                var id1 = meshTriangles[i + 1];
                var id2 = meshTriangles[i + 2];

                Polygons.Add(new CSGPolygon(id, new CSGVertex(meshTransform.TransformPoint(meshVertices[id0]), meshTransform.TransformDirection(meshNormals[id0]), meshUV[id0]),
                                             new CSGVertex(meshTransform.TransformPoint(meshVertices[id1]), meshTransform.TransformDirection(meshNormals[id1]), meshUV[id1]),
                                             new CSGVertex(meshTransform.TransformPoint(meshVertices[id2]), meshTransform.TransformDirection(meshNormals[id2]), meshUV[id2])));
            }

            root = new CSGNode();
            root.Build(Polygons);
        }
Ejemplo n.º 2
0
	// Misc drawing
	public static void DrawRect( Rect r, Transform t ) {
		Vector3 p0 = t.TransformPoint (new Vector3(r.xMin, r.yMin, 0));
		Vector3 p1 = t.TransformPoint (new Vector3(r.xMax, r.yMin, 0));
		Vector3 p2 = t.TransformPoint (new Vector3(r.xMax, r.yMax, 0));
		Vector3 p3 = t.TransformPoint (new Vector3(r.xMin, r.yMax, 0));
		Vector3[] worldPts = new Vector3[5] { p0, p1, p2, p3, p0 };
		Handles.DrawPolyLine (worldPts);
	}
Ejemplo n.º 3
0
 public static void DrawRectWithOutline(Transform transform, Rect rect, Color color, Color colorOutline)
 {
     Vector3[] rectVerts = {
     transform.TransformPoint(new Vector3(rect.x, rect.y, 0)),
     transform.TransformPoint(new Vector3(rect.x + rect.width, rect.y, 0)),
     transform.TransformPoint(new Vector3(rect.x + rect.width, rect.y + rect.height, 0)),
     transform.TransformPoint(new Vector3(rect.x, rect.y + rect.height, 0)) };
     Handles.DrawSolidRectangleWithOutline(rectVerts, color, colorOutline);
 }
Ejemplo n.º 4
0
        private Polygon Select(ServerNPC caster, EffectConfigData efCfg)
        {
                        #if DEBUG
            Utils.Assert(caster == null, "Can't find target unless caster isn't null.");
            Utils.Assert(efCfg == null, "Can't find target unless EffectConfigData isn't null.");
                        #endif

            UTran trans = caster.transform;
            float Y     = trans.localPosition.y;

            float halfWidth = efCfg.eParam2 * 0.5F;
            float Height    = efCfg.eParam1;

            UVec3[] localVecs = new UVec3[4];
            localVecs[0] = new UVec3(-halfWidth, Y, 0f);
            localVecs[1] = new UVec3(-halfWidth, Y, Height);
            localVecs[2] = new UVec3(halfWidth, Y, Height);
            localVecs[3] = new UVec3(halfWidth, Y, 0f);


            UVec3[] WorldVecs = new UVec3[4];
            WorldVecs[0] = trans.TransformPoint(localVecs[0]);
            WorldVecs[1] = trans.TransformPoint(localVecs[1]);
            WorldVecs[2] = trans.TransformPoint(localVecs[2]);
            WorldVecs[3] = trans.TransformPoint(localVecs[3]);

            PointF[] vecs = new PointF[4];

            vecs[0] = new PointF()
            {
                X = WorldVecs[0].x,
                Y = WorldVecs[0].z,
            };

            vecs[1] = new PointF()
            {
                X = WorldVecs[1].x,
                Y = WorldVecs[1].z,
            };

            vecs[2] = new PointF()
            {
                X = WorldVecs[2].x,
                Y = WorldVecs[2].z,
            };

            vecs[3] = new PointF()
            {
                X = WorldVecs[3].x,
                Y = WorldVecs[3].z,
            };

            Polygon rectangle = new Polygon(vecs);

            return(rectangle);
        }
        public static void DrawTriangle(Vector3 a, Vector3 b, Vector3 c, Color color, Transform t)
        {
            a = t.TransformPoint(a);
            b = t.TransformPoint(b);
            c = t.TransformPoint(c);

            Debug.DrawLine(a, b, color);
            Debug.DrawLine(b, c, color);
            Debug.DrawLine(c, a, color);
        }
Ejemplo n.º 6
0
 public static void DrawDotOutline(Transform transform, Vector3 position, float size, Color color, Color colorOutline)
 {
     Rect rDot = new Rect(-size / (2 * transform.localScale.x), -size / (2 * transform.localScale.y), size / transform.localScale.x, size / transform.localScale.y);
     Vector3[] rectVerts = {
     transform.TransformPoint( position + new Vector3(rDot.x, rDot.y, 0)),
     transform.TransformPoint( position + new Vector3(rDot.x + rDot.width, rDot.y, 0)),
     transform.TransformPoint( position + new Vector3(rDot.x + rDot.width, rDot.y + rDot.height, 0)),
     transform.TransformPoint( position + new Vector3(rDot.x, rDot.y + rDot.height, 0)) };
     Handles.DrawSolidRectangleWithOutline(rectVerts, color, colorOutline);
 }
Ejemplo n.º 7
0
    //4 "coins" du frustum a une distance donnee, par rapport au repere global
    void pointsSurLeFrustum(Transform origine, float fieldOfView, float aspect, float distance,
	                     out Vector3 hautGauche, out Vector3 hautDroite, out Vector3 basGauche, out Vector3 basDroite)
    {
        float demiHauteur = distance * Mathf.Tan(fieldOfView * 0.5f * Mathf.Deg2Rad );
        float demiLargeur = demiHauteur * aspect;
        hautDroite = origine.TransformPoint(demiLargeur, demiHauteur, distance);
        hautGauche = origine.TransformPoint(-demiLargeur, demiHauteur, distance);
        basDroite = origine.transform.TransformPoint(demiLargeur,-demiHauteur, distance);
        basGauche = origine.transform.TransformPoint(-demiLargeur,-demiHauteur, distance);
    }
Ejemplo n.º 8
0
 public static void DrawDottedLine(Transform transform, Rect rect, float screenSpaceSize)
 {
     Vector3[] rectVerts = {
     transform.TransformPoint(new Vector3(rect.x, rect.y, 0)),
     transform.TransformPoint(new Vector3(rect.x + rect.width, rect.y, 0)),
     transform.TransformPoint(new Vector3(rect.x + rect.width, rect.y + rect.height, 0)),
     transform.TransformPoint(new Vector3(rect.x, rect.y + rect.height, 0)) };
     Handles.DrawDottedLine(rectVerts[0], rectVerts[1], screenSpaceSize);
     Handles.DrawDottedLine(rectVerts[1], rectVerts[2], screenSpaceSize);
     Handles.DrawDottedLine(rectVerts[2], rectVerts[3], screenSpaceSize);
     Handles.DrawDottedLine(rectVerts[3], rectVerts[0], screenSpaceSize);
 }
Ejemplo n.º 9
0
 // hekp visualize the line of sight within the editor
 public static void DrawLineOfSight(Transform transform, float fieldOfViewAngle, float viewMagnitude)
 {
     #if UNITY_EDITOR
     float radius = viewMagnitude * Mathf.Sin(fieldOfViewAngle * Mathf.Deg2Rad);
     var oldColor = UnityEditor.Handles.color;
     UnityEditor.Handles.color = Color.yellow;
     // draw a disk at the end of the sight distance.
     UnityEditor.Handles.DrawWireDisc(transform.position + transform.forward * viewMagnitude, transform.forward, radius);
     // draw to lines to represent the left and right side of the line of sight
     UnityEditor.Handles.DrawLine(transform.position, transform.TransformPoint(new Vector3(radius, 0, viewMagnitude)));
     UnityEditor.Handles.DrawLine(transform.position, transform.TransformPoint(new Vector3(-radius, 0, viewMagnitude)));
     UnityEditor.Handles.color = oldColor;
     #endif
 }
Ejemplo n.º 10
0
    public override void UpdateFinger(Finger finger, Transform deviceTransform,
                                     Vector3 palm_normal, Vector3 palm_direction)
    {
        Vector3 last_bone_normal = palm_normal;
        Vector3 last_bone_direction = palm_direction;

        for (int i = 0; i < NUM_BONES; ++i) {
          // Set velocity.
          Vector3 next_bone_position = deviceTransform.TransformPoint(GetBonePosition(finger, i));
          bones[i].rigidbody.velocity = (next_bone_position - bones[i].transform.position) *
                                    ((1 - easing) / Time.fixedDeltaTime);

          // Set angular velocity.
          Vector3 bone_direction = deviceTransform.rotation * GetBoneDirection(finger, i);
          Vector3 bone_normal = Quaternion.FromToRotation(last_bone_direction, bone_direction) * last_bone_normal;

          Quaternion delta_rotation = Quaternion.LookRotation(bone_direction, -bone_normal) *
                                  Quaternion.Inverse(bones[i].transform.rotation);
          float angle = 0.0f;
          Vector3 axis = Vector3.zero;
          delta_rotation.ToAngleAxis(out angle, out axis);

          if (angle >= 180) {
        angle = 360 - angle;
        axis  = -axis;
          }
          if (angle != 0)
        bones[i].rigidbody.angularVelocity = (1 - easing) * angle * axis;

          last_bone_direction = bone_direction;
          last_bone_normal = bone_normal;
        }
    }
Ejemplo n.º 11
0
 // Determines if the targetObject is within sight of the transform. It will set the angle regardless of whether or not the object is within sight
 private static GameObject WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, GameObject targetObject, Vector3 targetOffset, bool usePhysics2D, out float angle, int ignoreLayerMask)
 {
     // The target object needs to be within the field of view of the current object
     var direction = targetObject.transform.position - transform.TransformPoint(positionOffset);
     if (usePhysics2D)
     {
         angle = Vector3.Angle(direction, transform.up);
         direction.z = 0;
     }
     else
     {
         angle = Vector3.Angle(direction, transform.forward);
         direction.y = 0;
     }
     if (direction.magnitude < viewDistance && angle < fieldOfViewAngle * 0.5f)
     {
         // The hit agent needs to be within view of the current agent
         if (LineOfSight(transform, positionOffset, targetObject, targetOffset, usePhysics2D, ignoreLayerMask) == targetObject)
         {
             return targetObject; // return the target object meaning it is within sight
         }
         else if (targetObject.GetComponent<Collider>() == null && targetObject.GetComponent<Collider2D>() == null)
         {
             // If the linecast doesn't hit anything then that the target object doesn't have a collider and there is nothing in the way
             if (targetObject.gameObject.activeSelf)
                 return targetObject;
         }
     }
     // return null if the target object is not within sight
     return null;
 }
Ejemplo n.º 12
0
	void DrawLayoutOutline(Transform t) {
		var layout = t.GetComponent<tk2dUILayout>();
		if (layout != null) {
			Vector3[] p = new Vector3[] {
				new Vector3(layout.bMin.x, layout.bMin.y, 0.0f),
				new Vector3(layout.bMax.x, layout.bMin.y, 0.0f),
				new Vector3(layout.bMax.x, layout.bMax.y, 0.0f),
				new Vector3(layout.bMin.x, layout.bMax.y, 0.0f),
				new Vector3(layout.bMin.x, layout.bMin.y, 0.0f),
			};
			for (int i = 0; i < p.Length; ++i) p[i] = t.TransformPoint(p[i]);
			Handles.color = Color.magenta;
			Handles.DrawPolyLine(p);

			var sizer = t.GetComponent<tk2dUILayoutContainerSizer>();
			if (sizer != null) {
				Handles.color = Color.cyan;
				float arrowSize = 0.3f * HandleUtility.GetHandleSize(p[0]);
				if (sizer.horizontal) {
					Handles.ArrowCap(0, (p[0] + p[3]) * 0.5f, Quaternion.LookRotation(p[1] - p[0]), arrowSize);
					Handles.ArrowCap(0, (p[1] + p[2]) * 0.5f, Quaternion.LookRotation(p[0] - p[1]), arrowSize);
				} else {
					Handles.ArrowCap(0, (p[0] + p[1]) * 0.5f, Quaternion.LookRotation(p[3] - p[0]), arrowSize);
					Handles.ArrowCap(0, (p[2] + p[3]) * 0.5f, Quaternion.LookRotation(p[0] - p[3]), arrowSize);
				}
			}
		}

		for (int i = 0; i < t.childCount; ++i)
			DrawLayoutOutline(t.GetChild(i));
	}
Ejemplo n.º 13
0
    public static FreePositionView InstantiateWithParent(TilePosition p_position, Transform p_parent, Player p_owner)
    {
        try {
            // Creation of the new instance.
            GameObject _new_instance = UnityEngine.Object.Instantiate (RESOURCE) as GameObject;
            _new_instance.transform.parent = p_parent;

            // Get the script associated with the new tile.
            FreePositionView _this = _new_instance.AddComponent<FreePositionView> ();

            // Set the common properties
            _this.m_position = p_position;
            _this.m_player = p_owner;
            if(_this.m_position != null)
            {
                // TODO Rework this Duplicate from TileView.
                Vector3 position = new Vector3(_this.m_position.x * 1.5f * TileView.OffsetX, 0, (_this.m_position.y + 1 ) * TileView.OffsetY);
                _this.transform.position = p_parent.TransformPoint(position);
            }
            else
            {
                Debug.LogError("Position for FreePositionView null !");
            }

            return _this;

        } catch (Exception) {
            Debug.LogError ("Error while instantiating FreePosition! Prefab not found !");
            return null;
        }
    }
Ejemplo n.º 14
0
		internal static void Handle(PivotType aSides, Transform aTransform, bool aLockX, bool aLockY, bool aLockZ, Vector3 aSnap, ref Vector3 lbf, ref Vector3 rtb, Handles.DrawCapFunction aCap) {
			Vector3 pt = new Vector3(0,0,0);
			Vector3 mask = new Vector3(aLockX?1:0, aLockY?1:0, aLockZ?1:0);
			if ((aSides & PivotType.Left  ) > 0) pt.x = lbf.x;
			if ((aSides & PivotType.Right ) > 0) pt.x = rtb.x;
			if ((aSides & PivotType.Top   ) > 0) pt.y = rtb.y;
			if ((aSides & PivotType.Bottom) > 0) pt.y = lbf.y;
			if ((aSides & PivotType.Front ) > 0) pt.z = lbf.z;
			if ((aSides & PivotType.Back  ) > 0) pt.z = rtb.z;
			pt = aTransform.TransformPoint(pt);
			
			Vector3 result = Handles.FreeMoveHandle(pt, Quaternion.identity, HandleUtility.GetHandleSize(pt) * mHandleSize, Vector3.zero, aCap);
			if (result != pt) {
				Vector3 dir = SuperCubeEditorUtil.CreateBillboardNormal(pt, aLockX, aLockY, aLockZ);
				result = SuperCubeEditorUtil.SnapVector(Vector3.Scale(SuperCubeEditorUtil.GetPlanePoint(result, new Plane(dir, pt)), mask), aSnap);
				result = aTransform.InverseTransformPoint(result);
				
				if ((aSides & PivotType.Left  ) > 0) lbf.x = result.x;
				if ((aSides & PivotType.Right ) > 0) rtb.x = result.x;
				if ((aSides & PivotType.Top   ) > 0) rtb.y = result.y;
				if ((aSides & PivotType.Bottom) > 0) lbf.y = result.y;
				if ((aSides & PivotType.Front ) > 0) lbf.z = result.z;
				if ((aSides & PivotType.Back  ) > 0) rtb.z = result.z;
			}
		}
 static public int TransformPoint(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.Transform self = (UnityEngine.Transform)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             var ret = self.TransformPoint(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.Transform self = (UnityEngine.Transform)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             var ret = self.TransformPoint(a1, a2, a3);
             pushValue(l, ret);
             return(1);
         }
         return(error(l, "No matched override function to call"));
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 16
0
    public override void UpdateHand(Transform deviceTransform)
    {
        Hand leap_hand = GetLeapHand();
        // Update all the fingers and palm.
        Vector3 palm_normal = deviceTransform.rotation * leap_hand.PalmNormal.ToUnityScaled();
        Vector3 palm_direction = deviceTransform.rotation * leap_hand.Direction.ToUnityScaled();
        Vector3 palm_center = GetPalmCenter(leap_hand);

        for (int f = 0; f < NUM_FINGERS; ++f) {
          if (fingers[f] != null) {
        fingers[f].UpdateFinger(leap_hand.Fingers[f], deviceTransform, palm_normal, palm_direction);
          }
        }

        if (palm != null) {
          // Set palm velocity.
          Vector3 next_position = deviceTransform.TransformPoint(palm_center);
          palm.rigidbody.velocity = (next_position - palm.transform.position) *
                                (1 - easing) / Time.fixedDeltaTime;

          // Set palm angular velocity.
          Quaternion delta_rotation = Quaternion.LookRotation(palm_normal, palm_direction) *
                                  Quaternion.Inverse(palm.transform.rotation);
          float angle = 0.0f;
          Vector3 axis = Vector3.zero;
          delta_rotation.ToAngleAxis(out angle, out axis);

          if (angle >= 180) {
        angle = 360 - angle;
        axis = -axis;
          }
          if (angle != 0)
        palm.rigidbody.angularVelocity = (1 - easing) * angle * axis;
        }
    }
        void LateUpdate()
        {
            Vector3    cameraPositionInSourceSpace = source.InverseTransformPoint(playerCamera.transform.position);
            Quaternion cameraRotationInSourceSpace = Quaternion.Inverse(source.rotation) * playerCamera.transform.rotation;

            transform.position = destination.TransformPoint(cameraPositionInSourceSpace);
            transform.rotation = destination.rotation * cameraRotationInSourceSpace;

            Vector3 destinationNormal = teleporterForOtherPortal.portalNormal;

            float dot = Vector3.Dot(teleporterForPortalBeingRendered.portalNormal, playerCamera.transform.position - source.position);
            // TODO: This is an approximation of edge-to-edge distance between colliders, maybe improve this to be true edge-to-edge distance?
            float distanceFromPlayerToPortal = GetDistanceFromPlayerToPortal();

            if (dot < 0.1f || distanceFromPlayerToPortal < 3)
            {
                portalCamera.projectionMatrix = originalProjectionMatrix;
                return;
            }

            // The leeway is to prevent "slices" at the bottom of the portal that fail to render properly (floating point error)
            float   leeway               = Mathf.Lerp(0f, 2.5f, distanceFromPlayerToPortal / 100f);
            float   distance             = Vector3.Dot(destination.position + destinationNormal * -leeway, -destinationNormal);
            Vector4 clipPlaneWorldSpace  = new Vector4(destinationNormal.x, destinationNormal.y, destinationNormal.z, distance);
            Vector4 clipPlaneCameraSpace = Matrix4x4.Transpose(Matrix4x4.Inverse(portalCamera.worldToCameraMatrix)) * clipPlaneWorldSpace;

            portalCamera.projectionMatrix = playerCamera.CalculateObliqueMatrix(clipPlaneCameraSpace);
        }
 public Line ToWorldFrom(Transform t)
 {
     Line ret = new Line();
     ret.from = t.TransformPoint(from);
     ret.to = ret.from + t.TransformDirection(to - from);
     return ret;
 }
Ejemplo n.º 19
0
 static public int TransformPoint(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(UnityEngine.Vector3)))
         {
             UnityEngine.Transform self = (UnityEngine.Transform)checkSelf(l);
             UnityEngine.Vector3   a1;
             checkType(l, 2, out a1);
             UnityEngine.Vector3 ret = self.TransformPoint(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, 2, typeof(System.Single), typeof(System.Single), typeof(System.Single)))
         {
             UnityEngine.Transform self = (UnityEngine.Transform)checkSelf(l);
             System.Single         a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             UnityEngine.Vector3 ret = self.TransformPoint(a1, a2, a3);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
    static int TransformPoint(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.Transform obj  = (UnityEngine.Transform)ToLua.CheckObject <UnityEngine.Transform>(L, 1);
                UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
                UnityEngine.Vector3   o    = obj.TransformPoint(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4)
            {
                UnityEngine.Transform obj = (UnityEngine.Transform)ToLua.CheckObject <UnityEngine.Transform>(L, 1);
                float arg0            = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1            = (float)LuaDLL.luaL_checknumber(L, 3);
                float arg2            = (float)LuaDLL.luaL_checknumber(L, 4);
                UnityEngine.Vector3 o = obj.TransformPoint(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Transform.TransformPoint"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 21
0
    public void startGame(bool fromRestart)
    {
        playerController = PlayerController.instance;
        playerTransform = playerController.transform;
        if (fromRestart) {
            targetPosition = inGamePosition;
            targetRotation.eulerAngles = inGameRotation;

            thisTransform.position = playerTransform.TransformPoint(inGamePosition);

            Vector3 relativeTargetRotationVec = inGameRotation;
            relativeTargetRotationVec.y += playerTransform.eulerAngles.y;
            Quaternion relativeTargetRotation = thisTransform.rotation;
            relativeTargetRotation.eulerAngles = relativeTargetRotationVec;
            thisTransform.rotation = relativeTargetRotation;

            transitioning = false;
        } else {
            targetPosition = inGamePosition;
            targetRotation.eulerAngles = inGameRotation;
            transitioning = true;
        }
        gameActive = true;

        GameManager.instance.onPauseGame += gamePaused;
        isShaking = false;
    }
Ejemplo n.º 22
0
 public void fChangeToSubCamera(Transform playerTrans)
 {
     mainCamera.enabled = false;
     subCamera.enabled = true;
     subCameraVect3 = playerTrans.TransformPoint (Vector3.forward * 3);
     gameObject.transform.position = subCameraVect3;
     transform.LookAt (lookTransform);
     clearedUi.fClearedOn ();
 }
Ejemplo n.º 23
0
 public void Transform(UnityEngine.Transform tranform)
 {
     this.dir = tranform.TransformDirection(this.dir);
     for (int i = 0; i < 4; i++)
     {
         this.offsets[i]  = tranform.TransformPoint(this.offsets[i]);
         this.offsets[i] -= tranform.position;
     }
 }
Ejemplo n.º 24
0
	public static void ProcessMesh(MeshFilter mf, Transform t)
	{
		int numVertices = 0;

		Mesh m = mf.mesh;
		if (!m)
		{
			meshString.Append("####Error####\n");
			return;
		}

		foreach (Vector3 vv in m.vertices)
		{
			Vector3 v = t.TransformPoint(vv);
			numVertices++;
			meshString.Append(string.Format("v {0} {1} {2}\n", v.x, v.y, -v.z));
		}
		meshString.Append("\n");
		foreach (Vector3 nn in m.normals)
		{
			Vector3 v = t.TransformDirection(nn);
			meshString.Append(string.Format("vn {0} {1} {2}\n", -v.x, -v.y, v.z));
		}
		meshString.Append("\n");
		foreach (Vector3 v in m.uv)
		{
			meshString.Append(string.Format("vt {0} {1}\n", v.x, v.y));
		}

		Material[] mats = mf.GetComponent<MeshRenderer>().materials;
		for (int material = 0; material < m.subMeshCount; material++)
		{
			Material mat = mats[material % mats.Length];
			string matName = mat.name.Replace(" (Instance)", "").Replace(' ', '_').Replace("__", "_");

			if (!materialList.ContainsKey(matName))
			{
				materialList.Add(matName, mat);
			}

			meshString.Append("\n");
			meshString.Append("usemtl ").Append(matName).Append("\n");
			meshString.Append("usemap ").Append(matName).Append("\n");

			int[] triangles = m.GetTriangles(material);
			for (int i = 0; i < triangles.Length; i += 3)
			{
				meshString.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n",
					triangles[i    ] + 1 + indexOffset, 
					triangles[i + 1] + 1 + indexOffset, 
					triangles[i + 2] + 1 + indexOffset));
			}
		}

		indexOffset += numVertices;
	}
Ejemplo n.º 25
0
        public Pivot(Transform pivotin, float incrementIn, Vector2 bounds)
        {
            pivot = pivotin;
            increment = Mathf.Deg2Rad * incrementIn;
            angleMinus = Mathf.Deg2Rad * bounds.y;
            anglePlus = Mathf.Deg2Rad * bounds.x;
            fullcircle = bounds == Vector2.zero;

            parentOrigRef = pivot.parent.InverseTransformPoint(pivot.TransformPoint(Vector3.up));
        }
Ejemplo n.º 26
0
 private void DrawEdgesForSelectedPoint(Vector3 worldPos, Transform transform, bool leftIntersect, bool rightIntersect, bool loop)
 {
     Vector2 vector2;
     Vector2 vector3;
     bool flag = true;
     bool flag2 = true;
     int pointCount = PolygonEditor.GetPointCount(this.m_SelectedPath);
     int pointIndex = this.m_SelectedVertex - 1;
     if (pointIndex == -1)
     {
         pointIndex = pointCount - 1;
         flag = loop;
     }
     int num3 = this.m_SelectedVertex + 1;
     if (num3 == pointCount)
     {
         num3 = 0;
         flag2 = loop;
     }
     Vector2 offset = this.m_ActiveCollider.offset;
     PolygonEditor.GetPoint(this.m_SelectedPath, pointIndex, out vector2);
     PolygonEditor.GetPoint(this.m_SelectedPath, num3, out vector3);
     vector2 += offset;
     vector3 += offset;
     Vector3 vector4 = transform.TransformPoint((Vector3) vector2);
     Vector3 vector5 = transform.TransformPoint((Vector3) vector3);
     vector4.z = vector5.z = worldPos.z;
     float width = 4f;
     if (flag)
     {
         Handles.color = (!leftIntersect && !this.m_DeleteMode) ? Color.green : Color.red;
         Vector3[] points = new Vector3[] { worldPos, vector4 };
         Handles.DrawAAPolyLine(width, points);
     }
     if (flag2)
     {
         Handles.color = (!rightIntersect && !this.m_DeleteMode) ? Color.green : Color.red;
         Vector3[] vectorArray2 = new Vector3[] { worldPos, vector5 };
         Handles.DrawAAPolyLine(width, vectorArray2);
     }
     Handles.color = Color.white;
 }
 public static void SplineEditHelper(Vector3[] path, Transform transform)
 {
     Vector3[] points = path;
     for(int i = 0; i < points.Length; i++){
         Vector3 v3 = Handles.PositionHandle(transform.TransformPoint(points[i]), transform.rotation);
         v3 = transform.InverseTransformPoint(v3);
         if(v3 != points[i]){
             points[i] = v3;
         }
     }
 }
Ejemplo n.º 28
0
    public static Transform LineOfSight(Transform transform, Vector3 positionOffset, Transform targetObject, bool usePhysics2D)
    {
        RaycastHit hit;
        if (Physics.Linecast(transform.TransformPoint(positionOffset), targetObject.position, out hit))
        {
            if (hit.transform.Equals(targetObject))
            {
                return targetObject; // return the target object meaning it is within sight
            }
        }

        return null;
    }
Ejemplo n.º 29
0
	private void calculateUVs(Transform t,GameObject go){
		MeshFilter mf = go.GetComponent<MeshFilter> ();
		if (mf == null) {
			return;
		}

		Mesh mesh = mf.sharedMesh;    

		if (mesh == null) {
			return;
		}

		Vector2[] uvs = new Vector2[mesh.vertices.Length];
		
		for (int triangle = 0; triangle < mesh.triangles.Length/3; triangle++) {
			
			Vector3[] positions = new Vector3[3];
			int[] indices = new int[3];
			Vector3 normal = new Vector3();
			
			for (int i=0; i<3; i++) {
				
				int vertexIndex = mesh.triangles [triangle * 3 + i];
				indices[i] = vertexIndex;
				if (t != null) {
					positions [i] = t.TransformPoint (mesh.vertices [vertexIndex]);
				} else {
					positions [i] = mesh.vertices [vertexIndex];
				}

				if (t != null) {
					normal += t.TransformDirection (mesh.normals [vertexIndex]);
				} else {
					normal += mesh.normals [vertexIndex];
				}
			}
			
			normal/=3;
			
			Quaternion rot = Quaternion.FromToRotation (normal, new Vector3 (0, 0, 1));

			Vector3 up = Vabs(rot*Vector3.up);
			Vector3 right = rot*Vector3.right;
			
			for (int j=0; j<positions.Length; j++) {
				uvs [indices[j]].x = Vector3.Dot(right,positions[j])/xScale;
				uvs [indices[j]].y = Vector3.Dot(up,positions[j])/yScale;
			}
		}
		mesh.uv4 = uvs;
	}
Ejemplo n.º 30
0
 public bool OnSceneGUI(Transform transform, Color color, bool handlesOnly, ref Vector3 center, ref Vector3 size)
 {
   if (!this.m_UseLossyScale)
     return this.OnSceneGUI(transform.localToWorldMatrix, color, handlesOnly, ref center, ref size);
   Matrix4x4 transform1 = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
   size.Scale(transform.lossyScale);
   center = transform.TransformPoint(center);
   center = transform1.inverse.MultiplyPoint(center);
   bool flag = this.OnSceneGUI(transform1, color, handlesOnly, ref center, ref size);
   center = transform1.MultiplyPoint(center);
   center = transform.InverseTransformPoint(center);
   size.Scale(new Vector3(1f / transform.lossyScale.x, 1f / transform.lossyScale.y, 1f / transform.lossyScale.z));
   return flag;
 }
Ejemplo n.º 31
0
	public static string MeshToString(MeshFilter mf, Transform t) 
	{	
		Vector3 s 		= t.localScale;
		Vector3 p 		= t.localPosition;
		Quaternion r 	= t.localRotation;
		
		
		int numVertices = 0;
		Mesh m = mf.sharedMesh;
		if (!m)
		{
			return "####Error####";
		}
		Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;
		
		StringBuilder sb = new StringBuilder();
		
		foreach(Vector3 vv in m.vertices)
		{
			Vector3 v = t.TransformPoint(vv);
			numVertices++;
			sb.Append(string.Format("v {0} {1} {2}\n",v.x,v.y,-v.z));
		}
		sb.Append("\n");
		foreach(Vector3 nn in m.normals) 
		{
			Vector3 v = r * nn;
			sb.Append(string.Format("vn {0} {1} {2}\n",-v.x,-v.y,v.z));
		}
		sb.Append("\n");
		foreach(Vector3 v in m.uv) 
		{
			sb.Append(string.Format("vt {0} {1}\n",v.x,v.y));
		}
		for (int material=0; material < m.subMeshCount; material ++) 
		{
			sb.Append("\n");
			sb.Append("usemtl ").Append(mats[material].name).Append("\n");
			sb.Append("usemap ").Append(mats[material].name).Append("\n");
			
			int[] triangles = m.GetTriangles(material);
			for (int i=0;i<triangles.Length;i+=3) {
				sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", 
				                        triangles[i]+1+StartIndex, triangles[i+1]+1+StartIndex, triangles[i+2]+1+StartIndex));
			}
		}
		
		StartIndex += numVertices;
		return sb.ToString();
	}
Ejemplo n.º 32
0
 public void Text(string output, Transform offset, float overrideScale, Color textColor)
 {
     scale = overrideScale;
     Vector3 letterOffset = Vector3.zero;
     for(int i=0;i<output.Length;i++){
         if(dict.ContainsKey(output[i].ToString())){
             List<object> letter = (List<object>)dict[output[i].ToString()];
             for(int k=0;k<letter.Count;k++){
                 List<object> points = (List<object>)letter[k];
                 for(int j = 0; j<points.Count-1;j++){
                     List<object> p1 = (List<object>)points[j];
                     List<object> p2 = (List<object>)points[j+1];
                     Vector3 pa = new Vector3(float.Parse(p1[0].ToString()), -float.Parse(p1[1].ToString()), 0);
                     Vector3 pb = new Vector3(float.Parse(p2[0].ToString()), -float.Parse(p2[1].ToString()), 0);
                     pa*=scale;
                     pb*=scale;
                     lines.AddLine(offset.TransformPoint(pa+letterOffset), offset.TransformPoint(pb+letterOffset), textColor);
                 }
             }
         }
         letterOffset += new Vector3(3*scale, 0, 0);
     }
 }
    static int TransformPoint(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2 && ToLua.CheckTypes(L, 1, typeof(UnityEngine.Transform), typeof(UnityEngine.Vector3)))
        {
            UnityEngine.Transform obj  = (UnityEngine.Transform)ToLua.ToObject(L, 1);
            UnityEngine.Vector3   arg0 = ToLua.ToVector3(L, 2);
            UnityEngine.Vector3   o;

            try
            {
                o = obj.TransformPoint(arg0);
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }

            ToLua.Push(L, o);
            return(1);
        }
        else if (count == 4 && ToLua.CheckTypes(L, 1, typeof(UnityEngine.Transform), typeof(float), typeof(float), typeof(float)))
        {
            UnityEngine.Transform obj = (UnityEngine.Transform)ToLua.ToObject(L, 1);
            float arg0 = (float)LuaDLL.lua_tonumber(L, 2);
            float arg1 = (float)LuaDLL.lua_tonumber(L, 3);
            float arg2 = (float)LuaDLL.lua_tonumber(L, 4);
            UnityEngine.Vector3 o;

            try
            {
                o = obj.TransformPoint(arg0, arg1, arg2);
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }

            ToLua.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: UnityEngine.Transform.TransformPoint");
        }

        return(0);
    }
	static void CovertToWorldSpace (ref Mesh originalMesh, Transform meshTransform)
	{
		Vector3[] newVertices = new Vector3[originalMesh.vertexCount];
		Vector3[] newNormals = new Vector3[originalMesh.vertexCount];
		Vector4[] newTangents = new Vector4[originalMesh.vertexCount];
		for (int i = 0; i < originalMesh.vertexCount; i++)
		{
			newVertices[i] = meshTransform.TransformPoint(originalMesh.vertices[i]);
			newNormals[i] = meshTransform.TransformVector(originalMesh.normals[i]);
			newTangents[i] = meshTransform.TransformVector(originalMesh.tangents[i]);
		}
		originalMesh.vertices = newVertices;
		originalMesh.normals = newNormals;
		originalMesh.tangents = newTangents;
	}
Ejemplo n.º 35
0
 public void UpdateFingers(Hand h, Transform parent, Vector3 offset)
 {
     for (int i = 0; i < m_fingers.Length; ++i) {
         LeapFinger finger = m_fingers[i].GetComponent<LeapFinger>();
         GameObject [] joints = finger.GetJoints();
         GameObject [] langes = finger.GetLanges();
         for(int j = 0; j < joints.Length; ++j) {
             Vector3 pos = parent.TransformPoint(offset + h.Fingers[i].JointPosition((Finger.FingerJoint) j).ToUnityScaled());
             Vector3 nextPos = parent.TransformPoint(offset + h.Fingers[i].JointPosition((Finger.FingerJoint) j + 1).ToUnityScaled());
             joints[j].transform.position = pos;
             joints[j].rigidbody.velocity = parent.TransformDirection(h.Fingers[i].TipVelocity.ToUnityScaled());
             Vector3 langePos = (pos + nextPos) * 0.5f;
             langes[j].transform.position = langePos;
             langes[j].transform.up = (nextPos - pos);
             Vector3 newScale = langes[j].transform.localScale;
             newScale.y = Mathf.Max(0.0f, (nextPos - pos).magnitude - 0.003f);
             langes[j].transform.localScale = newScale;
         }
         Vector3 tipPos = parent.TransformPoint(offset + h.Fingers[i].JointPosition(Finger.FingerJoint.JOINTTIP).ToUnityScaled());
         finger.GetFingerTip().transform.position = tipPos;
         finger.GetFingerTip().rigidbody.velocity = parent.TransformDirection(h.Fingers[i].TipVelocity.ToUnityScaled());
         finger.m_fingerID = h.Fingers[i].Id;
     }
 }
Ejemplo n.º 36
0
 static public int TransformPoint__Vector3(IntPtr l)
 {
     try {
         UnityEngine.Transform self = (UnityEngine.Transform)checkSelf(l);
         UnityEngine.Vector3   a1;
         checkType(l, 2, out a1);
         var ret = self.TransformPoint(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public void DrawGizmos(Transform t)
 {
     Vector3 pivotWorld = t.TransformPoint(pivotPoint);
     Vector3 forwardWorld = t.TransformDirection(forward).normalized;
     Vector3 upWorld = t.TransformDirection(up).normalized;
     Vector3 rightWorld = Vector3.Cross(forwardWorld, upWorld);
     upWorld = Vector3.Cross(rightWorld, forwardWorld);
     upWorld.Normalize();
     forwardWorld.Normalize();
     Gizmos.color = Color.red;
     Gizmos.DrawLine(pivotWorld, pivotWorld + rightWorld);
     Gizmos.color = Color.green;
     Gizmos.DrawLine(pivotWorld, pivotWorld + upWorld);
     Gizmos.color = Color.blue;
     Gizmos.DrawLine(pivotWorld, pivotWorld + forwardWorld);
 }
Ejemplo n.º 38
0
    public Vector3 RecursiveTransform(Vector3 pt, Transform trans)
    {
        //Basically, this will transform the point until it has no more parent transforms.
        Vector3 pt1 = Vector3.zero;
        //If we have a parent transform, run this function again
        if (trans.parent != null)
        {
            pt = RecursiveTransform(pt1, trans.parent);

            return pt;
        }
        else
        {
            pt1 = trans.TransformPoint(pt);
            return pt1;
        }
    }
Ejemplo n.º 39
0
 static public int TransformPoint__Single__Single__Single(IntPtr l)
 {
     try {
         UnityEngine.Transform self = (UnityEngine.Transform)checkSelf(l);
         System.Single         a1;
         checkType(l, 2, out a1);
         System.Single a2;
         checkType(l, 3, out a2);
         System.Single a3;
         checkType(l, 4, out a3);
         var ret = self.TransformPoint(a1, a2, a3);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 40
0
        private void RenderFocalPoints(List <UnityEngine.Vector4> focalPoints, Color color, float radius)
        {
            Color previousColor = Gizmos.color;

            Gizmos.color = color;

            foreach (var focalPoint in focalPoints)
            {
                var focalPointInEmitterSpace = new UnityEngine.Vector3(focalPoint.x, focalPoint.y, focalPoint.z);
                var focalPointInUnitySpace   = UnityToEmitterSpace.Transform.inverse * focalPointInEmitterSpace;
                if (ArrayTransform != null)
                {
                    focalPointInUnitySpace = ArrayTransform.TransformPoint(focalPointInUnitySpace);
                }
                color.a      = focalPoint.w;
                Gizmos.color = color;
                Gizmos.DrawSphere(focalPointInUnitySpace, radius);
            }

            Gizmos.color = previousColor;
        }
Ejemplo n.º 41
0
 /// <summary>Gets the bone's Unity World position using its Spine GameObject Transform. UpdateWorldTransform needs to have been called for this to return the correct, updated value.</summary>
 public static Vector3 GetWorldPosition(this Bone bone, UnityEngine.Transform spineGameObjectTransform)
 {
     return(spineGameObjectTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY)));
 }
Ejemplo n.º 42
0
        public static bool UnityEngineTransformMCall(object objSelf, string functionName, List <CQ_Value> param, out CQ_Value returnValue, bool mustEqual)
        {
            UnityEngine.Transform obj = (UnityEngine.Transform)objSelf;
            if (param.Count == 1 && functionName == "SetParent" && MatchType(param, new Type[] { typeof(UnityEngine.Transform) }, mustEqual))
            {
                returnValue = null;
                obj.SetParent((UnityEngine.Transform)param[0].ConvertTo(typeof(UnityEngine.Transform)));
                return(true);
            }
            if (param.Count == 2 && functionName == "SetParent" && MatchType(param, new Type[] { typeof(UnityEngine.Transform), typeof(bool) }, mustEqual))
            {
                returnValue = null;
                obj.SetParent((UnityEngine.Transform)param[0].ConvertTo(typeof(UnityEngine.Transform)), (bool)param[1].ConvertTo(typeof(bool)));
                return(true);
            }
            if (param.Count == 2 && functionName == "SetPositionAndRotation" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(UnityEngine.Quaternion) }, mustEqual))
            {
                returnValue = null;
                obj.SetPositionAndRotation((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (UnityEngine.Quaternion)param[1].ConvertTo(typeof(UnityEngine.Quaternion)));
                return(true);
            }
            if (param.Count == 1 && functionName == "Translate" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue = null;
                obj.Translate((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 2 && functionName == "Translate" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(UnityEngine.Space) }, mustEqual))
            {
                returnValue = null;
                obj.Translate((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (UnityEngine.Space)param[1].ConvertTo(typeof(UnityEngine.Space)));
                return(true);
            }
            if (param.Count == 3 && functionName == "Translate" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue = null;
                obj.Translate((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 4 && functionName == "Translate" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float), typeof(UnityEngine.Space) }, mustEqual))
            {
                returnValue = null;
                obj.Translate((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)), (UnityEngine.Space)param[3].ConvertTo(typeof(UnityEngine.Space)));
                return(true);
            }
            if (param.Count == 2 && functionName == "Translate" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(UnityEngine.Transform) }, mustEqual))
            {
                returnValue = null;
                obj.Translate((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (UnityEngine.Transform)param[1].ConvertTo(typeof(UnityEngine.Transform)));
                return(true);
            }
            if (param.Count == 4 && functionName == "Translate" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float), typeof(UnityEngine.Transform) }, mustEqual))
            {
                returnValue = null;
                obj.Translate((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)), (UnityEngine.Transform)param[3].ConvertTo(typeof(UnityEngine.Transform)));
                return(true);
            }
            if (param.Count == 1 && functionName == "Rotate" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue = null;
                obj.Rotate((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 2 && functionName == "Rotate" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(UnityEngine.Space) }, mustEqual))
            {
                returnValue = null;
                obj.Rotate((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (UnityEngine.Space)param[1].ConvertTo(typeof(UnityEngine.Space)));
                return(true);
            }
            if (param.Count == 3 && functionName == "Rotate" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue = null;
                obj.Rotate((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 4 && functionName == "Rotate" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float), typeof(UnityEngine.Space) }, mustEqual))
            {
                returnValue = null;
                obj.Rotate((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)), (UnityEngine.Space)param[3].ConvertTo(typeof(UnityEngine.Space)));
                return(true);
            }
            if (param.Count == 2 && functionName == "Rotate" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(float) }, mustEqual))
            {
                returnValue = null;
                obj.Rotate((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (float)param[1].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 3 && functionName == "Rotate" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(float), typeof(UnityEngine.Space) }, mustEqual))
            {
                returnValue = null;
                obj.Rotate((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (float)param[1].ConvertTo(typeof(float)), (UnityEngine.Space)param[2].ConvertTo(typeof(UnityEngine.Space)));
                return(true);
            }
            if (param.Count == 3 && functionName == "RotateAround" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(float) }, mustEqual))
            {
                returnValue = null;
                obj.RotateAround((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (UnityEngine.Vector3)param[1].ConvertTo(typeof(UnityEngine.Vector3)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 1 && functionName == "LookAt" && MatchType(param, new Type[] { typeof(UnityEngine.Transform) }, mustEqual))
            {
                returnValue = null;
                obj.LookAt((UnityEngine.Transform)param[0].ConvertTo(typeof(UnityEngine.Transform)));
                return(true);
            }
            if (param.Count == 2 && functionName == "LookAt" && MatchType(param, new Type[] { typeof(UnityEngine.Transform), typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue = null;
                obj.LookAt((UnityEngine.Transform)param[0].ConvertTo(typeof(UnityEngine.Transform)), (UnityEngine.Vector3)param[1].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 2 && functionName == "LookAt" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue = null;
                obj.LookAt((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (UnityEngine.Vector3)param[1].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 1 && functionName == "LookAt" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue = null;
                obj.LookAt((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 1 && functionName == "TransformDirection" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.TransformDirection((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 3 && functionName == "TransformDirection" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.TransformDirection((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 1 && functionName == "InverseTransformDirection" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.InverseTransformDirection((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 3 && functionName == "InverseTransformDirection" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.InverseTransformDirection((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 1 && functionName == "TransformVector" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.TransformVector((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 3 && functionName == "TransformVector" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.TransformVector((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 1 && functionName == "InverseTransformVector" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.InverseTransformVector((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 3 && functionName == "InverseTransformVector" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.InverseTransformVector((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 1 && functionName == "TransformPoint" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.TransformPoint((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 3 && functionName == "TransformPoint" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.TransformPoint((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 1 && functionName == "InverseTransformPoint" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.InverseTransformPoint((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)));
                return(true);
            }
            if (param.Count == 3 && functionName == "InverseTransformPoint" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Vector3);
                returnValue.value = obj.InverseTransformPoint((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 0 && functionName == "DetachChildren")
            {
                returnValue = null;
                obj.DetachChildren();
                return(true);
            }
            if (param.Count == 0 && functionName == "SetAsFirstSibling")
            {
                returnValue = null;
                obj.SetAsFirstSibling();
                return(true);
            }
            if (param.Count == 0 && functionName == "SetAsLastSibling")
            {
                returnValue = null;
                obj.SetAsLastSibling();
                return(true);
            }
            if (param.Count == 1 && functionName == "SetSiblingIndex" && MatchType(param, new Type[] { typeof(int) }, mustEqual))
            {
                returnValue = null;
                obj.SetSiblingIndex((int)param[0].ConvertTo(typeof(int)));
                return(true);
            }
            if (param.Count == 0 && functionName == "GetSiblingIndex")
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(int);
                returnValue.value = obj.GetSiblingIndex();
                return(true);
            }
            if (param.Count == 1 && functionName == "Find" && MatchType(param, new Type[] { typeof(string) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Transform);
                returnValue.value = obj.Find((string)param[0].ConvertTo(typeof(string)));
                return(true);
            }
            if (param.Count == 1 && functionName == "IsChildOf" && MatchType(param, new Type[] { typeof(UnityEngine.Transform) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(bool);
                returnValue.value = obj.IsChildOf((UnityEngine.Transform)param[0].ConvertTo(typeof(UnityEngine.Transform)));
                return(true);
            }
            if (param.Count == 1 && functionName == "FindChild" && MatchType(param, new Type[] { typeof(string) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Transform);
                returnValue.value = obj.Find((string)param[0].ConvertTo(typeof(string)));
                return(true);
            }
            if (param.Count == 2 && functionName == "RotateAround" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(float) }, mustEqual))
            {
                returnValue = null;
                obj.RotateAround((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (float)param[1].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 2 && functionName == "RotateAroundLocal" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3), typeof(float) }, mustEqual))
            {
                returnValue = null;
                obj.RotateAroundLocal((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3)), (float)param[1].ConvertTo(typeof(float)));
                return(true);
            }
            if (param.Count == 1 && functionName == "GetChild" && MatchType(param, new Type[] { typeof(int) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Transform);
                returnValue.value = obj.GetChild((int)param[0].ConvertTo(typeof(int)));
                return(true);
            }
            if (param.Count == 0 && functionName == "GetChildCount")
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(int);
                returnValue.value = obj.GetChildCount();
                return(true);
            }
            if (param.Count == 1 && functionName == "GetComponent" && MatchType(param, new Type[] { typeof(System.Type) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component);
                returnValue.value = obj.GetComponent((System.Type)param[0].ConvertTo(typeof(System.Type)));
                return(true);
            }
            if (param.Count == 1 && functionName == "GetComponent" && MatchType(param, new Type[] { typeof(string) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component);
                returnValue.value = obj.GetComponent((string)param[0].ConvertTo(typeof(string)));
                return(true);
            }
            if (param.Count == 2 && functionName == "GetComponentInChildren" && MatchType(param, new Type[] { typeof(System.Type), typeof(bool) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component);
                returnValue.value = obj.GetComponentInChildren((System.Type)param[0].ConvertTo(typeof(System.Type)), (bool)param[1].ConvertTo(typeof(bool)));
                return(true);
            }
            if (param.Count == 1 && functionName == "GetComponentInChildren" && MatchType(param, new Type[] { typeof(System.Type) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component);
                returnValue.value = obj.GetComponentInChildren((System.Type)param[0].ConvertTo(typeof(System.Type)));
                return(true);
            }
            if (param.Count == 1 && functionName == "GetComponentsInChildren" && MatchType(param, new Type[] { typeof(System.Type) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component[]);
                returnValue.value = obj.GetComponentsInChildren((System.Type)param[0].ConvertTo(typeof(System.Type)));
                return(true);
            }
            if (param.Count == 2 && functionName == "GetComponentsInChildren" && MatchType(param, new Type[] { typeof(System.Type), typeof(bool) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component[]);
                returnValue.value = obj.GetComponentsInChildren((System.Type)param[0].ConvertTo(typeof(System.Type)), (bool)param[1].ConvertTo(typeof(bool)));
                return(true);
            }
            if (param.Count == 1 && functionName == "GetComponentInParent" && MatchType(param, new Type[] { typeof(System.Type) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component);
                returnValue.value = obj.GetComponentInParent((System.Type)param[0].ConvertTo(typeof(System.Type)));
                return(true);
            }
            if (param.Count == 1 && functionName == "GetComponentsInParent" && MatchType(param, new Type[] { typeof(System.Type) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component[]);
                returnValue.value = obj.GetComponentsInParent((System.Type)param[0].ConvertTo(typeof(System.Type)));
                return(true);
            }
            if (param.Count == 2 && functionName == "GetComponentsInParent" && MatchType(param, new Type[] { typeof(System.Type), typeof(bool) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component[]);
                returnValue.value = obj.GetComponentsInParent((System.Type)param[0].ConvertTo(typeof(System.Type)), (bool)param[1].ConvertTo(typeof(bool)));
                return(true);
            }
            if (param.Count == 1 && functionName == "GetComponents" && MatchType(param, new Type[] { typeof(System.Type) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(UnityEngine.Component[]);
                returnValue.value = obj.GetComponents((System.Type)param[0].ConvertTo(typeof(System.Type)));
                return(true);
            }
            if (param.Count == 1 && functionName == "CompareTag" && MatchType(param, new Type[] { typeof(string) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(bool);
                returnValue.value = obj.CompareTag((string)param[0].ConvertTo(typeof(string)));
                return(true);
            }
            if (param.Count == 3 && functionName == "SendMessageUpwards" && MatchType(param, new Type[] { typeof(string), typeof(object), typeof(UnityEngine.SendMessageOptions) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessageUpwards((string)param[0].ConvertTo(typeof(string)), (object)param[1].ConvertTo(typeof(object)), (UnityEngine.SendMessageOptions)param[2].ConvertTo(typeof(UnityEngine.SendMessageOptions)));
                return(true);
            }
            if (param.Count == 2 && functionName == "SendMessageUpwards" && MatchType(param, new Type[] { typeof(string), typeof(object) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessageUpwards((string)param[0].ConvertTo(typeof(string)), (object)param[1].ConvertTo(typeof(object)));
                return(true);
            }
            if (param.Count == 1 && functionName == "SendMessageUpwards" && MatchType(param, new Type[] { typeof(string) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessageUpwards((string)param[0].ConvertTo(typeof(string)));
                return(true);
            }
            if (param.Count == 2 && functionName == "SendMessageUpwards" && MatchType(param, new Type[] { typeof(string), typeof(UnityEngine.SendMessageOptions) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessageUpwards((string)param[0].ConvertTo(typeof(string)), (UnityEngine.SendMessageOptions)param[1].ConvertTo(typeof(UnityEngine.SendMessageOptions)));
                return(true);
            }
            if (param.Count == 3 && functionName == "SendMessage" && MatchType(param, new Type[] { typeof(string), typeof(object), typeof(UnityEngine.SendMessageOptions) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessage((string)param[0].ConvertTo(typeof(string)), (object)param[1].ConvertTo(typeof(object)), (UnityEngine.SendMessageOptions)param[2].ConvertTo(typeof(UnityEngine.SendMessageOptions)));
                return(true);
            }
            if (param.Count == 2 && functionName == "SendMessage" && MatchType(param, new Type[] { typeof(string), typeof(object) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessage((string)param[0].ConvertTo(typeof(string)), (object)param[1].ConvertTo(typeof(object)));
                return(true);
            }
            if (param.Count == 1 && functionName == "SendMessage" && MatchType(param, new Type[] { typeof(string) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessage((string)param[0].ConvertTo(typeof(string)));
                return(true);
            }
            if (param.Count == 2 && functionName == "SendMessage" && MatchType(param, new Type[] { typeof(string), typeof(UnityEngine.SendMessageOptions) }, mustEqual))
            {
                returnValue = null;
                obj.SendMessage((string)param[0].ConvertTo(typeof(string)), (UnityEngine.SendMessageOptions)param[1].ConvertTo(typeof(UnityEngine.SendMessageOptions)));
                return(true);
            }
            if (param.Count == 3 && functionName == "BroadcastMessage" && MatchType(param, new Type[] { typeof(string), typeof(object), typeof(UnityEngine.SendMessageOptions) }, mustEqual))
            {
                returnValue = null;
                obj.BroadcastMessage((string)param[0].ConvertTo(typeof(string)), (object)param[1].ConvertTo(typeof(object)), (UnityEngine.SendMessageOptions)param[2].ConvertTo(typeof(UnityEngine.SendMessageOptions)));
                return(true);
            }
            if (param.Count == 2 && functionName == "BroadcastMessage" && MatchType(param, new Type[] { typeof(string), typeof(object) }, mustEqual))
            {
                returnValue = null;
                obj.BroadcastMessage((string)param[0].ConvertTo(typeof(string)), (object)param[1].ConvertTo(typeof(object)));
                return(true);
            }
            if (param.Count == 1 && functionName == "BroadcastMessage" && MatchType(param, new Type[] { typeof(string) }, mustEqual))
            {
                returnValue = null;
                obj.BroadcastMessage((string)param[0].ConvertTo(typeof(string)));
                return(true);
            }
            if (param.Count == 2 && functionName == "BroadcastMessage" && MatchType(param, new Type[] { typeof(string), typeof(UnityEngine.SendMessageOptions) }, mustEqual))
            {
                returnValue = null;
                obj.BroadcastMessage((string)param[0].ConvertTo(typeof(string)), (UnityEngine.SendMessageOptions)param[1].ConvertTo(typeof(UnityEngine.SendMessageOptions)));
                return(true);
            }
            if (param.Count == 0 && functionName == "ToString")
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(string);
                returnValue.value = obj.ToString();
                return(true);
            }
            if (param.Count == 0 && functionName == "GetInstanceID")
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(int);
                returnValue.value = obj.GetInstanceID();
                return(true);
            }
            if (param.Count == 0 && functionName == "GetHashCode")
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(int);
                returnValue.value = obj.GetHashCode();
                return(true);
            }
            if (param.Count == 1 && functionName == "Equals" && MatchType(param, new Type[] { typeof(object) }, mustEqual))
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(bool);
                returnValue.value = obj.Equals((object)param[0].ConvertTo(typeof(object)));
                return(true);
            }
            if (param.Count == 0 && functionName == "GetType")
            {
                returnValue       = new CQ_Value();
                returnValue.type  = typeof(System.Type);
                returnValue.value = obj.GetType();
                return(true);
            }

            returnValue = null;
            return(false);
        }
Ejemplo n.º 43
0
        public void FixedUpdate(UnityEngine.Transform rootTransform)
        {
            // - physics rigid body management
            // -set transforms/velocities for key framed bodies

            // get all the prediction time infos in this struct
            PredictionTimeParameters timeInfo = new PredictionTimeParameters(UnityEngine.Time.fixedDeltaTime);

            // start the predictor
            _predictor.StartBodyPredicitonForNextFrame();

            int index = 0;
            MultiSourceCombinedSnapshot snapshot;

            _snapshotManager.Step(timeInfo.DT, out snapshot);
            _snapshotManager.UpdateDebugDisplay(rootTransform);             // guarded by ifdef internally

            foreach (var rb in _rigidBodies.Values)
            {
                // if the body is owned then we only set the kinematic flag for the physics
                if (rb.Ownership)
                {
                    if (rb.IsKeyframed)
                    {
                        rb.RigidBody.isKinematic = true;
                    }
                    else
                    {
                        rb.RigidBody.isKinematic = false;
                    }
                    continue;
                }

                // Find corresponding rigid body info.
                // since both are sorted list this should hit without index=0 at the beginning
                while (index < snapshot.RigidBodies.Count && rb.Id.CompareTo(snapshot.RigidBodies.Values[index].Id) > 0)
                {
                    index++;
                }

                if (index < snapshot.RigidBodies.Count && rb.Id == snapshot.RigidBodies.Values[index].Id)
                {
                    // todo: kick-in prediction if we are missing an update for this rigid body
                    //if (!snapshot.RigidBodies.Values[index].HasUpdate)
                    //{
                    //	rb.RigidBody.isKinematic = false;
                    //	continue;
                    //}

                    RigidBodyTransform transform = snapshot.RigidBodies.Values[index].Transform;
                    float timeOfSnapshot         = snapshot.RigidBodies.Values[index].LocalTime;

                    // get the key framed stream, and compute implicit velocities
                    UnityEngine.Vector3    keyFramedPos         = rootTransform.TransformPoint(transform.Position);
                    UnityEngine.Quaternion keyFramedOrientation = rootTransform.rotation * transform.Rotation;
                    UnityEngine.Vector3    JBLinearVelocity     =
                        rootTransform.rotation * snapshot.RigidBodies.Values[index].LinearVelocity;
                    UnityEngine.Vector3 JBAngularVelocity =
                        rootTransform.rotation * snapshot.RigidBodies.Values[index].AngularVelocity;
                    // if there is a really new update then also store the implicit velocity
                    if (rb.lastTimeKeyFramedUpdate < timeOfSnapshot)
                    {
                        // we moved the velocity estimation into the jitter buffer
                        rb.lastValidLinerVelocityOrPos   = JBLinearVelocity;
                        rb.lastValidAngularVelocityorAng = JBAngularVelocity;

#if MRE_PHYSICS_DEBUG
                        // test the source of large velocities
                        if (rb.lastValidLinerVelocityOrPos.sqrMagnitude > _maxEstimatedLinearVelocity * _maxEstimatedLinearVelocity)
                        {
                            // limited debug version
                            Debug.Log(" ACTIVE SPEED LIMIT TRAP RB: "                             //+ rb.Id.ToString() + " got update lin vel:"
                                      + rb.lastValidLinerVelocityOrPos + " ang vel:" + rb.lastValidAngularVelocityorAng
                                      + " time:" + timeOfSnapshot
                                      + " newR:" + rb.lastTimeKeyFramedUpdate
                                      + " hasupdate:" + snapshot.RigidBodies.Values[index].HasUpdate
                                      + " DangE:" + eulerAngles + " DangR:" + radianAngles);
                        }
#endif

                        // cap the velocities
                        rb.lastValidLinerVelocityOrPos = UnityEngine.Vector3.ClampMagnitude(
                            rb.lastValidLinerVelocityOrPos, _maxEstimatedLinearVelocity);
                        rb.lastValidAngularVelocityorAng = UnityEngine.Vector3.ClampMagnitude(
                            rb.lastValidAngularVelocityorAng, _maxEstimatedAngularVelocity);
                        // if body is sleeping then all velocities are zero
                        if (snapshot.RigidBodies.Values[index].motionType == Patching.Types.MotionType.Sleeping)
                        {
                            rb.lastValidLinerVelocityOrPos.Set(0.0F, 0.0F, 0.0F);
                            rb.lastValidAngularVelocityorAng.Set(0.0F, 0.0F, 0.0F);
                        }
#if MRE_PHYSICS_DEBUG
                        if (true)
                        {
                            // limited debug version
                            Debug.Log(" Remote body: " + rb.Id.ToString() + " got update lin vel:"
                                      + rb.lastValidLinerVelocityOrPos + " ang vel:" + rb.lastValidAngularVelocityorAng
                                      + " time:" + timeOfSnapshot + " newR:" + rb.lastTimeKeyFramedUpdate);
                        }
                        else
                        {
                            Debug.Log(" Remote body: " + rb.Id.ToString() + " got update lin vel:"
                                      + rb.lastValidLinerVelocityOrPos + " ang vel:" + rb.lastValidAngularVelocityorAng
                                      //+ " DangE:" + eulerAngles + " DangR:" + radianAngles
                                      + " time:" + timeOfSnapshot + " newp:" + keyFramedPos
                                      + " newR:" + keyFramedOrientation
                                      + " oldP:" + rb.RigidBody.transform.position
                                      + " oldR:" + rb.RigidBody.transform.rotation
                                      + " OriginalRot:" + transform.Rotation
                                      + " keyF:" + rb.RigidBody.isKinematic
                                      + " KF:" + rb.IsKeyframed);
                        }
#endif
                        // cap the velocities
                        rb.lastValidLinerVelocityOrPos = UnityEngine.Vector3.ClampMagnitude(
                            rb.lastValidLinerVelocityOrPos, _maxEstimatedLinearVelocity);
                        rb.lastValidAngularVelocityorAng = UnityEngine.Vector3.ClampMagnitude(
                            rb.lastValidAngularVelocityorAng, _maxEstimatedAngularVelocity);
                        // if body is sleeping then all velocities are zero
                        if (snapshot.RigidBodies.Values[index].motionType == Patching.Types.MotionType.Sleeping)
                        {
                            rb.lastValidLinerVelocityOrPos.Set(0.0F, 0.0F, 0.0F);
                            rb.lastValidAngularVelocityorAng.Set(0.0F, 0.0F, 0.0F);
                        }
#if MRE_PHYSICS_DEBUG
                        Debug.Log(" Remote body: " + rb.Id.ToString() + " got update lin vel:"
                                  + rb.lastValidLinerVelocityOrPos + " ang vel:" + rb.lastValidAngularVelocityorAng
                                  //+ " DangE:" + eulerAngles + " DangR:" + radianAngles
                                  + " time:" + timeOfSnapshot + " newp:" + keyFramedPos
                                  + " newR:" + keyFramedOrientation
                                  + " incUpdateDt:" + invUpdateDT
                                  + " oldP:" + rb.RigidBody.transform.position
                                  + " oldR:" + rb.RigidBody.transform.rotation
                                  + " OriginalRot:" + transform.Rotation
                                  + " keyF:" + rb.RigidBody.isKinematic
                                  + " KF:" + rb.IsKeyframed);
#endif
                    }

                    rb.lastTimeKeyFramedUpdate = timeOfSnapshot;
                    rb.IsKeyframed             = (snapshot.RigidBodies.Values[index].motionType == Patching.Types.MotionType.Keyframed);

                    // code to disable prediction and to use just key framing (and comment out the prediction)
                    //rb.RigidBody.isKinematic = true;
                    //rb.RigidBody.transform.position = keyFramedPos;
                    //rb.RigidBody.transform.rotation = keyFramedOrientation;
                    //rb.RigidBody.velocity.Set(0.0f, 0.0f, 0.0f);
                    //rb.RigidBody.angularVelocity.Set(0.0f, 0.0f, 0.0f);

                    // call the predictor with this remotely owned body
                    _predictor.AddAndProcessRemoteBodyForPrediction(rb, transform,
                                                                    keyFramedPos, keyFramedOrientation, timeOfSnapshot, timeInfo);
                }
            }

            // call the predictor
            _predictor.PredictAllRemoteBodiesWithOwnedBodies(ref _rigidBodies, timeInfo);
        }
Ejemplo n.º 44
0
 public static Vector3 GetWorldPosition(this Bone bone, UnityEngine.Transform spineGameObjectTransform, float positionScale)
 {
     return(spineGameObjectTransform.TransformPoint(new Vector3(bone.worldX * positionScale, bone.worldY * positionScale)));
 }