///------------------------------------------------------------------------ /// /// LOCAL TO PARENT(PARENT, OBJ, rotation, translation) /// /// Rotates and offsets a child object to a parent object. /// The parent object may be child object to rotate or move against itself ///------------------------------------------------------------------------ void LocalToParent(int PARENT, int OBJ, Vector3 rotation, Vector3 translation) { Vector3 parentLocation; Quaternion parentOrientation; Quaternion newOrientation; Quaternion objectOrientation; Vector3 forward, location, newLocation; float x,y,z,ud,lr,fb; x = rotation.x; y = rotation.y; z = rotation.z; fb = translation.z; lr = translation.x; ud = translation.y; iObjectLocation(PARENT, parentLocation); iObjectOrientation(PARENT,parentOrientation); iObjectOrientationSet(OBJ,parentOrientation); iVectorRotate(forward,Vector3(lr,ud,fb),parentOrientation); newLocation = parentLocation + forward; iObjectLocationSet(OBJ,newLocation); iQuaternionFromEulerAngles(newOrientation,x,y,z,"xyz"); iQuaternionMultiply(newOrientation,newOrientation,parentOrientation); iObjectOrientationSet(OBJ,newOrientation); }
///------------------------------------------------------------------------ /// Returns a lookat orientation from vector a to vector b ///------------------------------------------------------------------------ Quaternion QuatGetLookAt(Vector3 a, Vector3 b){ Quaternion orientation; Vector3 up = Vector3(0,1,0); Vector3 direction = b - a; iQuaternionLookAt(orientation,direction,up); return orientation; }
///------------------------------------------------------------------------ /// Returns a direction vector from an orientation ///------------------------------------------------------------------------ Vector3 DirectionVector(Quaternion q) { Vector3 direction; iVectorRotate(direction,Vector3(0,0,1),q); return direction; }
///------------------------------------------------------------------------ /// Returns an orientation from a direction vector ///------------------------------------------------------------------------ Quaternion VectorOrientation(Vector3 v) { Quaternion orientation; Vector3 v1,v2; iVectorLengthSet(v1,v,1); iVectorLengthSet(v2,v,2); orientation = QuatGetLookAt(v1,v2); return orientation; }
///------------------------------------------------------------------------ /// Returns the multiplacation of vector with a scalor ///------------------------------------------------------------------------ Vector3 VectorTimesScalar(Vector3 v1, float value) { Vector3 v; v.x = v1.x * value; v.y = v1.y * value; v.z = v1.z * value; return v; }
скрипт должен быть связан с камерой,авто, скинмешом. Вот так должно получится