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

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
I want use jpct-ae as 3d engine to realize a car racing game , but i don't know how to use the 3D map , How can i get the  way point  for car to run ?  Could some one tell me or give me some refence code ?  thank s

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
I think that you have to define the waypoints yourself. Either in code by using some clever algorithm or by hand...i would revert to the latter... ;)

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Thanks, I add the 3d map into the world ,  I can't control the  car location on the  map ,Do you have some good ideas?
(I'm a newer for jpct-ae,sorry)

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
You can't locate the car on the world ? Why ?

2 ideas about place waypoint :
  • Place waypoint into the 3D model of the map with a specific name "way_point_X", and when you place the road on the world, just search model with this name. And memorise positions on the world. It's the waypoint for the car.
  • Use XML to write by hand before. With a node correspond to one waypoint and have 3 attributs (Coordinates). With this way, you can write into the file and add some "best time" at each way point for show how is the best time of the player.

And I never do a clever algorithm, so I can't help you.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Thanks, If I add waypoint in 3d mode, How can  I search the  "waypoint_1" by jpct-ae?   I use code like this:

            try
            {
            saidao =Object3D.mergeAll(Loader.loadOBJ(res.getAssets().open("road.obj"),null,0.8f));//
            }
            catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               
            }
            TextureManager.getInstance().addTexture("road", new Texture(res.openRawResource(R.raw.road)));
            saidao.setTexture("road");
            
            saidao.translate(0,10,0);
            saidao.build();
            world.addObject(saidao);


Could you give me some refrece code ? Thank you

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
If I was in your situation, I'll do :

Code: [Select]
Object3D[] obj;
try {
     obj = Loader.loadOBJ(res.getAssets().open("road.obj");
     for(int i = 0; i < obj.length; i++){
          world.addObject(obj[i]);
          if(obj[i].getName().equalsIgnoreCase("waypoint_1")){
               // memoryse informations of coordinate with obj[j].obj[j].getCenter(); in a arraylist or an array
          }
     }

     saidao = Object3D.mergeAll(obj,null,0.8f));//
} catch (IOException e) {
     Log.w("Loading", "Error while loading object : "+e.getMessage());
}

TextureManager.getInstance().addTexture("road", new Texture(res.openRawResource(R.raw.road)));
saidao.setTexture("road");
           
saidao.translate(0,10,0);
saidao.build();

I'm not sur if it work because I don't test it. But you can try it and correct it easly. And actually you just search "waypoint_1", but you need to implement a new "for" or a "while" to detect all waypoint you want.

PS : Use the tag [ code ][ /code ] (without spaces) to write code properly. It's more clean.
« Last Edit: May 28, 2014, 03:42:32 pm by rtSJ »

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Thank  you Very Much !  If  got  all the waypoints ,   I will get the line for car  to transform , so car can run in AI  mode,  Is't it ?
(sorry for my poor english)

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
If you get a lot of waypoints (to make the line very smooth and realistic), you can translate IA car from one to the other waypoint and do like an AI behavior.

I don't know how are programmed AI of car in racing game. Maybe it's not a good solution, but you can do what you want to do with this method.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
HI, I use this mthod ,but i can't get the postion of waypoint , they are all (0,0,0) , Help me ,please

thank you !!

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Object should build before get the position, now  i  can get the waypoint , I wan't to use camera "walk" along the way by way point ,
like this:
Camera cam = world.getCamera();

SimpleVector p = waypoint[WayID];

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

but is  seems mistake , could you help me to modify the code, thank s a lot

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Anyone help  me?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Not sure what your exact problem is...? Where do you get your waypoints from?

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
I add waypoint in 3D mode, the waypoint as the children of road, I  load the road  like this;

Object3D[] obj;
obj = Loader.loadOBJ(res.getAssets().open("road.obj"),null,0.05f);
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++;
                    
                   }

so the waypoint postion are got

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Have you printed out your waypoints to see if they are what you expect them to be?

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
The log seems  ok