예제 #1
0
void CGizmoTransformRotate::Rotate1Axe(const tvector3& rayOrigin,const tvector3& rayDir)
{
    tvector3 inters;
    m_plan=vector4(m_pMatrix->GetTranslation(), m_Axis2);
    m_plan.RayInter(inters,rayOrigin,rayDir);
    ptd = inters;

    tvector3 df = inters - m_pMatrix->GetTranslation();

    df.Normalize();
    m_LockVertex2 = df;

    float acosng = df.Dot(m_LockVertex);
    m_Ng2 = (float)acos(acosng);

    if (df.Dot(m_Vty)>0)
        m_Ng2 = -m_Ng2;

    tmatrix mt,mt2;

    if (m_bUseSnap)
    {
        m_Ng2*=(360.0f/ZPI);
        SnapIt(m_Ng2,m_AngleSnap);
        m_Ng2/=(360.0f/ZPI);
    }

    mt.RotationAxis(m_Axis,m_Ng2);
    mt.Multiply(m_InvOrigScale);
    mt.Multiply(m_svgMatrix);
    mt2 = m_OrigScale;
    mt2.Multiply(mt);
    *m_pMatrix=mt2;

    if (m_Axis == tvector3::ZAxis)
    {
        if (mEditQT)
        {
            /*
            Dans le cadre du jeu, et vu les pb avec les quaternions,
            le 1er float du quaternion en stockage est l'angle en radian.
            le stockage reste un quaternion.
            il y a des pbs de conversion quaternion/matrix
            */
#if USE_QUATERNION
            tquaternion gth(*m_pMatrix);

            gth.Normalize();
            gth.UnitInverse();

            tquaternion qtg;
            qtg.RotationAxis(m_Axis,m_Ng2);
            *mEditQT = gth;//gth+qtg;//tquaternion(mt2);
            mEditQT->Normalize();
#else
            mEditQT->z = m_Ng2;
#endif
        }
    }
}
예제 #2
0
void CGizmoTransformScale::SnapScale(float &val)
{
	if (m_bUseSnap)
	{
		val*=(100.0f);
		SnapIt(val,m_ScaleSnap);
		val/=(100.0f);
	}
}
예제 #3
0
void CGizmoTransformMove::OnMouseMove(unsigned int x, unsigned int y)
{
	if (m_MoveType != MOVE_NONE)
	{
		tvector3 rayOrigin,rayDir,df, inters;

		BuildRay(x, y, rayOrigin, rayDir);
		m_plan.RayInter(inters,rayOrigin,rayDir);

		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();
        }

        df = inters - m_LockVertex;

		switch (m_MoveType)
		{
        case MOVE_XZ:	df = tvector3(df.Dot(axeX) , 0,df.Dot(axeZ));		break;
		case MOVE_X:	df = tvector3(df.Dot(axeX) , 0,0);							break;
		case MOVE_Z:	df = tvector3(0, 0,df.Dot(axeZ));							break;
		case MOVE_XY:	df = tvector3(df.Dot(axeX) ,df.Dot(axeY), 0);		break;
		case MOVE_YZ:	df = tvector3(0,df.Dot(axeY) ,df.Dot(axeZ));		break;
		case MOVE_Y:	df = tvector3(0,df.Dot(axeY), 0);							break;
		}

        tvector3 adf;

		tmatrix mt;
		if (m_bUseSnap)
		{
			SnapIt(df.x,m_MoveSnap.x);
			SnapIt(df.y,m_MoveSnap.y);
			SnapIt(df.z,m_MoveSnap.z);
		}

        adf = df.x*axeX + df.y*axeY + df.z*axeZ;

		mt.Translation(adf);
		*m_pMatrix = m_svgMatrix;
		m_pMatrix->Multiply(mt);
        //if (mTransform) mTransform->Update();

        if (mEditPos)
            *mEditPos = m_pMatrix->V4.position;
	}
	else
	{
		// predict move
		if (m_pMatrix)
		{
			GetOpType(m_MoveTypePredict, x, y);
		}
	}

}