Search code examples
c#c++openglopentk

Gizmo OpenTK (or OpenGL)


Is there anybody here who wrote the code to move objects using Gizmo? I mean to translate or rotate, cube for example by mouse? For example like in 3ds max or blender editors. I can't understand how to use 3d mouse position for this.


Solution

  • I did it. My algoritm :

    Vector2 mouseDelta;//set this for your own
    Vector3 objectPosition;//and this
    Vector3 objectUpDir;//and this
    //Here
    Vector3 MoveY(){
    Vector2 center = worldToScreen(objectPosition);//get center to screen
    Vector2 up = worldToScreen(objectPosition+objectUpDir);//get up to screen
    float ang = Vector2.CalculateAngle(mouseDelta,up-center);//get angle from up && mouse delta
    ang = MathHelper.RadiansToDegrees(ang);//get degreees
    ang = ang/90-1;//here :if perpendicular, then ang = 0
    return objPosition + objUpDir * (ang/5);//5 - your speed
    }