www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: gamenewer on May 27, 2014, 03:31:52 am

Title: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 27, 2014, 03:31:52 am
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]
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on May 27, 2014, 08:14:46 pm
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... ;)
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 28, 2014, 02:11:00 am
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)
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: rtSJ on May 28, 2014, 09:51:54 am
You can't locate the car on the world ? Why ?

2 ideas about place waypoint :

And I never do a clever algorithm, so I can't help you.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 28, 2014, 12:21:31 pm
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
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: rtSJ on May 28, 2014, 01:35:27 pm
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 28, 2014, 03:04:53 pm
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)
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: rtSJ on May 28, 2014, 03:48:34 pm
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 29, 2014, 03:44:27 am
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 !!
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 29, 2014, 06:02:07 am
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
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 29, 2014, 01:59:49 pm
Anyone help  me?
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on May 29, 2014, 03:10:53 pm
Not sure what your exact problem is...? Where do you get your waypoints from?
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 29, 2014, 03:35:42 pm
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
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on May 29, 2014, 04:11:46 pm
Have you printed out your waypoints to see if they are what you expect them to be?
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 29, 2014, 04:17:32 pm
The log seems  ok 
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on May 29, 2014, 06:13:47 pm
Ok...so what is the actual issue then?
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 30, 2014, 02:42:04 am
I can't walk along the way by way point, it seems the carmera position  not incrocet
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 30, 2014, 02:56:44 am
I want  my car  run along the road,and the camera follow the car , like this:


[attachment deleted by admin]
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: rtSJ on May 30, 2014, 09:37:18 am
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 ?
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 30, 2014, 02:59:01 pm
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~~



Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: rtSJ on May 30, 2014, 03:34:05 pm
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 30, 2014, 03:47:01 pm
thank you very much !  I will try it soon  and give the result ...
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 30, 2014, 04:25:56 pm
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
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 30, 2014, 04:33:10 pm
Here is  my used  3d model , the way point named WP_1 WP_2 .... WP_43

[attachment deleted by admin]
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: rtSJ on May 30, 2014, 04:59:44 pm
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 30, 2014, 05:11:31 pm
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]
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on May 30, 2014, 05:52:29 pm
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...
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on May 31, 2014, 02:16:14 am
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 ....
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on June 01, 2014, 08:52:13 pm
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on June 03, 2014, 02:38:29 am
thanks ,I will try it   ~~
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on June 08, 2014, 04:41:32 pm
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 !
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on June 09, 2014, 09:50:39 pm
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on June 10, 2014, 10:00:41 am
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 
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on June 10, 2014, 09:14:37 pm
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on June 11, 2014, 07:22:37 am
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]
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: EgonOlsen on June 11, 2014, 07:39:31 am
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.
Title: Re: Could someone tell me how to use jpct-ae realize the attached car racing game?
Post by: gamenewer on June 11, 2014, 12:04:30 pm
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  :)