void CGizmoTransformScale::ApplyTransform(tvector3& trans, bool bAbsolute) { if (bAbsolute) { tmatrix m_InvOrigScale,m_OrigScale; m_OrigScale.Scaling(GetTransformedVector(0).Length(), GetTransformedVector(1).Length(), GetTransformedVector(2).Length()); m_InvOrigScale.Inverse(m_OrigScale); m_svgMatrix = *m_pMatrix; tmatrix mt; mt.Scaling(trans.x/100.0f,trans.y/100.0f,trans.z/100.0f); mt.Multiply(m_InvOrigScale); mt.Multiply(m_svgMatrix); *m_pMatrix=mt; } else { tmatrix mt,mt2; m_svgMatrix = *m_pMatrix; mt.Scaling(trans.x/100.0f,trans.y/100.0f,trans.z/100.0f); mt2.SetLine(0,GetTransformedVector(0)); mt2.SetLine(1,GetTransformedVector(1)); mt2.SetLine(2,GetTransformedVector(2)); mt2.Translation(0,0,0); mt.Multiply(mt2); mt.Multiply(m_svgMatrix); *m_pMatrix = mt; } }
bool CGizmoTransformRotate::GetOpType(ROTATETYPE &type, unsigned int x, unsigned int y) { tvector3 rayOrigin,rayDir, axis; tvector3 dir = m_pMatrix->GetTranslation()-m_CamSrc; dir.Normalize(); BuildRay(x, y, rayOrigin, rayDir); if (mMask&AXIS_TRACKBALL) if (CheckRotatePlan(dir,1.0f,rayOrigin,rayDir,-1)) { tmatrix mt = *m_pMatrix; mt.NoTrans(); //mt.Inverse(); //m_Axis = m_Axis2 = dir; m_Axis.TransformPoint(mt); /* m_Axis *=tvector3(GetTransformedVector(0).Length(), GetTransformedVector(1).Length(), GetTransformedVector(2).Length()); */ type = ROTATE_TWIN; return true; } // plan 1 : X/Z m_Axis = GetTransformedVector(0); if (mMask&AXIS_X) if (CheckRotatePlan(m_Axis,1.0f,rayOrigin,rayDir,0)) { type = ROTATE_X; return true; } m_Axis = GetTransformedVector(1); if (mMask&AXIS_Y) if (CheckRotatePlan(m_Axis,1.0f,rayOrigin,rayDir,1)) { type = ROTATE_Y; return true; } m_Axis = GetTransformedVector(2); if (mMask&AXIS_Z) if (CheckRotatePlan(m_Axis,1.0f,rayOrigin,rayDir,2)) { type = ROTATE_Z; return true; } //m_Axis = GetTransformedVector(dir); if (mMask&AXIS_SCREEN) if (CheckRotatePlan(dir,1.2f,rayOrigin,rayDir,-1)) { tmatrix mt = *m_pMatrix; mt.NoTrans(); mt.Inverse(); m_Axis = m_Axis2 = dir; m_Axis.TransformPoint(mt); m_Axis *=tvector3(GetTransformedVector(0).Length(), GetTransformedVector(1).Length(), GetTransformedVector(2).Length()); type = ROTATE_SCREEN; return true; } type = ROTATE_NONE; return false; }
bool CGizmoTransformRotate::CheckRotatePlan(tvector3 &vNorm, float factor, const tvector3 &rayOrig,const tvector3 &rayDir,int id) { tvector3 df, inters; m_Axis2 = vNorm; m_plan=vector4(m_pMatrix->GetTranslation(), vNorm); m_plan.RayInter(inters,rayOrig,rayDir); ptd = inters; df = inters - m_pMatrix->GetTranslation(); df/=GetScreenFactor(); if ( ((df.Length()/factor) >0.9f) && ( (df.Length()/factor) < 1.1f) ) { m_svgMatrix = *m_pMatrix; m_LockVertex = df; m_LockVertex.Normalize(); m_Vtx = m_LockVertex; m_Vty.Cross(m_LockVertex,vNorm); m_Vty.Normalize(); m_Vtx *= factor; m_Vty *= factor; m_Vtz.Cross(m_Vtx,m_Vty); m_Ng2 = 0; if (id!=-1) m_Axis = GetVector(id); m_OrigScale.Scaling(GetTransformedVector(0).Length(), GetTransformedVector(1).Length(), GetTransformedVector(2).Length()); m_InvOrigScale.Inverse(m_OrigScale); return true; } 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; 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; }
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::ApplyTransform(tvector3& trans, bool bAbsolute) { tmatrix mt; m_OrigScale.Scaling(GetTransformedVector(0).Length(), GetTransformedVector(1).Length(), GetTransformedVector(2).Length()); if (bAbsolute) { tvector3 translation = m_pMatrix->GetTranslation(); //X mt.RotationAxis(GetVector(0),((trans.x/360)*ZPI)); mt.Multiply(m_OrigScale); *m_pMatrix=mt; //Y mt.RotationAxis(GetVector(1),((trans.y/360)*ZPI)); mt.Multiply(m_OrigScale); *m_pMatrix=mt; //Z mt.RotationAxis(GetVector(2),((trans.z/360)*ZPI)); mt.Multiply(m_OrigScale); *m_pMatrix=mt; //translate m_pMatrix->m16[12] = translation.x; m_pMatrix->m16[13] = translation.y; m_pMatrix->m16[14] = translation.z; } else { tmatrix mt2; m_InvOrigScale.Inverse(m_OrigScale); if (trans.x!=0) { m_svgMatrix = *m_pMatrix; mt.RotationAxis(GetVector(0),((trans.x/360)*ZPI)); mt.Multiply(m_InvOrigScale); mt.Multiply(m_svgMatrix); mt2 = m_OrigScale; mt2.Multiply(mt); *m_pMatrix=mt2; } if (trans.y!=0) { m_svgMatrix = *m_pMatrix; mt.RotationAxis(GetVector(1),((trans.y/360)*ZPI)); mt.Multiply(m_InvOrigScale); mt.Multiply(m_svgMatrix); mt2 = m_OrigScale; mt2.Multiply(mt); *m_pMatrix=mt2; } if (trans.z!=0) { m_svgMatrix = *m_pMatrix; mt.RotationAxis(GetVector(2),((trans.z/360)*ZPI)); mt.Multiply(m_InvOrigScale); mt.Multiply(m_svgMatrix); mt2 = m_OrigScale; mt2.Multiply(mt); *m_pMatrix=mt2; } } }
/* 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 } }
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); } } }