Giter VIP home page Giter VIP logo

libgizmo's Introduction

********************************************************************************************************
* INTRODUCTION
 
 - LibGizmo is a small, standalone library that adds a 3D matrix (4x4 floats) manipulation control 
   called 'Gizmo'. It consists of 3 different controls: a Move, a Rotate and a Scale. It works the 
   same way as in 3DStudio Max or Maya. It's written using C++ and the current implementation use 
   OpenGL fixed pipeline. Integration should be easy.

********************************************************************************************************
* LICENSE

Copyright (C) 2012 Cedric Guillemet

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

********************************************************************************************************
* Contact

 - email/GTALK : [email protected]
 - Twitter : @skaven_
 - web : http://www.skaven.fr
 
********************************************************************************************************
* USE

 - Set include path to inc, library path to lib

 - Link with LibGizmoDebug.lib for debug build, LibGizmo.lib for release

 - In your code :
	#include "iGizmo.h"

 - create one or more Gizmo with the functions : CreateMoveGizmo(), CreateRotateGizmo(), CreateScaleGizmo()

 - set a pointer to the 16 floats composing the matrix you want to edit
	gizmo->SetEditMatrix( objectMatrix );

 - Any time the display viewport changes, call SetScreenDimensions
    	gizmo->SetScreenDimension( screenWidth, screenHeight );

 - Once a frame, call SetCameraMatrix. The matrices you send

	float viewMat[16];
	float projMat[16];
       
	glGetFloatv (GL_MODELVIEW_MATRIX, viewMat );  
	glGetFloatv (GL_PROJECTION_MATRIX, projMat );  

	gizmo->SetCameraMatrix( viewMat, projMat );


 - Draw the gizmo
        gizmo->Draw();

 - Change the kind of matrix manipulation (view, local, world). Example for 'WORLD' mode:
	gizmo->SetLocation( IGizmo::LOCATE_WORLD );
	
 - When you receive a mouse button down, call
   if (gizmo->OnMouseDown( mousex, mousey ))
        SetCapture( hWnd );
	This methods returns true if you have to capture the mouse. mousex and mousey are display viewport
	local coordinates. 0,0 is upper left.
 - for mouse move and mouse button up, call:
		gizmo->OnMouseMove( mousex, mousey );
        gizmo->OnMouseUp( mousex, mousey );

********************************************************************************************************
* RENDERING

 - The rendering code is done by OpenGL Fixed pipeline. The implementation is done in GizmoTransformRender.cpp.
   6 methodes are called by all the 3 gizmo:

void DrawCircle(const tvector3 &orig,float r,float g,float b,const tvector3 &vtx,const tvector3 &vty);
void DrawCircleHalf(const tvector3 &orig,float r,float g,float b,const tvector3 &vtx,const tvector3 &vty,tplane &camPlan);
void DrawAxis(const tvector3 &orig, const tvector3 &axis, const tvector3 &vtx,const tvector3 &vty, float fct,float fct2,const tvector4 &col);
void DrawCamem(const tvector3& orig,const tvector3& vtx,const tvector3& vty,float ng);
void DrawQuad(const tvector3& orig, float size, bool bSelected, const tvector3& axisU, const tvector3 &axisV);
void DrawTri(const tvector3& orig, float size, bool bSelected, const tvector3& axisU, const tvector3& axisV);

   You can implement those methods using any API. There aren't any other call to a rendering library anywhere
   else. There is an old (untested) version using DX9 api.

********************************************************************************************************
* TODO

 - Linux/MacOSX port
 - Code cleanup
 - improve example with local/world/screen space change
 - DX10/11 rendering


libgizmo's People

Contributors

cedricguillemet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libgizmo's Issues

rotation gizmo usability problem/suggestion

Not a critical bug, but this will allow the LOCATE_VIEW and LOCATE_WORLD mode for rotation gizmo a lot more useful.
currently, rotation gizmo doesn't always rotate the object around the gizmo's "visual-axis"... meaning, the X-Y-Z arc rotate the object along the object's X-Y-Z axis, and after a few rotations, user will not be able to tell how the rotation axis is oriented (unless the gizmo is set to LOCAL mode). Ideally, regardless of whether the gizmo is in LOCAL, WORLD, or VIEW mode, the object should always rotate according to the visual arc visualized by the gizmo.

Thanks for a great lib, I found it very useful and I'm sure others will too. Keep up the great work!

improvement to scaling gizmo

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

after rotation, mouse detection will be incorrect in move/scale gizmo

Hi,

First of all, thanks for creating this lib. Love it, extremely useful. I hope you'll keep improving this lib :)

After trying out your lib, I've found a few bugs, but this one is the most important one. You can reproduce this bug easily by:

  1. run the executable demo included with the lib
  2. press 2 to switch to rotation gizmo
  3. rotate the object, (just 90 degree around Y axis should be enough)
  4. press 1 to switch back to move gizmo
  5. move the cursor over all the gizmo's arrows
  6. notice that the gizmo will no longer correctly detect collision between the cursor and the gizmo.

I might be wrong, but it looks like the collision detection is done as if the gizmo is set to LOCATE_LOCAL even when the gizmo is set to LOCATE_VIEW or LOCATE_WORLD

after non-uniform scaling, rotation will be not work correctly

To replicate this bug:

  1. run the example executable
  2. press 3 to switch to scale mode
    3 scale along the red axis to make the cube into a long box
  3. press 2 to switch to rotate mode
  4. try rotate along all axis and observe how the box will be distorted after some rotation

Please let me know if you have question about the bug. I hope it is not a difficult fix :)

Binaries in the repository

Hi,

It is, perhaps, not a great idea to include large binaries and intermediate build files (such as .ipch) in the git repository.
It might be worth-while deleting this repository while it doesn't contain any history and re-uploading the source excluding all binaries (use .gitignore rules).

Pre-built versions of the library and example applications can be uploaded to github as a separate downloadable packages.

Thank you,
Yuriy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.