bool CGizmoTransformRotate::OnMouseDown(unsigned int x, unsigned int y)
{
    if (m_pMatrix)
    {
        return GetOpType(m_RotateType, x, y);
    }

    m_RotateType = ROTATE_NONE;
    return false;
}
Example #2
0
bool CGizmoTransformMove::OnMouseDown(unsigned int x, unsigned int y)
{
	if (m_pMatrix)
	{
		return GetOpType(m_MoveType, x, y);
	}

	m_MoveType = MOVE_NONE;
	return false;
}
bool CGizmoTransformScale::OnMouseDown(unsigned int x, unsigned int y)
{
	if (m_pMatrix)
	{
		return GetOpType(m_ScaleType, x, y);
	}

	m_ScaleType = SCALE_NONE;
	return false;
}
Example #4
0
File: xformOp.cpp Project: JT-a/USD
GfMatrix4d 
UsdGeomXformOp::GetOpTransform(UsdTimeCode time) const
{
    GfMatrix4d result(1);

    VtValue opVal;
    if (!Get(&opVal, time))
        return result;

    result = GetOpTransform(GetOpType(), opVal, _isInverseOp); 

    return result;
}
Example #5
0
GString *parse_script_str(const char *enc)
{
	char **tokens = g_strsplit_set(enc, " \t\n", 0);
	assert (tokens != NULL);

	GString *script = g_string_sized_new(64);

	unsigned int idx;
	for (idx = 0; tokens[idx] != NULL; idx++) {
		char *token = tokens[idx];

		if (is_digitstr(token)) {
			int64_t v = strtoll(token, NULL, 10);
			bsp_push_int64(script, v);
		}

		else if (is_hexstr(token, true)) {
			GString *raw = hex2str(token);
			g_string_append_len(script, raw->str, raw->len);
			g_string_free(raw, TRUE);
		}

		else if ((strlen(token) >= 2) &&
			 (token[0] == '\'') &&
			 (token[strlen(token) - 1] == '\''))
			bsp_push_data(script, &token[1], strlen(token) - 2);

		else if (GetOpType(token) != OP_INVALIDOPCODE)
			bsp_push_op(script, GetOpType(token));

		else
			assert(!"parse error");
	}

	g_strfreev(tokens);

	return script;
}
Example #6
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);
		}
	}

}
void CGizmoTransformScale::OnMouseMove(unsigned int x, unsigned int y)
{
	if (m_ScaleType != SCALE_NONE)
	{
		tvector3 rayOrigin,rayDir,df, inters, machin;
		tvector3 scVect,scVect2;

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

		switch (m_ScaleType)
		{
		case SCALE_XZ: scVect = tvector3(1,0,1); break;
		case SCALE_X:  scVect = tvector3(1,0,0); break;
		case SCALE_Z:  scVect = tvector3(0,0,1); break;
		case SCALE_XY: scVect = tvector3(1,1,0); break;
		case SCALE_YZ: scVect = tvector3(0,1,1); break;
		case SCALE_Y:  scVect = tvector3(0,1,0); break;
		case SCALE_XYZ:scVect = tvector3(1,1,1); break;
		}

		df = inters-m_pMatrix->GetTranslation();
		df/=GetScreenFactor();
		scVect2 = tvector3(1,1,1) - scVect;

		if (m_ScaleType == SCALE_XYZ)
		{
			int difx = x - m_LockX;
			float lng2 = 1.0f + ( float(difx) / 200.0f);
			SnapScale(lng2);
			scVect *=lng2;
		}
		else
		{
			float lng2 = ( df.Dot(m_LockVertex)/ m_Lng);
			if (lng2 < 1)
			{
				if (lng2<=-4)
					lng2 = 0.001f;
				else
				{
					lng2+=4;
					lng2/=5;
				}
			}
			SnapScale(lng2);
			scVect *= lng2;
			scVect += scVect2;
		}


		tmatrix mt,mt2;



		mt.Scaling(scVect);

        mt2.Identity();
		mt2.SetLine(0,GetTransformedVector(0));
		mt2.SetLine(1,GetTransformedVector(1));
		mt2.SetLine(2,GetTransformedVector(2));

		//mt2.Translation(0,0,0);
		//mt.Multiply(mt2);

        if (mLocation == LOCATE_WORLD)
        {
            mt2 = m_svgMatrix * mt;
        }
        else
        {
		    mt2 = mt * m_svgMatrix;//.Multiply(m_svgMatrix);
        }
		*m_pMatrix = mt2;
        //if (mTransform) mTransform->Update();
	}
	else
	{
		// predict move
		if (m_pMatrix)
		{
			GetOpType(m_ScaleTypePredict, x, y);
		}
	}

}
void CGizmoTransformScale::OnMouseMove(unsigned int x, unsigned int y)
{
  if (m_ScaleType != SCALE_NONE)
  {
    tvector3 rayOrigin,rayDir,df, inters, machin;
    tvector3 scVect,scVect2;

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

    switch (m_ScaleType)
    {
    case SCALE_XZ: scVect = tvector3(1,0,1); break;
    case SCALE_X:  scVect = tvector3(1,0,0); break;
    case SCALE_Z:  scVect = tvector3(0,0,1); break;
    case SCALE_XY: scVect = tvector3(1,1,0); break;
    case SCALE_YZ: scVect = tvector3(0,1,1); break;
    case SCALE_Y:  scVect = tvector3(0,1,0); break;
    case SCALE_XYZ:scVect = tvector3(1,1,1); break;
    }

    df = inters-m_pMatrix->GetTranslation();
    df/=GetScreenFactor();
    scVect2 = tvector3(1,1,1) - scVect;

    if (m_ScaleType == SCALE_XYZ)
    {
      int difx = x - m_LockX;
      float lng2 = 1.0f + ( float(difx) / 200.0f);
      SnapScale(lng2);
      scVect *=lng2;
    }
    else
    {
      int difx = x - m_LockX;
      int dify = y - m_LockY;

      float len = sqrtf( (float)(difx*difx) + (float)(dify*dify) );

      float lng2 = len /100.f;

      SnapScale(lng2);
      scVect *= lng2;
      scVect += scVect2;
    }


    tmatrix mt,mt2;



    mt.Scaling(scVect);

    mt2.Identity();
    mt2.SetLine(0,GetTransformedVector(0));
    mt2.SetLine(1,GetTransformedVector(1));
    mt2.SetLine(2,GetTransformedVector(2));


    if (mLocation == LOCATE_WORLD)
    {
      mt2 = mt * m_svgMatrix;
    }
    else
    {
      mt2 = mt * m_svgMatrix;//.Multiply(m_svgMatrix);
    }
    *m_pMatrix = mt2;

  }
  else
  {
    // predict move
    if (m_pMatrix)
    {
      GetOpType(m_ScaleTypePredict, x, y);
    }
  }

}
void CGizmoTransformRotate::OnMouseMove(unsigned int x, unsigned int y)
{
    tvector3 rayOrigin, rayDir, axis;

    BuildRay(x, y, rayOrigin, rayDir);

    if (m_RotateType != ROTATE_NONE)
    {
        if (m_RotateType == ROTATE_TWIN)
        {
            tvector3 inters;
            tvector3 dir = m_pMatrix->GetTranslation()-m_CamSrc;
            dir.Normalize();

            m_plan=vector4(m_pMatrix->GetTranslation(), dir);
            m_plan.RayInter(inters,rayOrigin,rayDir);
            ptd = inters;
            tvector3 df = inters - m_pMatrix->GetTranslation();
            df/=GetScreenFactor();
            float lng1 = df.Length();
            if (lng1 >= 1.0f) lng1 = 0.9f;

            float height = (float)sin(acos(lng1));
            tvector3 m_CamRealUp,camRight;
            camRight.Cross(m_Axis,m_CamUp);
            m_CamRealUp.Cross(camRight,dir);

            tvector3 idt = height*dir;
            idt+=df;

            //ptd = idt;
            idt= m_LockVertex-idt;

            tmatrix mt,mt2;

            mt.LookAtLH(tvector3(0,0,0),idt,m_CamRealUp);
            mt.Multiply(m_InvOrigScale);
            mt.Multiply(m_svgMatrix);
            mt2 = m_OrigScale;
            mt2.Multiply(mt);
            *m_pMatrix=mt2;
            /*
            if (mEditQT)
            {
            *mEditQT = tquaternion(mt2);
            }
            */
        }
        else
        {
            Rotate1Axe(rayOrigin, rayDir);

        }

        //if (mTransform) mTransform->Update();
    }
    else
    {
        // predict move
        if (m_pMatrix)
        {
            GetOpType(m_RotateTypePredict, x, y);
        }
    }
}
void CGizmoTransformScale::OnMouseMove(unsigned int x, unsigned int y)
{
	if (m_ScaleType != SCALE_NONE)
	{
		tvector3 rayOrigin,rayDir,df, inters, machin;
		tvector3 scVect,scVect2;

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

		switch (m_ScaleType)
		{
		case SCALE_XZ: scVect = tvector3(1,0,1); break;
		case SCALE_X:  scVect = tvector3(1,0,0); break;
		case SCALE_Z:  scVect = tvector3(0,0,1); break;
		case SCALE_XY: scVect = tvector3(1,1,0); break;
		case SCALE_YZ: scVect = tvector3(0,1,1); break;
		case SCALE_Y:  scVect = tvector3(0,1,0); break;
		case SCALE_XYZ:scVect = tvector3(1,1,1); break;
		}

		df = inters-m_pMatrix->GetTranslation();
		df/=GetScreenFactor();
		scVect2 = tvector3(1,1,1) - scVect;

		if (m_ScaleType == SCALE_XYZ)
		{
			int difx = x - m_LockX;
			float lng2 = 1.0f + ( float(difx) / 200.0f);
			SnapScale(lng2);
			scVect *=lng2;
		}
		else
		{
            int difx = x - m_LockX;
            int dify = y - m_LockY;

            float len = sqrtf( (float)(difx*difx) + (float)(dify*dify) );

            float lng2 = len /100.f;
            /*
			float lng2 = ( df.Dot(m_LockVertex));
            char tmps[512];
            sprintf(tmps, "%5.4f\n", lng2 );
            OutputDebugStringA( tmps );


			if (lng2 < 1.f)
			{
				if ( lng2<= 0.001f )
					lng2 = 0.001f;
				else
				{
					//lng2+=4.f;
					lng2/=5.f;
				}
			}
            else
            {
                int a = 1;
            }
            */
			SnapScale(lng2);
			scVect *= lng2;
			scVect += scVect2;
		}


		tmatrix mt,mt2;



		mt.Scaling(scVect);

        mt2.Identity();
		mt2.SetLine(0,GetTransformedVector(0));
		mt2.SetLine(1,GetTransformedVector(1));
		mt2.SetLine(2,GetTransformedVector(2));

		//mt2.Translation(0,0,0);
		//mt.Multiply(mt2);

        if (mLocation == LOCATE_WORLD)
        {
            mt2 = mt * m_svgMatrix;
        }
        else
        {
		    mt2 = mt * m_svgMatrix;//.Multiply(m_svgMatrix);
        }
		*m_pMatrix = mt2;
        //if (mTransform) mTransform->Update();
	}
	else
	{
		// predict move
		if (m_pMatrix)
		{
			GetOpType(m_ScaleTypePredict, x, y);
		}
	}

}