void arc_ball_camera::update(float deltaTime)
{
	glm::mat4 mat = glm::eulerAngleYX(_rotY, _rotX);
	glm::vec4 translation(0.0f, 0.0f, _distance, 1.0f);
	translation = mat * translation; 
	_position = _target + glm::vec3(translation.x, translation.y, translation.z);
	glm::vec4 tempUp(0.0f, 1.0f, 0.0f, 1.0f);
	tempUp = mat * tempUp;
	_up = glm::vec3(tempUp.x, tempUp.y, tempUp.z);
	_view = glm::lookAt(_position, _target, _up);
}
Пример #2
0
void PlaneData::findOrientation(cv::Point3f a, cv::Point3f b, cv::Point3f c)
{
	cv::Vec3f f1 = cv::Vec3f(b.x - a.x, b.y - a.y, b.z - a.z);
	cv::Vec3f f2 = cv::Vec3f(c.x - a.x, c.y - a.y, c.z - a.z);
	normal = f1.cross(f2);
	//std::cout << "f1:" << f1 << " f2:" << f2 << " no:" << normal << "\n";
	if (normal[1] < 0) normal = -normal;
	normal = cv::normalize(normal);
	cv::Vec3f tempUp(0, 0, 1);
	tempUp = normal.cross(tempUp);
	up = normal.cross(tempUp);
	up = cv::normalize(up);
	//std::cout << "tp:" << tempUp << " up:" << up << " no:" << normal << "\n";
}
void first_person_camera::update(float deltaTime)
{
	glm::mat4 mat = glm::mat4_cast(_rotation);
	glm::vec4 vec(_translation, 1.0f);
	vec = mat * vec;
	_translation = glm::vec3(vec.x, vec.y, vec.z);
	_position += _translation;
	_translation = glm::vec3 (0.0f, 0.0f, 0.0f);

	glm::vec4 forward(0.0f, 0.0f, 1.0f, 1.0f);
	forward = mat * forward;
	_target = _position + glm::vec3(forward.x, forward.y, forward.z);

	glm::vec4 tempUp(0.0f, 1.0f, .0f, 1.0f);
	tempUp = mat * tempUp;
	_up = glm::vec3(tempUp.x, tempUp.y, tempUp.z);

	_view = glm::lookAt(_position, _target, _up);
}
Пример #4
0
	inline Matrix4<T_ObjType>& ConstructRotationMatrixFromDirectionalVector( Matrix4<T_ObjType>& outMatrix, const Vector3<T_ObjType>& direction)
	{
		Vector3<T_ObjType> tempUp( 0, 1, 0);
		Vector3<T_ObjType> directiontemp(direction);
		directiontemp.Normalize();
		Vector3<T_ObjType> right(directiontemp.CrossProduct(tempUp));
		right.Normalize();
		Vector3<T_ObjType> up(right.CrossProduct(directiontemp));
		
		memset(outMatrix.m_Matrix, 0, 16 * static_cast<int>( sizeof(T_ObjType) ) );
		outMatrix[0]  = right.x;
		outMatrix[4]  = right.y;
		outMatrix[8]  = right.z;
		outMatrix[2]  = directiontemp.x;
		outMatrix[6]  = directiontemp.y;
		outMatrix[10]  = directiontemp.z;
		outMatrix[1]  = up.x;
		outMatrix[5]  = up.y;
		outMatrix[9] = up.z;
		outMatrix[15] = 1;

		return outMatrix;
	}