void Camera::Init() { Vector3f HTarget(m_target.x, 0.0, m_target.z); HTarget.Normalize(); if (HTarget.z >= 0.0f) { if (HTarget.x >= 0.0f) { m_AngleH = 360.0f - ToDegree(asin(HTarget.z)); } else { m_AngleH = 180.0f + ToDegree(asin(HTarget.z)); } } else { if (HTarget.x >= 0.0f) { m_AngleH = ToDegree(asin(-HTarget.z)); } else { m_AngleH = 90.0f + ToDegree(asin(-HTarget.z)); } } m_AngleV = -ToDegree(asin(m_target.y)); m_mousePos.x = m_windowWidth / 2; m_mousePos.y = m_windowHeight / 2; glutWarpPointer(m_mousePos.x, m_mousePos.y); }
void Camera::Init() { Vector3f HTarget(m_target.x, 0.f, m_target.z); HTarget.Normalize(); if (HTarget.z >= 0.f) { if (HTarget.x >= 0.f) { m_AngleH = 360.f - ToDegree(asin(HTarget.z)); } else { m_AngleH = 180.f + ToDegree(asin(HTarget.z)); } } else { if (HTarget.x >= 0.f) { m_AngleH = ToDegree(asin(-HTarget.z)); } else { m_AngleH = 90.f + ToDegree(asin(-HTarget.z)); } } m_AngleV = -ToDegree(asin(m_target.y)); m_onUpperEdge = false; m_onLowerEdge = false; m_onRightEdge = false; m_onLeftEdge = false; }
Vector3f Quaternion::ToDegrees() const { float f[3]; f[0] = atan2(x * z + y * w, x * w - y * z); f[1] = acos(-x * x - y * y - z * z - w * w); f[2] = atan2(x * z - y * w, x * w + y * z); f[0] = ToDegree(f[0]); f[1] = ToDegree(f[1]); f[2] = ToDegree(f[2]); return Vector3f(f); }
float FindAngle(const Vector3 &v1, const Vector3 &v2) { // *********************************************** // Angle through DotProduct // ----------------------------------------------- // /- -\ // | a . b | // theta = acos| ------- | // | |a|*|b| | // \- -/ // ----------------------------------------------- // Where: // T = theta. // a = a vector. // |a|= magnitude of a vector. // b = b vector // |b|= magnitude of b vector // *********************************************** float theta = 0.0f; Vector3 a(v1); Vector3 b(v2); a.Normalise(); b.Normalise(); theta = acos((float)Vector3::DOT(a, b)); return ToDegree(theta); }
ZTaskResult ZTask_RotateToDir::OnRun(float fDelta) { rvector dir = m_TargetDir; if (!m_bRotated) { rmatrix mat; rvector vBodyDir = m_pParent->GetDirection(); float fAngle=GetAngleOfVectors(dir, vBodyDir); float fRotAngle = m_pParent->GetNPCInfo()->fRotateSpeed * (fDelta / 1.0f); if (fAngle > 0.0f) fRotAngle = -fRotAngle; if (fabs(fRotAngle) > fabs(fAngle)) { fRotAngle = -fAngle; m_bRotated = true; return ZTR_COMPLETED; } mat = RGetRotZ(ToDegree(fRotAngle)); m_pParent->RotateTo(vBodyDir * mat); } else { return ZTR_COMPLETED; } return ZTR_RUNNING; }
// initializes internal class data void Camera::init() { // create horizontal target vector + normalize it vec3D HTarget(m_target.x, 0.0, m_target.z); HTarget.normalize(); // check to see if z is positive or negative, then calculate horizontal vectors based on target vec if (HTarget.z >= 0.0f) { if (HTarget.x >= 0.0f) m_AngleH = 360.0f - ToDegree(asin(HTarget.z)); else m_AngleH = 180.0f + ToDegree(asin(HTarget.z)); } else { if (HTarget.x >= 0.0f) m_AngleH = ToDegree(asin(-HTarget.z)); else m_AngleH = 90.0f + ToDegree(asin(-HTarget.z)); } // do the same with vertical angle m_AngleV = -ToDegree(asin(m_target.y)); // init constants m_OnUpperEdge = false; m_OnLowerEdge = false; m_OnLeftEdge = false; m_OnRightEdge = false; keys[0] = false; keys[1] = false; keys[2] = false; keys[3] = false; m_mousePos.x = m_windowWidth / 2; m_mousePos.y = m_windowHeight / 2; //starts mouse in centre of the screen //glutWarpPointer(m_mousePos.x, m_mousePos.y); //SetCursorPos(m_mousePos.x,m_mousePos.y); glutWarpPointer(m_mousePos.x, m_mousePos.y); glutSetCursor(GLUT_CURSOR_NONE); }
//----------------------------------------------------------------------- Frustum::Frustum(Vector3f pos,Vector3f target,Vector3f up): m_positionVector(pos), m_targetVector(target), m_upVector(up), m_FOVy(45.0f), m_nearDist(1), m_farDist(10000), m_aspectRadio(1.333333333f), m_viewChanged(true), m_projChanged(true), m_frustumPlanesChanged(true) { m_targetVector.Normalize(); m_upVector.Normalize(); //Initialize two angles Vector3f targetVector(m_targetVector.x, 0.0f, m_targetVector.z);//horizontal target targetVector.Normalize(); if(targetVector.z >= 0.0f) { if(targetVector.x >= 0.0f) { m_angleHorizontal = 360.0f - ToDegree(asin(targetVector.z)); } else { m_angleHorizontal = 180.0f + ToDegree(asin(targetVector.z)); } } else { if(targetVector.x >= 0.0f) { m_angleHorizontal = ToDegree(asin(-targetVector.z)); }else { m_angleHorizontal = 90.0f + ToDegree(asin(-targetVector.z)); } } m_angleVertical = -ToDegree(asin(m_targetVector.y)); }
void Camera::Init() { Vector3f HTarget(m_target.x, 0.0, m_target.z); HTarget.Normalize(); if (HTarget.z >= 0.0f) { if (HTarget.x >= 0.0f) { m_AngleH = 360.0f - ToDegree(asin(HTarget.z)); } else { m_AngleH = 180.0f + ToDegree(asin(HTarget.z)); } } else { if (HTarget.x >= 0.0f) { m_AngleH = ToDegree(asin(-HTarget.z)); } else { m_AngleH = 90.0f + ToDegree(asin(-HTarget.z)); } } m_AngleV = -ToDegree(asin(m_target.y)); m_OnUpperEdge = false; m_OnLowerEdge = false; m_OnLeftEdge = false; m_OnRightEdge = false; m_mousePos.x = m_windowWidth / 2; m_mousePos.y = m_windowHeight / 2; SDL_WarpMouseInWindow(m_window, m_mousePos.x, m_mousePos.y); }