Forums
PyGTK Track Editor - Round 2 - Printable Version

+- Forums (https://www.vdrift.net/Forum)
+-- Forum: Project (https://www.vdrift.net/Forum/forumdisplay.php?fid=4)
+--- Forum: Development (https://www.vdrift.net/Forum/forumdisplay.php?fid=9)
+--- Thread: PyGTK Track Editor - Round 2 (/showthread.php?tid=937)

Pages: 1 2 3


- alex25 - 03-28-2008

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--


- joevenzon - 03-28-2008

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.


- rookie1 - 03-29-2008

Hi Joe, can you confirm LookAt() is not used? I can see it being used in vamosworld.cpp to compute chase camera.


- joevenzon - 03-30-2008

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).


- rookie1 - 04-04-2008

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 :?


- joevenzon - 04-04-2008

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....


- joevenzon - 04-04-2008

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.


- rookie1 - 04-08-2008

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.


- alex25 - 04-08-2008

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--


- rookie1 - 04-09-2008

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


- rookie1 - 04-22-2008

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.


- alex25 - 04-22-2008

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--


- rookie1 - 04-22-2008

That's next on my list. Sorry for the slow update. Pretty busy recently.


- alex25 - 04-23-2008

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--


- rookie1 - 04-28-2008

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.