Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyGTK Track Editor - Round 2
03-28-2008, 05:53 PM,
#16
 
alex25 Wrote:the latest changes seem to have broken object selection.

looks like i needed to update vdrift as well. the camera direction still doesn't work though.

--alex--
Reply
03-28-2008, 07:51 PM,
#17
 
rookie1 Wrote:1. How do we decide the camera position? Ideally, it should not be too near nor too far. And it should not be obstructed by other objects.

Hmm... what about just placing the camera some distance away (the distance could be determined by the object's size), and then providing some mechanism for the user the orbit the camera around the object?

Quote:2. Is there anything wrong in the above code to calculate camera direction?

The lookat function is kind of sketchy. It uses the opengl lookat function to change the modelview matrix, and then copies the model view matrix and tries to back-calculate the quaternion representation of that matrix. I don't think it's used and so probably hasn't ever been tested very well. As an alternative, try attacking the problem using vector math. Warning, sloppy pseudo-code ahead:

By default the quaternion points straight ahead (0,0,1). The direction to the object is (campos - objpos).normalize(). You can find the y-axis rotation between those two vectors by setting the y components of each to zero and using the equation:
angle = arccos (a.normalize().dot(b.normalize()))
You can then do
quaternion.Rotate(angle, 0,1,0);
and your camera should be properly rotated (on the Y axis) so it points at the object. Beware of special cases (what if the camera is above the object?). Also, the quaternion class uses radians as the angle units. By the way, you might as well just rewrite the lookat function and use that, since it is unused and apparently broken at the moment.
Reply
03-29-2008, 10:28 AM,
#18
 
Hi Joe, can you confirm LookAt() is not used? I can see it being used in vamosworld.cpp to compute chase camera.
Reply
03-30-2008, 01:27 PM,
#19
 
rookie1 Wrote:Hi Joe, can you confirm LookAt() is not used? I can see it being used in vamosworld.cpp to compute chase camera.

Oops, you're right.

Okay, I re-implemented LookAt in R1973. It's based on the OpenGL reference code but uses no OpenGL functions, so I'm hoping it'll work better when you use it (previously it was kind of dependent on OpenGL state, and maybe that's why it wasn't working for you).
Reply
04-04-2008, 08:57 AM,
#20
 
It seems even setting camera position is not working as expected.

Code:
obj_pos = vdrift.VERTEX(pyobj.model.jmodel.GetBBOX().GetCenter())
cam_pos = vdrift.VERTEX(obj_pos)
cam_pos.Scale(-1)
vdrift.game.cam.SetPosition(cam_pos)

I'm using the object model's bounding box center as the camera position. If everything works as expected, the camera should be inside the object. But in fact the camera is some distance away from the object. The camera is always at below ground level when I test Laguna Seca. Even when I comment out cam_pos.Scale(-1), it's still not correct! Can't figure out where I did wrong :?
Reply
04-04-2008, 10:26 AM,
#21
 
The vamos engine uses a different coordinate system than the rest of VDrift, and that may be where the problems are coming from. It's a mess, in fact. I'll post more info later tonight....
Reply
04-04-2008, 10:12 PM,
#22
 
If you do objects.GetSceneNode().TransformIntoWorldSpace(VERTEX&) it takes your vertex in local object space (i.e. vamos coordinate system) and returns a VERTEX in world space. The similar function TransformIntoLocalSpace(VERTEX&) will do the opposite. This should allow you to transform the object position into camera position.
Reply
04-08-2008, 11:24 AM,
#23
 
Thanks Joe. TransformIntoWorldSpace() is the step I'm missing. Now the camera is working correctly. Smile I've also implemented zoom using mouse wheel. Check the latest revision in pygtk-trackeditor branch.
Reply
04-08-2008, 01:21 PM,
#24
 
rookie1 Wrote:Thanks Joe. TransformIntoWorldSpace() is the step I'm missing. Now the camera is working correctly. Smile I've also implemented zoom using mouse wheel. Check the latest revision in pygtk-trackeditor branch.

great job! a couple of requests though. would it be possible to select an object by clicking on it? second: it seems that i can move the camera sideways but i can't move it up and down. am i missing something?

--alex--
Reply
04-09-2008, 10:21 AM,
#25
 
I've just added camera rotation along horizontal axis in the latest revision. As to object picking, I'll need to copy some code from the original track editor. Coming soon. Smile
Reply
04-22-2008, 10:32 AM,
#26
 
Ok, I've implemented mouse pick. Left mouse click at an object will select it. It's done in Python, and the code needs to iterate through the whole object list. So it's quite slow at the moment.

Btw, now click and hold right(instead of left) mouse button to rotate the camera around the selected object.
Reply
04-22-2008, 01:26 PM,
#27
 
rookie1 Wrote:Ok, I've implemented mouse pick. Left mouse click at an object will select it.

would be nice if the object list got updated as well so the selected object is highlighted and centered in the objects display window.

--alex--
Reply
04-22-2008, 10:43 PM,
#28
 
That's next on my list. Sorry for the slow update. Pretty busy recently.
Reply
04-23-2008, 01:28 AM,
#29
 
rookie1 Wrote:That's next on my list. Sorry for the slow update. Pretty busy recently.

take your time. you are doing a great job.

--alex--
Reply
04-28-2008, 09:31 AM,
#30
 
Now the object list will scroll to the selected object when you do a mouse pick. I've also optimised the code to iterate through only those objects currently on screen (in the viewing frustum). This should hopefully make the object selection faster. Note that you need to update vdrift svn and re-compile the python wrapper for this to work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)