예제 #1
0
//----------------------------------------
void ofNode::lookAt(const glm::vec3& lookAtPosition){
    auto relPosition = (getGlobalPosition() - lookAtPosition);
	auto radius = glm::length(relPosition);
    if(radius>0){
		float latitude = acos(relPosition.y / radius) - glm::half_pi<float>();
		float longitude = atan2(relPosition.x , relPosition.z);
		glm::quat q = glm::angleAxis(latitude, glm::vec3(1,0,0)) * glm::angleAxis(longitude, glm::vec3(0,1,0)) * glm::angleAxis(0.f, glm::vec3(0,0,1));
        setGlobalOrientation(q);
    }

}
예제 #2
0
//----------------------------------------
void ofNode::lookAt(const ofVec3f& lookAtPosition){
    auto relPosition = (getGlobalPosition() - lookAtPosition);
    auto radius = relPosition.length();
    if(radius>0){
        auto latitude = ofRadToDeg(acos(relPosition.y / radius)) - 90;
        auto longitude = ofRadToDeg(atan2(relPosition.x , relPosition.z));
        ofQuaternion q(latitude, ofVec3f(1,0,0), longitude, ofVec3f(0,1,0), 0, ofVec3f(0,0,1));
        setGlobalOrientation(q);
    }

}
예제 #3
0
//----------------------------------------
void ofNode::lookAt(const ofVec3f& lookAtPosition, ofVec3f upVector) {
	if(parent) upVector = upVector * ofMatrix4x4::getInverseOf(parent->getGlobalTransformMatrix());
	ofVec3f zaxis = (getGlobalPosition() - lookAtPosition).normalized();
	ofVec3f xaxis = upVector.getCrossed(zaxis).normalized();
	ofVec3f yaxis = zaxis.getCrossed(xaxis);
	
	ofMatrix4x4 m;
	m._mat[0].set(xaxis.x, xaxis.y, xaxis.z, 0);
	m._mat[1].set(yaxis.x, yaxis.y, yaxis.z, 0);
	m._mat[2].set(zaxis.x, zaxis.y, zaxis.z, 0);
	
	setGlobalOrientation(m.getRotate());
}
예제 #4
0
//----------------------------------------
void ofNode::lookAt(const glm::vec3& lookAtPosition, glm::vec3 upVector) {
	if(parent){
		auto upVector4 = glm::inverse(parent->getGlobalTransformMatrix()) * glm::vec4(upVector, 1.0);
		upVector = upVector4.xyz() / upVector4.w;
	}
	auto zaxis = glm::normalize(getGlobalPosition() - lookAtPosition);
	if (glm::length(zaxis) > 0) {
		auto xaxis = glm::normalize(glm::cross(upVector, zaxis));
		auto yaxis = glm::cross(zaxis, xaxis);
		glm::mat4 m;
		m[0] = glm::vec4(xaxis, 0.f);
		m[1] = glm::vec4(yaxis, 0.f);
		m[2] = glm::vec4(zaxis, 0.f);

		setGlobalOrientation(glm::toQuat(m));
	}
}
	void GameBodyObject::simulate(float dT)
	{
		// Check if the scene node has been changed, other than by the physics system,
		// and update the physics transforms accordingly
		if (mNode != NULL)
		{
			if (prevGlobalPosition != mNode->_getDerivedPosition())
			{
				setGlobalPosition(mNode->_getDerivedPosition());
			}
			if (prevGlobalOrientation != mNode->_getDerivedOrientation())
			{
				setGlobalOrientation(mNode->_getDerivedOrientation());
			}
		}
		shapeSimulate(dT);
	}