Author Topic: Could someone tell me how to use jpct-ae realize the attached car racing game?  (Read 11642 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Ok...so what is the actual issue then?

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
I can't walk along the way by way point, it seems the carmera position  not incrocet

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
I want  my car  run along the road,and the camera follow the car , like this:


[attachment deleted by admin]

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
I don't understand what your problem is. The position of the camera is never set ? Or it's set, but not at the right position ?
Try to log every single part of your code to identify the part where the error came from, to compare the result log with an expect result.

We can't help you with this informations. We don't understand what's going on and what is the real problem. Sorry. Can you explicit more ?

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Maybe my poor english...                  I have got the waypoint from 3d model ,  and I  set the camera position like this:

Camera cam = world.getCamera();

SimpleVector p = waypoint[WayID];

p.y -= 20;
p.z -= 100;
cam.setPosition(p);

but it seems the camera position is not correct(it should always on the road ,like a man walk on the road) ,  My purpose is to "walk along" on road so  my car can to do so,
sorry  for my poor english~~




Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
Okay so, if you want a smooth moving along the different waypoint and "on the road", you need to translate you camera. Or to set a new position on the duration. My solution is if you have a game cycle, you need to update the position of the camera between 2 waypoints.

Code: [Select]
int wayID;
int wayIDMax = waypoint.lenght;
float percent = 0;

function boolean moveAlongRoad(){
     Camera c = world.getCamera();
     // Adjust it with your duration of your game cycle
     float addPercent= 0.1;
     
     if(wayID < wayIDMax-1){
          c.setPosition(waypoint[wayID].getPosition.add(waypoint[wayID+1].sub(waypoint[wayID])*percent));
          percent += addPercent;
     } else {
          // Run finished
          return true;
     }
     
     if(addPercent >= 1){
          wayID++;
     }

     return false;
}

But for a perfect behavior, you need to apply this to an invisble object in front of your camera (Or just use a fictive position), translate the camera too but with a lower percentage, and do a "lookAt" to your camera on this object juste in front of it.
You camera will follow the path of your waypoint and always look in front of itself, on the road.

If you want to control exactly the view of the camera, you need to create other waypoint only for the invisible object, but it's more complicated to syncronyze both and more long to create a lots of waypoint. But it can work.
« Last Edit: May 30, 2014, 03:42:55 pm by rtSJ »

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
thank you very much !  I will try it soon  and give the result ...

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
HI,  I  do a  simple test,  the "walk step" is 1, when I  click the screen ,the WayID ++,  set camera position like this:

cam.setPosition(waypoint[WayID].calcAdd(waypoint[WayID+1].calcSub(waypoint[WayID])));

but the camera position still incrocrect,  I don't know why?

I  load 3d model like this:

try
            {
               
                obj = Loader.loadOBJ(res.getAssets().open("road.obj"),null,0.05f);

               
            saidao =Object3D.mergeAll(Loader.loadOBJ(res.getAssets().open("road.obj"),null,0.05f));//
               
            }
            catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               Log.v("ttt", "load error!");
            }
            TextureManager.getInstance().addTexture("road", new Texture(res.openRawResource(R.raw.road)));

            saidao.rotateX((float) (Math.PI) / 1f);
            saidao.translate(0,10,0);
            saidao.build();
            world.addObject(saidao);
            
             int k = 0;
              for(int i = 0; i < obj.length; i++){
                   //world.addObject(obj);
                   if(obj.getName().contains("WP_")){
                      obj.build();
                      waypoint[k] = obj.getTransformedCenter();
                     
                      wayNav[k] = obj;
                      k++;
                      Logger.log(obj.getTransformedCenter() + "-->GET WP->"+obj.getName());
                   }
                   else if(obj.getName().contains("Road"))
                   {
                      obj.setTexture("road");
                   }
                        
                   }

the  print is :
05-30 22:06:30.230: I/jPCT-AE(886): (-412.28714,1.8050749,1105.2081)-->GET WP->WP_1_jPCT1
05-30 22:06:30.230: I/jPCT-AE(886): Normal vectors calculated in 1ms!
05-30 22:06:30.230: I/jPCT-AE(886): (-482.62927,1.3220211,1107.2769)-->GET WP->WP_2_jPCT2
05-30 22:06:30.230: I/jPCT-AE(886): Normal vectors calculated in 1ms!
05-30 22:06:30.230: I/jPCT-AE(886): (-625.3562,1.3489301,1113.7605)-->GET WP->WP_3_jPCT3
.....................


Is there is something wrong ? thanks
« Last Edit: May 30, 2014, 04:48:42 pm by gamenewer »

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Here is  my used  3d model , the way point named WP_1 WP_2 .... WP_43

[attachment deleted by admin]

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
Are you sure that you export is correct ? I try to open your .obj with blender and all the waypoint are in the center of the world. And I don't see the road.

Try to display the position of your waypoint when you search them. Try to display the position of your camera at any moment too. I think your probleme come from your model. Not the librairy jPCT or my alogithm. I'm not sur, but your .obj is not correct.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
The model export from unity3d  and  changed type by 3dsmax,   I  can see the road and waypoint in application, the picture is captured from my handset 

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
I don't get your calculation...you that the point at wayId, add the one aat wayId+1 and subtract the one at wayId, which effectively is the same as setting it to wayId+1... ???

Apart from that, i might help to know what exactly "still incorrect" means...

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
sorry ,still incorrect  means that  I want to walk along the road , I always see the road ,but the result is not always on the road and sometimes the road not seen ....

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
The transformed center is being calculated based on the roads geometry. I might not always be located in a spot that a human would consider to be the actual center. About the road not being visible...maybe that's just because you are looking in the wrong direction? Try to align the camera with the direction vector from this waypoint to the next.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
thanks ,I will try it   ~~