Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement to scaling gizmo #6

Open
mustcode opened this issue Nov 20, 2013 · 0 comments
Open

improvement to scaling gizmo #6

mustcode opened this issue Nov 20, 2013 · 0 comments

Comments

@mustcode
Copy link

here's a way to not have the scaling gizmo always snap to zero scale when user start scaling non-uniformly

            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;

                // modification start ////////////////////////////////////////////////////

                // original code...
                //float len = sqrtf( (float)(difx*difx) + (float)(dify*dify) );
                //float lng2 = len /100.f;

                // get location of object in screen space
                tmatrix viewproj = m_Model * m_Proj;
                tvector3 trans = m_pMatrix->GetTranslation();
                tvector4 wpos = vector4(trans.x, trans.y, trans.z, 1.f);
                wpos.Transform(viewproj);
                tvector2 spos(wpos.x/wpos.w, -(wpos.y/wpos.w));
                if(wpos.z < 0)
                    return;
                tvector2 screenPos(0,0);
                tvector2 screenSize((float)mScreenWidth, (float)mScreenHeight);
                tvector2 pos(screenPos.x + (1.f + spos.x)*(screenSize.x * .5f), (screenPos.y + (1.f + spos.y)*(screenSize.y * .5f)));

                // compare clicked pos and object pos to choose between x or y axis
                // and determine which direction is positive or negative
                float lng2;
                float distx = abs(m_LockX - pos.x);
                float disty = abs(m_LockY - pos.y);
                if(distx >= disty)
                {
                    if(m_LockX < pos.x)
                        lng2 = 1.0f - ( float(difx) / 100.0f);
                    else
                        lng2 = 1.0f + ( float(difx) / 100.0f);
                }
                else
                {
                    if(m_LockY < pos.y)
                        lng2 = 1.0f - ( float(dify) / 100.0f);
                    else
                        lng2 = 1.0f + ( float(dify) / 100.0f);
                }
                // modification end //////////////////////////////////////////////////////

                /*
                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;
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant