I have a Question reguarding how to drag shapes in a 3D world.
I have methods that allow shapes to be "picked" properly but
I need to know how to calculate the NEW position of a
selected (picked) object .
Im posting a sample code for the translation method (x-y plane only).
It works but its not accurate and thats why im here :)
incx and incy are the amounts taken from the Mouse
position minus Old mouse position , after an object has
been picked and the mouse has moved.
A CObject3D instance is an object oriented shape
and cx, cy ,cz are its center coordinates.
WorldCenter : world center position on z axis
void Translate(float incx, float incy)
if(toolkit.m_SelectedObject3D != null )
float w = surface.Width; //display size
float h = surface.Height; //display size
float vx = 0;
float vy = 0;
CObject3D obj = toolkit.m_SelectedObject3D;
vx = -incx * ((obj.cz + surface.WorldCenter) / w);
vy = -incy * ((obj.cz + surface.WorldCenter) / h);
obj.cx -= vx;
obj.cy -= vy;
ps : this sample is from a C# wrapper for OpenGL i wrote and itsQuote:}
free to try here : www.headbits.com