cedricguillemet / libgizmo Goto Github PK
View Code? Open in Web Editor NEWGizmo control library for 3D object manipulation (4x4 matrix)
Home Page: http://skaven.fr
Gizmo control library for 3D object manipulation (4x4 matrix)
Home Page: http://skaven.fr
******************************************************************************************************** * 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
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:
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
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
When orthogonal has some problems
Unrecognizable axis
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!
To replicate this bug:
Please let me know if you have question about the bug. I hope it is not a difficult fix :)
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;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.