/// <summary> /// set unity transform from vs vehicle infomation. /// </summary> /// <param name="gameObject"></param> /// <param name="forward"></param> /// <param name="left"></param> /// <param name="up"></param> /// <param name="roll"></param> /// <param name="pitch"></param> /// <param name="yaw"></param> static public void SetUnityTransformFromSolverValues(GameObject gameObject, float forward, float left, float up, float roll, float pitch, float yaw) { gameObject.transform.position = VsUnityLib.VSToUnityVector(forward, left, up); gameObject.transform.rotation = VsUnityLib.VSToUnityRotation(roll, pitch, yaw); }
bool RoadInfoCallback(IntPtr callbackData , double carSimX0 , double carSimY0 , double carSimZ0 , double carSimX1 , double carSimY1 , double carSimZ1 , ref BestMedia.VsDotnet.vs_vehicle.VsRoadInfo out_roadInfo) { bool retSuccess = false; var MovementComponent = VsUtility.ToObject(callbackData) as CarSimMovementComponent; Vector3 StartVect = VsUnityLib.VSToUnityVector(carSimX0, carSimY0, carSimZ0); Vector3 EndVect = VsUnityLib.VSToUnityVector(carSimX1, carSimY1, carSimZ1); Vector3 DirVect = EndVect - StartVect; DirVect.Normalize(); Ray ray = new Ray(StartVect, DirVect); RaycastHit HitResult; bool roadPointFound = Physics.Raycast(ray, out HitResult, (StartVect - EndVect).magnitude, RayLayerMask, QueryTriggerInteraction.Ignore); if (DebugShowRay) { Debug.DrawRay(ray.origin, ray.direction * (StartVect - EndVect).magnitude, Color.red, 0.1f); } if (!roadPointFound) { Check(retSuccess == false); } else { if (HitResult.normal.y == 0) { Check(retSuccess == false); } else { HitResult.point.UnityToVSVector(ref out_roadInfo.mCarSimLocX, ref out_roadInfo.mCarSimLocY, ref out_roadInfo.mCarSimLocZ); double nx = 0, ny = 0, nz = 0; HitResult.normal.UnityToVSVector(ref nx, ref ny, ref nz); out_roadInfo.mCarSimDzDx = nz / nx; out_roadInfo.mCarSimDzDy = nz / ny; if (HitResult.collider != null && HitResult.collider.material != null) { out_roadInfo.mCarSimMu = HitResult.collider.material.dynamicFriction; } else { out_roadInfo.mCarSimMu = 0.85f; } out_roadInfo.mCollisionInfo = IntPtr.Zero; retSuccess = true; } } return(retSuccess); }