Hello,
I am newer at game developing and bullet. I have question about object dragging. OpenGL demo project contain good example how to pick objects in 3D and move them. My task is drag object in 2 axis (came is turned, object picking is going in 3D). So I can move object only in the floor (X-Z) and Y axis is locked. I limit Y axis using:
body->setLinearFactor(btVector3(1,0,1));
body->setAngularFactor(btVector3(0,1,0));
But the mouse motion function does not work correct. Because it's still calculate object moving for Y axis. After dragging position of object is not equals with position of mouse. How can I solve this problem? The object should stay at the center of the mouse.
Also I have question about constrain should I use btPoint2PointConstraint or is better to use btGeneric6DofConstraint for object sliding at 2D?
Thanks a lot!
Kirils
Picking object in 3D and drag in 2d
-
memoni
- Posts: 2
- Joined: Sun Jan 31, 2010 12:39 pm
Re: Picking object in 3D and drag in 2d
What you could do is to first find the hitpoint point of the selected object (this probably is done in the opengl demo), and then construct a plane which has has normal pointing upwards and its' distance calculated using the hitpoint. Then as you drag the mouse, calculate intersection between the ray and the plane you just generated. This will limit the movement delta on XZ plane and should also result natural movement of the object. There are some perceptional discontinuities with this method, though, i.e. when moving something up or down a slope.
-
kiril
- Posts: 2
- Joined: Sat Jan 30, 2010 11:27 am
Re: Picking object in 3D and drag in 2d
Finally all start works like I want.
Firstly I set pivot A to 0, 0, 0 to pick object at center. The distance was removed. Now I upward ray to flore.
btVector3 cameraPosition = ...;
btVector3 newRayTo = getRayTo(x, y);
btVector3 dir = newRayTo - CameraPosition;
dir.normalize();
btVector3 pivot = CameraPosition;
// trying get y eq 0.0f
float k = pivot.getY() / dir.getY();
pivot = pivot - dir * k;
p2p->setPivotB( pivot );
Also I remove dragging impulse from my constrain
p2p->m_setting.m_impulseClamp // i don't why i set it to 1000.0f previously
Thanks!
Firstly I set pivot A to 0, 0, 0 to pick object at center. The distance was removed. Now I upward ray to flore.
btVector3 cameraPosition = ...;
btVector3 newRayTo = getRayTo(x, y);
btVector3 dir = newRayTo - CameraPosition;
dir.normalize();
btVector3 pivot = CameraPosition;
// trying get y eq 0.0f
float k = pivot.getY() / dir.getY();
pivot = pivot - dir * k;
p2p->setPivotB( pivot );
Also I remove dragging impulse from my constrain
p2p->m_setting.m_impulseClamp // i don't why i set it to 1000.0f previously
Thanks!