Flier Match

Started by Melssj5, January 18, 2006, 04:07:06 PM

Previous topic - Next topic

Melssj5

Well, I began coding this 2 days ago, I make a Bullet class, a Shot class and a movingThread for the bullets. I will have a Thread just for moving the bullets. On that way it wont depend on the speed of the rendering Thread nor on the lag from the server. I have not been at home this last 2 days (HANGOVER) but with a bit of luck I would have the basics of the shooting stuff by tomorrow.
Nada por ahora

Melssj5

Hi, I am having problems here. My problem is mainly that I am confused about how to set the initial position and direction from my bullets. I made some code here and there and I have now bullets being shot from my camera position "aparently". But I am having some problems, I guess I messed arround the rotation matrix of the camera and the bullets. Egon would you mind checking it a bit. Actually, I guess that is all that is missing from the client visulization. I have not added the shotting on the server yet. I just have a small code for shooting a bullet from my client. I will post the code tomorrow.
Nada por ahora

paulscode

You probably already thought of this, but just in case.  When applying the Camera rotation matrix to an Object3D, you might need to clone and invert it:

myObject3D.setRotationMatrix( myCamera.getBack().cloneMatrix().invert3x3() );

Then you could translate the bullet to the Camera's position in World space.  Then fire it in the direction of Camera.getDriection().

Melssj5

Thats exactly what I am doing. But the bullet is rotated 90 degrees and I dont know why. another problem is that I set the initial position of the bullet on the camera.getPosition SimpleVector but is not being fired exactly from the camera position. And when I move the camera down and lookAt the old camera position I dont look ant the center of the bullet. I also checked about the pivot of the bullet and everything is right.

I will continue trying it and post the code by tomorrow to see if I can fix it on somehow.
Nada por ahora

paulscode

#109
Another thing I thought of: are you loading the bullet model from a 3ds file?  If so, make sure the orientation on it is correct after loading.  I usually have to do something like this to make the object in jPCT match what the 3DS Max orientation looks like.  I always do this right after loading a 3DS model, before adding it to the world:

obj.rotateX( (float) Math.PI / 2 );
obj.rotateY( (float) Math.PI );
obj.rotateZ( (float) Math.PI );
obj.rotateMesh();
obj.setRotationMatrix( new Matrix() );

I'm not sure why the position is wrong though.  Could you post a link to the bullet model you are using, and I'll play around with it to see if I can help figure something out.

Melssj5

Well, I exported to a md2 model as is a very simple model. I checked the model orientation inside max and seems to be well, I will post everything by tomorrow, today I am at office and forgot my pen drive.

I will check that and try to post the project tomorrow.
Nada por ahora

paulscode

Ran a couple of tests on MD2 files created with 3DS MAX + QTip, and discovered that there is also an orientation difference with the MD2 format.  Unlike 3DS files, MD2 files only needed to be turned 90 degrees around the Y-axis.  Do this right after loading the file:


        myObject.rotateY( (float) Math.PI / 2 );
        myObject.rotateMesh();
        myObject.setRotationMatrix( new Matrix() );

Melssj5

Thanks, that should solve the problem about the bullet orientation. But I am still having the problem that when setting the position of the bullet on the camera position , it is placed near but not in the exact place.
Nada por ahora

Melssj5

#113
 :-[ :-[

The problem about not being shot from the camera center was a problem when modeling the bullet. It was moved a bit from the center. Anyway rotating it the PI/2 over the Y axis was helpfull too. Now the bullets are being fired correctly.

Now my problem is that they doesnt fire any collision event. I added a collisionListener to the bullets but they does not fires the event. I have used the collision listener before when moving the crafts on the server but when shooting the bullets on the client they dont.

Basicly.

When I create the bullet I add the colissionlistener, the bullet and the map has CHECK_SELF | CHECK_OTHERS as the collision mode. I am calling the checkforcollision and checkforcollisionelipsoid methods and they doesnt fire any event. The project is posted at:

melssj5.paulscode.com/FlierMatch.zip

Egon, can you please replace the one in the download section with this new one, is still not finished but it is closest to be finished. And please can any one help me with the collisionListening on the bullets?

About the code: Well, I have this classes:

- BulletThread (Thread for moving the bullets and detecting the collisions)
- ManejadorDisparos ("ShotManager"--> add the bullets to the List of bullets to be moved, moves the loist of bullets, creates the predefined bullet types to be used in the game)
- Disparo ("Shoot"--> Is the shot class, it has the position, direction, speed, and the bullet. Has the methods to move the bullet it has)
- Bullet (Is an inherited class from Object3d that has the damage, type, sounds to play)

The code and var names are in Spanish and the code is a kind of messy but any help would be very appreciated. Actually the shots are being fired with the control key or the space key. They are being shoot from a class called ManejadorEventos an the end of the method EventosJuego.
Nada por ahora

EgonOlsen

Judging from a quick look and fighting with spanish method and class names ( ;) ), it seems to me that your code assumes that an Object3D created from another one by new Object3D(<Object3D>) inherits its source's listeners. That's not the case. Try to add the listeners to the newly created bullet not just to the blue print.

Melssj5

#115
I am adding it to the new created bullet. I have a method on the Disparo class


public void setBulletListener (BulletListener BL) {
       bala.addCollisionListener(BL);
}


here I am adding the collition listener to the new created Bullet called "bala", bala is a global Bullet var inside the Disparo class.


Here on the ManejadorDisparos class, when I add a shot to the shot list I have:


public void addDisparo (SimpleVector pos, SimpleVector dir, int tipoBala, World mundo, Camera cam) {

Bullet bala=null;
if (tipoBala==Bullet.BULLET_BALA1) {
bala=new Bullet (bala1);
}
if (tipoBala==Bullet.BULLET_BALA2) {
bala=new Bullet (bala2);
}
if (tipoBala==Bullet.BULLET_MISIL1) {
bala=new Bullet (misil1);
}
if (tipoBala==Bullet.BULLET_MISIL2) {
bala=new Bullet (misil2);
}//CREATE THE BULLET
System.out.println ("Disparo AGREGADO EN POS: "+pos+" - DIR: "+dir);
Disparo D=new Disparo (pos, dir, SoundManager, bala, mundo, cam);
                          //SHOT CREATED WITH THE NEW BULLET
D.setBulletListener (ManejadorColisionesBalas);
                          //COLLISIONLISTENER ADDED TO THE NEW SHOT
disparos.add (D);
}



May it be due to my Bullet class is a subclass of Object3D and maybe is losing the capacity of firing events???? I am just guessing!
Nada por ahora

EgonOlsen

Yes, my fault...i didn't mean the listener but the collision mode. It won't be cloned either.

Melssj5

mmmmmmm Yes, I set The collision mode before constructing a new Bullet from the model. Well, I guess I should use a clone method the have an exact copy? I will set the CollisionMode after creating the bullet to see if it helps, I will post the results by tomorrow! Thanks a lot, and please replace the old version of my project beucasse that was a version in which nothing works! Hopefully I will finish the first realease of the game sooner. And of course after that I will have to spend some time modelling some good maps, spacecrafts, bullets, misiles, etc!
Nada por ahora

EgonOlsen

cloning is just another way to get the same effect as new Object3D(<Object3D>). Just set the mode afterwards. Maybe i should clone it too...i'm undecided... ???

Melssj5

Is the collisionMode keeped inside the world when serializing it?

Each tima a new player gets it, I send all the World from the server to the specified client. But I do not know if those objects inside that world will have the same collisionMode set on them.
Nada por ahora