Exemple #1
0
bool CGizmoTransformMove::GetOpType(MOVETYPE &type, unsigned int x, unsigned int y)
{
    tvector3 rayOrigin, rayDir, df;
    BuildRay(x, y, rayOrigin, rayDir);
    m_svgMatrix = *m_pMatrix;


    tvector3 trss(GetTransformedVector(0).Length(),
        GetTransformedVector(1).Length(),
        GetTransformedVector(2).Length());

    tmatrix mt;
    if (mLocation == LOCATE_LOCAL)
    {
        mt = *m_pMatrix;
        mt.V4.position += vector4(m_Offset, 0.0f);
        mt.Inverse();
    }
    else
    {
        // world
        tvector4 pos = m_pMatrix->V4.position;
        pos += vector4(m_Offset, 0.0f);
        mt.Translation(-pos);
    }

    // plan 1 : X/Z
    df = RayTrace2(rayOrigin, rayDir, GetTransformedVector(1), mt, trss, false);

    if ( ( df.x >= 0 ) && (df.x <= 1) && ( fabs(df.z) < 0.1f ) ) { type = MOVE_X; return true; }
    else if ( ( df.z >= 0 ) && (df.z <= 1) && ( fabs(df.x) < 0.1f ) ){ type = MOVE_Z; return true; }
    else if ( (df.x<0.5f) && (df.z<0.5f) && (df.x>0) && (df.z>0)) { type = MOVE_XZ; return true; }
    else {

        //plan 2 : X/Y
        df = RayTrace2(rayOrigin, rayDir, GetTransformedVector(2), mt, trss, false);

        if ( ( df.x >= 0 ) && (df.x <= 1) && ( fabs(df.y) < 0.1f ) ) { type = MOVE_X; return true; }
        if ( ( df.y >= 0 ) && (df.y <= 1) && ( fabs(df.x) < 0.1f ) ) { type = MOVE_Y; return true; }
        else if ( (df.x<0.5f) && (df.y<0.5f) && (df.x>0) && (df.y>0)) { type = MOVE_XY; return true; }
        else
        {
            //plan 3: Y/Z
            df = RayTrace2(rayOrigin, rayDir, GetTransformedVector(0), mt, trss, false);

            if ( ( df.y >= 0 ) && (df.y <= 1) && ( fabs(df.z) < 0.1f ) ) { type = MOVE_Y; return true; }
            else if ( ( df.z >= 0 ) && (df.z <= 1) && ( fabs(df.y) < 0.1f ) ) { type = MOVE_Z; return true; }
            else if ( (df.y<0.5f) && (df.z<0.5f) && (df.y>0) && (df.z>0)) { type = MOVE_YZ; return true; }

        }
    }

    type = MOVE_NONE;
    return false;
}
bool CGizmoTransformScale::GetOpType(SCALETYPE &type, unsigned int x, unsigned int y)
{
	// init
	tvector3 trss(GetTransformedVector(0).Length(),
		GetTransformedVector(1).Length(),
		GetTransformedVector(2).Length());

	m_LockX = x;
	m_svgMatrix = *m_pMatrix;

	tmatrix mt;
	mt = *m_pMatrix;
	mt.NoTrans();
	mt.Inverse();


	// ray casting
	tvector3 rayOrigin,rayDir,df2;
	BuildRay(x, y, rayOrigin, rayDir);

	// plan 1 : X/Z
	df2 = RayTrace2(rayOrigin, rayDir, GetTransformedVector(1), mt, trss);


	if ( (df2.x<0.2f) && (df2.z<0.2f) && (df2.x>0) && (df2.z>0)) { type = SCALE_XYZ; return true; }
	else if ( ( df2.x >= 0 ) && (df2.x <= 1) && ( fabs(df2.z) < 0.1f ) ) { type = SCALE_X; return true;	}
	else if ( ( df2.z >= 0 ) && (df2.z <= 1) && ( fabs(df2.x) < 0.1f ) ) { type = SCALE_Z; return true;	}
	else if ( (df2.x<0.5f) && (df2.z<0.5f) && (df2.x>0) && (df2.z>0)) {	type = SCALE_XZ; return true; }
	else
	{
		//plan 2 : X/Y
		df2 = RayTrace2(rayOrigin, rayDir, GetTransformedVector(2), mt, trss);

		if ( (df2.x<0.2f) && (df2.y<0.2f) && (df2.x>0) && (df2.y>0)) { type = SCALE_XYZ; return true; }
		else if ( ( df2.x >= 0 ) && (df2.x <= 1) && ( fabs(df2.y) < 0.1f ) ) { type = SCALE_X; return true;	}
		else if ( ( df2.y >= 0 ) && (df2.y <= 1) && ( fabs(df2.x) < 0.1f ) ) { type = SCALE_Y; return true; }
		else if ( (df2.x<0.5f) && (df2.y<0.5f) && (df2.x>0) && (df2.y>0)) { type = SCALE_XY; return true; }
		else
		{
			//plan 3: Y/Z
			df2 = RayTrace2(rayOrigin, rayDir, GetTransformedVector(0), mt, trss);

			if ( (df2.y<0.2f) && (df2.z<0.2f) && (df2.y>0) && (df2.z>0)) { type = SCALE_XYZ; return true; }
			else if ( ( df2.y >= 0 ) && (df2.y <= 1) && ( fabs(df2.z) < 0.1f ) ) { type = SCALE_Y; return true;	}
			else if ( ( df2.z >= 0 ) && (df2.z <= 1) && ( fabs(df2.y) < 0.1f ) ) { type = SCALE_Z; return true;	}
			else if ( (df2.y<0.5f) && (df2.z<0.5f) && (df2.y>0) && (df2.z>0)) { type = SCALE_YZ; return true; }
		}
	}

	type = SCALE_NONE;
	return false;
}
bool CGizmoTransformMove::GetOpType(MOVETYPE &type, unsigned int x, unsigned int y)
{
	tvector3 rayOrigin, rayDir, df;
	BuildRay(x, y, rayOrigin, rayDir);
	m_svgMatrix = *m_pMatrix;


	tvector3 trss(GetTransformedVector(0).Length(),
		GetTransformedVector(1).Length(),
		GetTransformedVector(2).Length());

	tmatrix mt;
	mt = *m_pMatrix;
	mt.NoTrans();
	mt.Inverse();

	// plan 1 : X/Z
	df = RayTrace2(rayOrigin, rayDir, GetTransformedVector(1), mt, trss, false);

	if ( ( df.x >= 0 ) && (df.x <= 1) && ( fabs(df.z) < 0.1f ) ) { type = MOVE_X; return true; }
	else if ( ( df.z >= 0 ) && (df.z <= 1) && ( fabs(df.x) < 0.1f ) ){ type = MOVE_Z; return true; }
	else if ( (df.x<0.5f) && (df.z<0.5f) && (df.x>0) && (df.z>0)) { type = MOVE_XZ; return true; }
	else {

		//plan 2 : X/Y
		df = RayTrace2(rayOrigin, rayDir, GetTransformedVector(2), mt, trss, false);

		if ( ( df.x >= 0 ) && (df.x <= 1) && ( fabs(df.y) < 0.1f ) ) { type = MOVE_X; return true; }
		if ( ( df.y >= 0 ) && (df.y <= 1) && ( fabs(df.x) < 0.1f ) ) { type = MOVE_Y; return true; }
		else if ( (df.x<0.5f) && (df.y<0.5f) && (df.x>0) && (df.y>0)) { type = MOVE_XY; return true; }
		else
		{
			//plan 3: Y/Z
			df = RayTrace2(rayOrigin, rayDir, GetTransformedVector(0), mt, trss, false);

			if ( ( df.y >= 0 ) && (df.y <= 1) && ( fabs(df.z) < 0.1f ) ) { type = MOVE_Y; return true; }
			else if ( ( df.z >= 0 ) && (df.z <= 1) && ( fabs(df.y) < 0.1f ) ) { type = MOVE_Z; return true; }
			else if ( (df.y<0.5f) && (df.z<0.5f) && (df.y>0) && (df.z>0)) { type = MOVE_YZ; return true; }

		}
	}

	type = MOVE_NONE;
	return false;
}