// next arguments probably contain redundant info, for later...
void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat, 
										 const MT_Matrix3x3 & camOrientMat3x3,
										 const MT_Point3 & pos,
										 bool perspective)
{
	m_viewmatrix = mat;

	// correction for stereo
	if (Stereo() && perspective)
	{
		MT_Vector3 unitViewDir(0.0, -1.0, 0.0);  // minus y direction, Blender convention
		MT_Vector3 unitViewupVec(0.0, 0.0, 1.0);
		MT_Vector3 viewDir, viewupVec;
		MT_Vector3 eyeline;

		// actual viewDir
		viewDir = camOrientMat3x3 * unitViewDir;  // this is the moto convention, vector on right hand side
		// actual viewup vec
		viewupVec = camOrientMat3x3 * unitViewupVec;

		// vector between eyes
		eyeline = viewDir.cross(viewupVec);

		switch (m_curreye) {
			case RAS_STEREO_LEFTEYE:
				{
				// translate to left by half the eye distance
				MT_Transform transform;
				transform.setIdentity();
				transform.translate(-(eyeline * m_eyeseparation / 2.0));
				m_viewmatrix *= transform;
				}
				break;
			case RAS_STEREO_RIGHTEYE:
				{
				// translate to right by half the eye distance
				MT_Transform transform;
				transform.setIdentity();
				transform.translate(eyeline * m_eyeseparation / 2.0);
				m_viewmatrix *= transform;
				}
				break;
		}
	}

	m_viewinvmatrix = m_viewmatrix;
	m_viewinvmatrix.invert();

	// note: getValue gives back column major as needed by OpenGL
	MT_Scalar glviewmat[16];
	m_viewmatrix.getValue(glviewmat);

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixd(glviewmat);
	m_campos = pos;
}
示例#2
0
/**
 *	Transforms the collision object. A cone is not correctly centered
 *	for usage.  */
void KX_RadarSensor::SynchronizeTransform()
{
    // Getting the parent location was commented out. Why?
    MT_Transform trans;
    trans.setOrigin(((KX_GameObject*)GetParent())->NodeGetWorldPosition());
    trans.setBasis(((KX_GameObject*)GetParent())->NodeGetWorldOrientation());
    // What is the default orientation? pointing in the -y direction?
    // is the geometry correctly converted?

    // a collision cone is oriented
    // center the cone correctly
    // depends on the radar 'axis'
    switch (m_axis)
    {
    case SENS_RADAR_X_AXIS: // +X Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_Y_AXIS: // +Y Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_Z_AXIS: // +Z Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_X_AXIS: // -X Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(-90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_Y_AXIS: // -Y Axis
    {
        //MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
        //trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_Z_AXIS: // -Z Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    default:
    {
    }
    }

    //Using a temp variable to translate MT_Point3 to float[3].
    //float[3] works better for the Python interface.
    MT_Point3 temp = trans.getOrigin();
    m_cone_origin[0] = temp[0];
    m_cone_origin[1] = temp[1];
    m_cone_origin[2] = temp[2];

    temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0));
    m_cone_target[0] = temp[0];
    m_cone_target[1] = temp[1];
    m_cone_target[2] = temp[2];


    if (m_physCtrl)
    {
        PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
        const MT_Point3& pos = trans.getOrigin();
        float ori[12];
        trans.getBasis().getValue(ori);
        motionState->setWorldPosition(pos[0], pos[1], pos[2]);
        motionState->setWorldOrientation(ori);
        m_physCtrl->WriteMotionStateToDynamics(true);
    }

}