コード例 #1
0
ファイル: MgcCont3DMinBox.cpp プロジェクト: OpenXRay/xray
//----------------------------------------------------------------------------
static void MinimalBoxForAngles (int iQuantity, const Vector3* akPoint,
    Real afAngle[3], Box3& rkBox)
{
    Real fCos0 = Math::Cos(afAngle[0]);
    Real fSin0 = Math::Sin(afAngle[0]);
    Real fCos1 = Math::Cos(afAngle[1]);
    Real fSin1 = Math::Sin(afAngle[1]);
    Vector3 kAxis(fCos0*fSin1,fSin0*fSin1,fCos1);
    Matrix3 kRot;
    kRot.FromAxisAngle(kAxis,afAngle[2]);

    Vector3 kMin = akPoint[0]*kRot, kMax = kMin;
    for (int i = 1; i < iQuantity; i++)
    {
        Vector3 kTest = akPoint[i]*kRot;

        if ( kTest.x < kMin.x )
            kMin.x = kTest.x;
        else if ( kTest.x > kMax.x )
            kMax.x = kTest.x;

        if ( kTest.y < kMin.y )
            kMin.y = kTest.y;
        else if ( kTest.y > kMax.y )
            kMax.y = kTest.y;

        if ( kTest.z < kMin.z )
            kMin.z = kTest.z;
        else if ( kTest.z > kMax.z )
            kMax.z = kTest.z;
    }

    Vector3 kMid = 0.5f*(kMax + kMin);
    Vector3 kRng = 0.5f*(kMax - kMin);

    rkBox.Center() = kRot*kMid;
    rkBox.Axis(0) = kRot.GetColumn(0);
    rkBox.Axis(1) = kRot.GetColumn(1);
    rkBox.Axis(2) = kRot.GetColumn(2);
    rkBox.Extent(0) = kRng.x;
    rkBox.Extent(1) = kRng.y;
    rkBox.Extent(2) = kRng.z;
}
コード例 #2
0
ファイル: LuxMaxUtils.cpp プロジェクト: LuxRender/LuxMax
std::string LuxMaxUtils::getMaxNodeTransform(INode* node)
{
	LuxMaxUtils *lmutil;
	std::string tmpTrans = "";
	Matrix3 nodeTransformPos = node->GetObjTMAfterWSM(GetCOREInterface()->GetTime());
	Matrix3 nodeTransformRot = nodeTransformPos;
	Matrix3 nodeTransformScale = nodeTransformPos;

	nodeTransformRot.NoTrans();
	nodeTransformScale.NoTrans();
	nodeTransformScale.NoRot();

	nodeTransformRot = nodeTransformRot * nodeTransformScale;

	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(0).x));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(1).x));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(2).x));
	tmpTrans.append(" ");
	tmpTrans.append("0 ");

	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(0).y));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(1).y));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(2).y));
	tmpTrans.append(" ");
	tmpTrans.append("0 ");

	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(0).z));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(1).z));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformRot.GetColumn(2).z));
	tmpTrans.append(" ");
	tmpTrans.append("0 ");

	tmpTrans.append(floatToString(nodeTransformPos.GetTrans().x));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformPos.GetTrans().y));
	tmpTrans.append(" ");
	tmpTrans.append(floatToString(nodeTransformPos.GetTrans().z));
	tmpTrans.append(" 1.0");

	return tmpTrans;
}
コード例 #3
0
void  ObjectRenderer::Render(){
    if(!bDrawObject) return;

    if(mObject!=NULL){
        glPushMatrix();
        glMultMatrixf(mObject->GetReferenceFrame().GetHMatrix().RowOrderForceFloat());
    }

    if(bDrawRef)
        GLT::DrawRef(mRefSize);

    for(int i=0;i<int(mShapes.size());i++){
        glPushMatrix();
        if(bDrawCom){
            GLT::SetColor(mComColor[0],mComColor[1],mComColor[2],mComColor[3]);
            Matrix ine(3,3);
            Vector d(3);
            Matrix eg(3,3);
            Matrix3 egt;
            Matrix3 degt;
            Matrix  dd(3,3);
            Matrix3 ddd;
            ine = (mObject->GetSpatialInertia().mInertiaMoment);
            ine.EigenValuesDecomposition(d, eg);
            egt.Set(eg);
            egt.STranspose();
            dd.Diag(d);
            ddd.Set(dd);

            egt.Mult(ddd,degt);

            glPushMatrix();
                Vector3 &com = mObject->GetSpatialInertia().mCenterOfMass;
                glTranslatef(com[0],com[1],com[2]);
                GLT::DrawVector(degt.GetColumn(0),0.1);
                GLT::DrawVector(degt.GetColumn(1),0.1);
                GLT::DrawVector(degt.GetColumn(2),0.1);
            glPopMatrix();
        }

        float col[4];
        //bUseDefaultColor is not needed since providing no color tag automatically sets the color to default
//        if(bUseDefaultColor){
//            col[0] = mDefaultColor[0];
//            col[1] = mDefaultColor[1];
//            col[2] = mDefaultColor[2];
//            col[3] = mDefaultColor[3];
//        }else{
            col[0] = mShapes[i]->color[0];
            col[1] = mShapes[i]->color[1];
            col[2] = mShapes[i]->color[2];
            col[3] = mShapes[i]->color[3];
//        }

        if(!bUseTransparency)
            col[3] = 1.0;


        glColor4fv(col);
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,col);

        if(mShapes[i]->culling)
        	glDisable(GL_CULL_FACE);


        if(mShapes[i]->shape){
            mShapes[i]->shape->Render();
        }


        if(mShapes[i]->culling)
        	glEnable(GL_CULL_FACE);

        glPopMatrix();
    }

    if(mObject!=NULL){
        glPopMatrix();
    }

    AbstractRenderer::Render();
}
コード例 #4
0
//---------------------------------------------------------------------------
long FAR PASCAL 
WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static Vector3 s_kEye;
    static QuadricSurface::ConvexPolyhedron s_kPoly;
    static int s_iSteps = 0;
    static Matrix3 s_kRot;
    Matrix3 kIncr;

    switch ( message ) 
    {
    case WM_CREATE:
    {
        CreatePoly(s_kPoly);
        QuadricSurface::TessellateSphere(s_iSteps,s_kPoly);

        // initial camera orientation and eye point
        s_kRot.FromAxisAngle(Vector3::UNIT_Z,0.0f);
        s_kEye = 2.0f*s_kRot.GetColumn(2);

        return 0;
    }
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hDC = BeginPaint(hWnd,&ps);
        DrawPolyhedron(hDC,s_kEye,s_kRot,s_kPoly);
        EndPaint(hWnd,&ps);
        return 0;
    }
    case WM_KEYDOWN:
    {
        switch ( wParam )
        {
        case VK_LEFT:
        {
            // rotate camera about its 'up' vector
            kIncr.FromAxisAngle(s_kRot.GetColumn(1),0.1f);
            s_kRot = kIncr*s_kRot;
            s_kEye = 2.0f*s_kRot.GetColumn(2);
            InvalidateRect(hWnd,NULL,TRUE);
            break;
        }
        case VK_RIGHT:
        {
            // rotate camera about its 'up' vector
            kIncr.FromAxisAngle(s_kRot.GetColumn(1),-0.1f);
            s_kRot = kIncr*s_kRot;
            s_kEye = 2.0f*s_kRot.GetColumn(2);
            InvalidateRect(hWnd,NULL,TRUE);
            break;
        }
        case VK_UP:
        {
            // rotate camera about its 'right' vector
            kIncr.FromAxisAngle(s_kRot.GetColumn(0),-0.1f);
            s_kRot = kIncr*s_kRot;
            s_kEye = 2.0f*s_kRot.GetColumn(2);
            InvalidateRect(hWnd,NULL,TRUE);
            break;
        }
        case VK_DOWN:
        {
            // rotate camera about its 'right' vector
            kIncr.FromAxisAngle(s_kRot.GetColumn(0),0.1f);
            s_kRot = kIncr*s_kRot;
            s_kEye = 2.0f*s_kRot.GetColumn(2);
            InvalidateRect(hWnd,NULL,TRUE);
            break;
        }
        }
        return 0;
    }
    case WM_CHAR:
    {
        switch ( wParam )
        {
            case '+':
            case '=':
            {
                s_iSteps++;
                QuadricSurface::DeletePolyhedron(s_kPoly);
                CreatePoly(s_kPoly);
                QuadricSurface::TessellateSphere(s_iSteps,s_kPoly);
                InvalidateRect(hWnd,NULL,TRUE);
                break;
            }
            case '-':
            case '_':
            {
                if ( s_iSteps >= 1 )
                {
                    s_iSteps--;
                    QuadricSurface::DeletePolyhedron(s_kPoly);
                    CreatePoly(s_kPoly);
                    QuadricSurface::TessellateSphere(s_iSteps,s_kPoly);
                    InvalidateRect(hWnd,NULL,TRUE);
                }
                break;
            }
            case 'q':
            case 'Q':
            case VK_ESCAPE:
            {
                PostMessage(hWnd,WM_DESTROY,0,0);
                break;
            }
        }
        return 0;
    }
    case WM_DESTROY:
    {
        QuadricSurface::DeletePolyhedron(s_kPoly);
        PostQuitMessage(0);
        return 0;
    }
    }
	return DefWindowProc(hWnd,message,wParam,lParam);
}