Could someone tell me how to use jpct-ae realize the attached car racing game?

Started by gamenewer, May 27, 2014, 03:31:52 AM

Previous topic - Next topic

gamenewer

Hello !  I can use camera  "walk along" the road ,it seems ok.  Now , I add a car into the world and let the camera  follow it , the car's position set by

SimpleVector pos = waypoint[WayID];
car.clearTranslation();
car.translate(pos);

the camera position set by

          pos.x -=2;
          pos.y += 60;
          pos.z -= 40;

cam.setPosition(pos);

but  the car  position is seems not ok ,   it somtimes lost on road,  camera is always ok , because I  always "walk along" the road  , I try to find object3d  setposition function , but  I only found  translate function , please help me , thanks !

EgonOlsen

There is no setPosition for Object3D's, but what you are doing (clear/translate) is exactly the same thing. If it doesn't work out, make sure that you aren't using setOrigin() on your car and that the center of the car is located where you think that it is (you can verify this by printing out the result of getCenter() after calling build). If should be roughly located around 0,0,0 or are car's object space is off.

gamenewer

Sorry , I  don't know  how to translate from object-space  to world- space or  from world-space to object-space  by jpct-ae,   for example, I want to translate my car   by  it's right  direction  a distance  or  by it's  forward  direction a distance   or rotate a  angle ....    and don't care of world - space,  I look at the doc  and not found about this 

EgonOlsen

You objects exist in object space, each in it's own. By applying transformations to them like rotations and translations, you transform them into world space. Usually, the game logic "thinks" in world space in most cases. Why i mentioned these spaces is simply because, depending on the model, your model's object space position might be off, so that you'll get confusing results. An example: If your object is located around 0,0,0 in object space, your camera hasn't moved and you are looking down the z-axis, a translation of your model by 0,0,100 will transform the object's center of (0,0,0) into the world space coordinates (0,0,100). And you would be able to see it as expected with your camera setup. However, if your model is centered around 0,0,-200 in object space, the translation will place it at (0,0,-100) in world space and your won't be able to see it without changing the camera. Or in other words: Make sure that your object's center is roughly where you expect it to be. I should be, but some exporters produces strange outputs. So there's always a chance that, if you don't see a model where you think that it should be, this might be the reason.

gamenewer

Thanks for help,  When load a model   , it's have an object-space default   or  should to  do some setting ? 

I attached a picture may help me to explain the problem,  I want the car move by  x axis (or other axis)    a   distance  d (object-space ) , How can I do it ?

another new  question is   :   I have got the point A  , and I know  the  distance   from  A to B , How can I caculate the Point B?   ( In object -space ,   the  direction from A to B is   x axis , you can consider  A is an object ,  I want to get  B,the point at  the object   right direction(x axis or other axis)   , distance is d)   I hope you can see my explain  ;)




[attachment deleted by admin]

EgonOlsen

Quote
I want the car move by  x axis (or other axis)    a   distance  d (object-space ).
It might have been a better idea of mine if i would never have mentioned object space at all...it was just an idea about what to look for, if object aren't visible or not placed where you want them to. I don't think that it matters here. You seem to want to move the car relative to it's position and orientation. That's pretty simple. You have get?Axis()-methods in the Object3D for the x,y and z axis of an object. You can use the results to translate the car along the returned vectors (you might have to multiply them by some factor to get the car up to speed) to translate it relative to it's orientation.

Quote
I have got the point A  , and I know  the  distance   from  A to B , How can I caculate the Point B?   ( In object -space ,   the  direction from A to B is   x axis , you can consider  A is an object ,  I want to get  B,the point at  the object   right direction(x axis or other axis)   , distance is d)   I hope you can see my explain
That's basically the same thing. Given that A is rotated correctly, you can call getXAxis() on it, multiply it by the distance and add the result to the current translation of A. That should give you B.

gamenewer

thanks very much ,  I know the function getXAxis  getYAxis  getZAxis  usage, they are used to get the  object  up . right , and forward direction vector , use this can easy do something about object ,  thanks again  :)