Exemple #1
0
void CGizmoTransformMove::Draw()
{
    ComputeScreenFactor();

    Initialize();
    if (m_pMatrix)
    {

        //glDisable(GL_DEPTH_TEST);
        tvector3 orig = GetTranslation();

        tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);


        if (mLocation == LOCATE_LOCAL)
        {
            axeX.TransformVector(*m_pMatrix);
            axeY.TransformVector(*m_pMatrix);
            axeZ.TransformVector(*m_pMatrix);
            axeX.Normalize();
            axeY.Normalize();
            axeZ.Normalize();
        }




        DrawQuad(orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XZ), axeX, axeZ);
        DrawQuad(orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XY), axeX, axeY);
        DrawQuad(orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_YZ), axeY, axeZ);

        axeX*=GetScreenFactor();
        axeY*=GetScreenFactor();
        axeZ*=GetScreenFactor();

        static const tvector3 selectedColor(0xff / 255.0, 0xdc / 255.0, 0),
                unitXColor(1, 0x41 / 255.0, 0x36 / 255.0),
                unitYColor(0x2e / 255.0, 0xcc / 255.0, 0x40 / 255.0),
                unitZColor(0, 0x74 / 255.0, 0xd9 / 255.0);

        // plan1
        if (m_MoveTypePredict != MOVE_X) DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,unitXColor);
            else DrawAxis(orig,axeX,axeY,axeZ, 0.05f,0.83f,selectedColor);

        //plan2
        if (m_MoveTypePredict != MOVE_Y) DrawAxis(orig,axeY,axeX,axeZ, 0.05f,0.83f,unitYColor);
            else DrawAxis(orig,axeY,axeX,axeZ, 0.05f,0.83f,selectedColor);

        //plan3
        if (m_MoveTypePredict != MOVE_Z) DrawAxis(orig,axeZ,axeX,axeY, 0.05f,0.83f,unitZColor);
            else DrawAxis(orig,axeZ,axeX,axeY, 0.05f,0.83f,selectedColor);
    }
}
void CGizmoTransformScale::Draw()
{
  if (m_pMatrix)
  {
    ComputeScreenFactor();


    tvector3 orig(m_pMatrix->m16[12],m_pMatrix->m16[13],m_pMatrix->m16[14]);


    // axis
    tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);
    if (mLocation == LOCATE_LOCAL)
    {
      axeX.TransformVector(*m_pMatrix);
      axeY.TransformVector(*m_pMatrix);
      axeZ.TransformVector(*m_pMatrix);
      axeX.Normalize();
      axeY.Normalize();
      axeZ.Normalize();
    }

    DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeZ);
    DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XY)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeY);
    DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_YZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeY, axeZ);

    axeX*=GetScreenFactor();
    axeY*=GetScreenFactor();
    axeZ*=GetScreenFactor();


    // plan1
    if (m_ScaleTypePredict != SCALE_X)
      DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1));
    else
      DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,1,1,1));

    //plan2
    if (m_ScaleTypePredict != SCALE_Y)
      DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(0,1,0,1));
    else
      DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(1,1,1,1));

    //plan3
    if (m_ScaleTypePredict != SCALE_Z)
      DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(0,0,1,1));
    else
      DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(1,1,1,1));
  }


}
void CGizmoTransformMove::Draw()
{
  ComputeScreenFactor();

  if (m_pMatrix)
  {

    //glDisable(GL_DEPTH_TEST);
    tvector3 orig = m_pMatrix->GetTranslation();

    tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);


    if (mLocation == LOCATE_LOCAL)
    {
      axeX.TransformVector(*m_pMatrix);
      axeY.TransformVector(*m_pMatrix);
      axeZ.TransformVector(*m_pMatrix);
      axeX.Normalize();
      axeY.Normalize();
      axeZ.Normalize();
    }

    DrawQuad(orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XZ), axeX, axeZ);
    DrawQuad(orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XY), axeX, axeY);
    DrawQuad(orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_YZ), axeY, axeZ);

    axeX*=GetScreenFactor();
    axeY*=GetScreenFactor();
    axeZ*=GetScreenFactor();

    // plan1
    if (m_MoveTypePredict != MOVE_X) DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1));
    else DrawAxis(orig,axeX,axeY,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

    //plan2
    if (m_MoveTypePredict != MOVE_Y) DrawAxis(orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(0,1,0,1));
    else DrawAxis(orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

    //plan3
    if (m_MoveTypePredict != MOVE_Z) DrawAxis(orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(0,0,1,1));
    else DrawAxis(orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(1,1,1,1));
  }
}
void CGizmoTransformMove::Draw()
{
	ComputeScreenFactor();

	if (m_pMatrix)
	{
		CRenderingContext c(Manipulator()->GetRenderer(), true);
		c.UseProgram("model");
		c.SetUniform("bDiffuse", false);

		//glDisable(GL_DEPTH_TEST);
		tvector3 orig = m_pMatrix->GetTranslation();

		tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);


        if (mLocation == LOCATE_LOCAL)
        {
            axeX.TransformVector(*m_pMatrix);
		    axeY.TransformVector(*m_pMatrix);
		    axeZ.TransformVector(*m_pMatrix);
		    axeX.Normalize();
		    axeY.Normalize();
		    axeZ.Normalize();
        }




		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XZ), axeX, axeZ);
		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_XY), axeX, axeY);
		DrawQuad(&c, orig, 0.5f*GetScreenFactor(), (m_MoveTypePredict == MOVE_YZ), axeY, axeZ);

		axeX*=GetScreenFactor();
		axeY*=GetScreenFactor();
		axeZ*=GetScreenFactor();

		// plan1
		if (m_MoveTypePredict != MOVE_X)
			DrawAxis(&c, orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1));
		else
			DrawAxis(&c, orig,axeX,axeY,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

		//plan2
		if (m_MoveTypePredict != MOVE_Y)
			DrawAxis(&c, orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(0,1,0,1));
		else
			DrawAxis(&c, orig,axeY,axeX,axeZ, 0.05f,0.83f,vector4(1,1,1,1));

		//plan3
		if (m_MoveTypePredict != MOVE_Z)
			DrawAxis(&c, orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(0,0,1,1));
		else
			DrawAxis(&c, orig,axeZ,axeX,axeY, 0.05f,0.83f,vector4(1,1,1,1));
#if 0
#ifdef WIN32
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    GDD->GetD3D9Device()->SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE );
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ZENABLE , D3DZB_TRUE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHATESTENABLE , FALSE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);
#endif
	extern RenderingState_t GRenderingState;
	GRenderingState.mAlphaTestEnable = 0;
	GRenderingState.mZWriteEnable = 1;
	GRenderingState.mBlending = 0;
	GRenderingState.mCulling = 0;
	GRenderingState.mZTestType = 1;
#endif
/*

PSM_LVERTEX svVts[2];
	svVts[0].x = ptd.x;
    svVts[0].y = ptd.y;
    svVts[0].z = ptd.z;
    svVts[0].diffuse = 0xFFFFFFFF;

	svVts[1].x = ptd.x+10;
    svVts[1].y = ptd.y+10;
    svVts[1].z = ptd.z+10;
    svVts[1].diffuse = 0xFFFFFFFF;


    IDirect3DDevice9 *pDev = ((PSM_D3D9RenderDevice*)PSM_D3D9RenderDevice::GetInterfacePtr())->d3dDevice;
	pDev->DrawPrimitiveUP(D3DPT_LINESTRIP , 1, svVts, sizeof(PSM_LVERTEX));
    */
}
/*
		// debug
		glPointSize(20);
		glBegin(GL_POINTS);
		glVertex3fv(&ptd.x);
		glEnd();

		glEnable(GL_DEPTH_TEST);
*/

}
void CGizmoTransformScale::Draw()
{
	if (m_pMatrix)
	{
		ComputeScreenFactor();

		//glDisable(GL_DEPTH_TEST);
		tvector3 orig(m_pMatrix->m16[12],m_pMatrix->m16[13],m_pMatrix->m16[14]);


		// axis
		tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);
        if (mLocation == LOCATE_LOCAL)
        {
            axeX.TransformVector(*m_pMatrix);
		    axeY.TransformVector(*m_pMatrix);
		    axeZ.TransformVector(*m_pMatrix);
		    axeX.Normalize();
		    axeY.Normalize();
		    axeZ.Normalize();
        }

		DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeZ);
		DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_XY)||(m_ScaleTypePredict==SCALE_XYZ)), axeX, axeY);
		DrawTri(orig, 0.5f*GetScreenFactor(),((m_ScaleTypePredict==SCALE_YZ)||(m_ScaleTypePredict==SCALE_XYZ)), axeY, axeZ);

		axeX*=GetScreenFactor();
		axeY*=GetScreenFactor();
		axeZ*=GetScreenFactor();


		// plan1
		if (m_ScaleTypePredict != SCALE_X)
			DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,0,0,1));
		else
			DrawAxis(orig,axeX,axeY,axeZ,0.05f,0.83f,vector4(1,1,1,1));

		//plan2
		if (m_ScaleTypePredict != SCALE_Y)
			DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(0,1,0,1));
		else
			DrawAxis(orig,axeY,axeX,axeZ,0.05f,0.83f,vector4(1,1,1,1));

		//plan3
		if (m_ScaleTypePredict != SCALE_Z)
			DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(0,0,1,1));
		else
			DrawAxis(orig,axeZ,axeX,axeY,0.05f,0.83f,vector4(1,1,1,1));

/*
		// debug
		glPointSize(20);
		glBegin(GL_POINTS);
		glVertex3fv(&ptd.x);
		glEnd();

		glEnable(GL_DEPTH_TEST);
        */
#if 0
#ifdef WIN32
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    GDD->GetD3D9Device()->SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE );
    GDD->GetD3D9Device()->SetRenderState(D3DRS_ZENABLE , D3DZB_TRUE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHATESTENABLE , FALSE);
	GDD->GetD3D9Device()->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);
#endif
	extern RenderingState_t GRenderingState;
	GRenderingState.mAlphaTestEnable = 0;
	GRenderingState.mZWriteEnable = 1;
	GRenderingState.mBlending = 0;
	GRenderingState.mCulling = 0;
	GRenderingState.mZTestType = 1;
#endif
	}


}
/*
            char tmps[512];
            sprintf(tmps, "%5.2f %5.2f %5.2f %5.2f", plCam.x, plCam.y, plCam.z, plCam.w );
            MessageBoxA(NULL, tmps, tmps, MB_OK);
            */
void CGizmoTransformRotate::Draw()
{
    if (m_pMatrix)
    {

        ComputeScreenFactor();

        tvector3 right,up,frnt,dir;

        //glDisable(GL_DEPTH_TEST);
        tvector3 orig(m_pMatrix->GetTranslation());
        
        tvector3 plnorm(m_CamSrc-orig);
            

        plnorm.Normalize();





        tplane plCam = vector4(plnorm,0);


        dir = orig-m_CamSrc;
        dir.Normalize();

        right.Cross(dir,GetTransformedVector(1));
        right.Normalize();

        up.Cross(dir,right);
        up.Normalize();

        right.Cross(dir,up);
        right.Normalize();

        tvector3 axeX(1,0,0),axeY(0,1,0),axeZ(0,0,1);


        if (mLocation == LOCATE_LOCAL)
        {
            axeX.TransformVector(*m_pMatrix);
            axeY.TransformVector(*m_pMatrix);
            axeZ.TransformVector(*m_pMatrix);
            axeX.Normalize();
            axeY.Normalize();
            axeZ.Normalize();
        }

        // Twin
        if (mMask&AXIS_TRACKBALL)
        {

            if (m_RotateTypePredict != ROTATE_TWIN)
                DrawCircle(orig, 0.2f,0.2f,0.2f,right*GetScreenFactor(),up*GetScreenFactor());
            else
                DrawCircle(orig, 1,1,1,right*GetScreenFactor(),up*GetScreenFactor());
        }

        // Screen
        if (mMask&AXIS_SCREEN)
        {
            if (m_RotateTypePredict != ROTATE_SCREEN)
                DrawCircle(orig, 1.0f,0.3f,1.0f,up*1.2f*GetScreenFactor(),right*1.2f*GetScreenFactor());
            else
                DrawCircle(orig, 1,1,1,up*1.2f*GetScreenFactor(),right*1.2f*GetScreenFactor());
        }

        // X
        right.Cross(dir, axeX);
        right.Normalize();
        frnt.Cross(right, axeX);

        frnt.Normalize();

        if (mMask&AXIS_X)
        {
            if (m_RotateTypePredict != ROTATE_X)
                DrawCircleHalf(orig, 1,0,0,right*GetScreenFactor(),frnt*GetScreenFactor(),plCam);
            else
                DrawCircleHalf(orig, 1,1,1,right*GetScreenFactor(),frnt*GetScreenFactor(),plCam);
        }

        // Y

        right.Cross(dir, axeY);
        right.Normalize();
        frnt.Cross(right, axeY);

        frnt.Normalize();

        if (mMask&AXIS_Y)
        {

            if (m_RotateTypePredict != ROTATE_Y)
                DrawCircleHalf(orig, 0,1,0,right*GetScreenFactor(),frnt*GetScreenFactor(),plCam);
            else
                DrawCircleHalf(orig, 1,1,1,right*GetScreenFactor(),frnt*GetScreenFactor(),plCam);
        }

        // Z
        right.Cross(dir, axeZ);
        right.Normalize();
        frnt.Cross(right, axeZ);

        frnt.Normalize();

        if (mMask&AXIS_Z)
        {
            if (m_RotateTypePredict != ROTATE_Z)
                DrawCircleHalf(orig, 0,0,1,right*GetScreenFactor(),frnt*GetScreenFactor(),plCam);
            else
                DrawCircleHalf(orig, 1,1,1,right*GetScreenFactor(),frnt*GetScreenFactor(),plCam);
        }
        // camembert
        if ( (m_RotateType != ROTATE_NONE) && (m_RotateType != ROTATE_TWIN ) )
            DrawCamem(orig,m_Vtx*GetScreenFactor(),m_Vty*GetScreenFactor(),-m_Ng2);
        /*
        // debug
        glPointSize(20);
        glBegin(GL_POINTS);
        glVertex3fv(&ptd.x);
        glEnd();

        glEnable(GL_DEPTH_TEST);
        */
#if 0
#ifdef WIN32
        GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
        GDD->GetD3D9Device()->SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE );
        GDD->GetD3D9Device()->SetRenderState(D3DRS_ZENABLE , D3DZB_TRUE);
        GDD->GetD3D9Device()->SetRenderState(D3DRS_ALPHATESTENABLE , FALSE);
        GDD->GetD3D9Device()->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);
#endif
        extern RenderingState_t GRenderingState;
        GRenderingState.mAlphaTestEnable = 0;
        GRenderingState.mZWriteEnable = 1;
        GRenderingState.mBlending = 0;
        GRenderingState.mCulling = 0;
        GRenderingState.mZTestType = 1;
#endif
    }


}