int GLWidget::setCenter(){ if(!isCenChanged){ return(0); } isCenChanged = false; isFocusChanged = true; curCen.x = BOXSIZE/2.0; curCen.y = BOXSIZE/2.0; curCen.z = BOXSIZE/2.0; float d[3]; d[0] = curCen.x-lastCen.x; d[1] = curCen.y-lastCen.y; d[2] = curCen.z-lastCen.z; lastCen.x = curCen.x; lastCen.y = curCen.y; lastCen.z = curCen.z; yRotation(lastRotY, d); xRotation(lastRotX, d); curFocus.x = lastFocus.x+d[0]; curFocus.y = lastFocus.y+d[1]; curFocus.z = lastFocus.z+d[2]; lastFocus.x = curFocus.x; lastFocus.y = curFocus.y; lastFocus.z = curFocus.z; return(0); }
void Camera::Rotate(const float xAmount, const float yAmount, const float zAmount) { quat xRotation(DegToRad(xAmount), m_right.x, m_right.y, m_right.z); quat yRotation(DegToRad(yAmount), m_up.x, m_up.y, m_up.z); quat zRotation(DegToRad(zAmount), m_facing.x, m_facing.y, m_facing.z); quat rotation = xRotation * yRotation * zRotation; m_right = normalize(rotation * m_right); m_up = normalize(rotation * m_up); m_facing = normalize(rotation * m_facing); }
void GraphicRootTracker::evaluate() { if (!IsConnected()) return; double alpha = gc::Pi - GetAzimuth(); SbVec3f yAxis( 0.0, 1.0, 0.0 ); SbRotation yRotation( yAxis, alpha ); SbVec3f xAxis( 1.0, 0.0, 0.0 ); SbRotation xRotation( xAxis, GetZenith() ); SbRotation rotation = xRotation * yRotation; SetEngineOutputRotation(rotation); }
Matrix3 Matrix3::rotation(float x, float y, float z) { Matrix3 xRotation( 1, 0, 0, 0, cos(x), sin(x), 0, -sin(x), cos(x)); Matrix3 yRotation( cos(y), 0, -sin(y), 0, 1, 0, sin(y), 0, cos(y)); Matrix3 zRotation( cos(z), sin(z), 0, -sin(z), cos(z), 0, 0, 0, 1); return xRotation * yRotation * zRotation; }
void TSceneTracker::evaluate() { if (!IsConnected()) return; SetAnglesToScene(); double alpha = gc::Pi - GetAzimuth(); SbVec3f yAxis( 0.0, 1.0, 0.0 ); SbRotation yRotation( yAxis, -alpha ); SbVec3f xAxis( 1.0, 0.0, 0.0 ); SbRotation xRotation( xAxis, -GetZenith() ); SbRotation rotation = yRotation * xRotation; SetEngineOutputRotation(rotation); }
void Camera::RotateAroundPoint(const float xAmount, const float yAmount, const float zAmount) { quat xRotation(DegToRad(xAmount), m_right.x, m_right.y, m_right.z); quat yRotation(DegToRad(yAmount), m_up.x, m_up.y, m_up.z); quat zRotation(DegToRad(zAmount), m_facing.x, m_facing.y, m_facing.z); quat rotation = xRotation * yRotation * zRotation; // Get the view position, based on the facing and the zoom amount vec3 view = m_position + (m_facing*m_zoomAmount); m_position -= view; // Translate the position to the origin, relative to the view position (that is the facing zoomed) m_position = (rotation * m_position); m_position += view; // Translate back to relative view position m_right = normalize(rotation * m_right); m_facing = normalize(rotation * m_facing); m_up = normalize(rotation * m_up); }
Matrix4 Matrix4::rotation(float x, float y, float z) { Matrix4 xRotation( 1, 0, 0, 0, 0, cos(x), sin(x), 0, 0, -sin(x), cos(x), 0, 0, 0, 0, 1); Matrix4 yRotation( cos(y), 0, -sin(y), 0, 0, 1, 0, 0, sin(y), 0, cos(y), 0, 0, 0, 0, 1); Matrix4 zRotation( cos(z), sin(z), 0, 0, -sin(z), cos(z), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); return xRotation * yRotation * zRotation; }
void Player::MouseMove(int x, int y) { double deltaX = -(x - _resolution.x / 2) / _resolution.x * PI * 4; double deltaY = -(y - _resolution.y / 2) / _resolution.y * PI; Mat3 xRotation(cos(deltaX), -sin(deltaX), 0, sin(deltaX), cos(deltaX), 0, 0, 0, 1); _lookat = xRotation * Vec3(-1, -1, 0); _lookat.normalize(); Vec3 rn = Vec3(0, 0, 1).cross(_lookat); //rotate axis Mat3 yRotation(rn.x*rn.x*(1 - cos(deltaY)) + cos(deltaY), rn.x*rn.y*(1 - cos(deltaY)) + rn.z*sin(deltaY), rn.x*rn.z*(1 - cos(deltaY)) - rn.y*sin(deltaY), rn.x*rn.y*(1 - cos(deltaY)) - rn.z*sin(deltaY), rn.y*rn.y*(1 - cos(deltaY)) + cos(deltaY), rn.y*rn.z*(1 - cos(deltaY)) + rn.x*sin(deltaY), rn.x*rn.z*(1 - cos(deltaY)) + rn.y*sin(deltaY), rn.y*rn.z*(1 - cos(deltaY)) - rn.x*sin(deltaY), rn.z*rn.z*(1 - cos(deltaY)) + cos(deltaY)); _lookat = yRotation * _lookat; _lookat.normalize(); _lookChanged = true; }
int GLWidget::setFocus(){ if(!(isFocusChanged)){ return(0); } isFocusChanged = false; isCenChanged = true; curFocus.x = lookAt.x; curFocus.y = lookAt.y; curFocus.z = lookAt.z-0.1; float d[3]; d[0] = curFocus.x-lastFocus.x; d[1] = curFocus.y-lastFocus.y; d[2] = curFocus.z-lastFocus.z; lastFocus.x = curFocus.x; lastFocus.y = curFocus.y; lastFocus.z = curFocus.z; xRotation(-lastRotX, d); yRotation(-lastRotY, d); // zRotation(-lastRotZ, d); curCen.x = lastCen.x+d[0]; curCen.y = lastCen.y+d[1]; curCen.z = lastCen.z+d[2]; lastCen.x = curCen.x; lastCen.y = curCen.y; lastCen.z = curCen.z; return(0); }
//============================================================= // rpyRotation //============================================================= Transform rpyRotation(double roll, double pitch, double yaw) { Transform rpyRotation; rpyRotation = (zRotation(roll) * yRotation(pitch)) * xRotation(yaw); return rpyRotation; }