Jump to content
• Advertisement

# cicerohellmann

Member

8

100 Neutral

• Rank
Newbie
1. ## JOGL Enemy Space Ship dont point correctly to the player, HELP!

Fking thank you : ) im doing a game development course but they didnt gave me a good mathematic base... and im getting raped, im good at the game craft art im just not good with math..since this 2 are very close to each other i may be not the best as i thought
2. ## Fun With Vectors & Matrices

i forget the line that i use to reflect the player moviment MathUtil.rotacionaGLViaVetores(Player.eixoZ, Player.eixoY, Player.eixoX);
3. ## Fun With Vectors & Matrices

And i can do this in 2 forms, using a rotate angle funciont that rotate my ship and pint to the 3 vector angles i use OR doing like i do in the player ,using moviment functions and testing colisions to the axis i should turn. [size=2][color=#000000] [color=#000088]if[color=#666600]([color=#660066]Player[color=#666600].[color=#000000]X[color=#666600]>[color=#000088]this[color=#666600].[color=#000000]X[color=#666600]+[color=#006666]0.5[color=#666600]){[color=#000000] rotAngleY [color=#666600]=[color=#000000] [color=#666600]([color=#000088]float[color=#666600])[color=#000000] [color=#666600]-[color=#006666]1[color=#666600];[color=#000000] [color=#660066]Matrix4x4[color=#000000] k [color=#666600]=[color=#000000] [color=#000088]new[color=#000000] [color=#660066]Matrix4x4[color=#666600]();[color=#000000] k[color=#666600].[color=#000000]setRotate[color=#666600]([color=#000000]rotAngleY[color=#666600],[color=#000000] eixoY[color=#666600].[color=#000000]x[color=#666600],[color=#000000] eixoY[color=#666600].[color=#000000]y[color=#666600],[color=#000000] eixoY[color=#666600].[color=#000000]z[color=#666600]);[color=#000000] k[color=#666600].[color=#000000]transform[color=#666600]([color=#000000]eixoZ[color=#666600]);[color=#000000] k[color=#666600].[color=#000000]transform[color=#666600]([color=#000000]eixoY[color=#666600]);[color=#000000] k[color=#666600].[color=#000000]transform[color=#666600]([color=#000000]eixoX[color=#666600]);[color=#000000] eixoZ[color=#666600].[color=#660066]Normalize[color=#666600]();[color=#000000] eixoY[color=#666600].[color=#660066]Normalize[color=#666600]();[color=#000000] eixoX[color=#666600].[color=#660066]Normalize[color=#666600]();[color=#000000] [color="#666600"]} this is like i do in the player, my math is probably wrong but when the guy is far from a certain position i turn my ship in the right axis, thats what is do! the other way i have, and ive used to fake a true pointing, is to use the player axis to reflect his axis, actualy look very strange, cause if i move my ship the eneme do litle moves too...this other way is under my rotation funcion. i'll give to you guys this rotacionaGLViaVetores that mean rotateGLUsingVectors public static void rotacionaGLViaVetores(Vector3f frontV,Vector3f rightV,Vector3f upV){ float[] matriz = new float[16]; matriz[0] = upV.x; matriz[1] = upV.y; matriz[2] = upV.z; //------------------ matriz[4] = rightV.x; matriz[5] = rightV.y; matriz[6] = rightV.z; //------------------ matriz[8] = frontV.x; matriz[9] = frontV.y; matriz[10] = frontV.z; //------------------ matriz[3] = matriz[7] = matriz[11] = matriz[12] = matriz[13] = matriz[14] = 0.0f; matriz[15] = 1.0f; // float[] -> matrix de rotacao // int -> offset(primeiro representante da matrix) FloatBuffer fb = BufferUtils.createFloatBuffer(16); fb = (FloatBuffer)fb.put(matriz).flip(); glMultMatrix(fb); }
4. ## Fun With Vectors & Matrices

My problem isnt realy to orientate the shipd in the space, i dont know how to make it point to my player ship... i use axis i have my own matrix libary
5. ## Fun With Vectors & Matrices

OK, im posting my enemy class! its not completly in english but i beleave u guys can understand, if not i can translate import static org.lwjgl.opengl.GL11.glColor4f; import static org.lwjgl.opengl.GL11.glPopMatrix; import static org.lwjgl.opengl.GL11.glPushMatrix; import static org.lwjgl.opengl.GL11.glRotatef; import static org.lwjgl.opengl.GL11.glScaled; import static org.lwjgl.opengl.GL11.glTranslatef; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GLContext; import matematcbase.MathUtil; import matematcbase.Matrix4x4; import matematcbase.Vector3f; import obj.ObjModel; public class Inimigo extends Entidade { public final static short MOVENDOSE_ALEATORIAMENTE = 0; public final static short AGRUPANDO = 1; public final static short MOVENDO_E_ATIRANDO = 2; public final static short FUGINDO = 3; public short estado = 0; ObjModel meuModelo; Vector3f vetorDeAproximacao; boolean tomoChumbo = false; // Tiro tiro; float mx, my; boolean freeMotion = true; public static float playerAlpha = 1.0f; int loadTiro = 0; public static float velRotation = 190.0f; Player playerQueDevoMatar; boolean teste = true; int tempo = 0; public Inimigo(float X, float Y, float Z, float raio, float velX, float velY, float velZ, String modeloDaNaveDoInimigo, Player player) { super(X, Y, Z, raio, velX, velY, velZ); // TODO Auto-generated constructor stub meuModelo = new ObjModel(); meuModelo.loadObj(modeloDaNaveDoInimigo); playerQueDevoMatar = player; vetorDeAproximacao = new Vector3f(); vivo = true; vida = 100; estado = MOVENDO_E_ATIRANDO; } void rotacionaEixos() { } public void movimentacao(double diftime) { if(Player.X>this.X+0.5){ rotAngleY = (float) -1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleY, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } if(Player.X<this.X-0.5){ rotAngleY = (float) 1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleY, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } if(Player.Y>this.Y+0.5){ rotAngleX = (float) -1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleX, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } if(Player.Y<this.Y-0.5){ rotAngleX = (float) 1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleX, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } // rotAngleX = (float) 1; // Matrix4x4 k = new Matrix4x4(); // k.setRotate(rotAngleX, eixoX.x, eixoX.y, eixoX.z); // k.transform(eixoZ); // k.transform(eixoY); // k.transform(eixoX); // eixoZ.Normalize(); // eixoY.Normalize(); // eixoX.Normalize(); // // movimenta para a esquerda e direita // rotAngleY = (float) 1; // Matrix4x4 m = new Matrix4x4(); // m.setRotate(rotAngleY, eixoY.x, eixoY.y, eixoY.z); // m.transform(eixoZ); // m.transform(eixoY); // m.transform(eixoX); // eixoZ.Normalize(); // eixoY.Normalize(); // eixoX.Normalize(); } public void IA(double Difftime) { switch (estado) { case MOVENDOSE_ALEATORIAMENTE: break; case AGRUPANDO: break; case MOVENDO_E_ATIRANDO: // // X += vetorDeAproximacao.x * velX * Difftime / 1000.0f; // Y += vetorDeAproximacao.y * velY * Difftime / 1000.0f; // Z += vetorDeAproximacao.z * velZ * Difftime / 1000.0f; // // X += vetorDeAproximacao.x *eixoZ.x * velX * Difftime / 1000.0f; // Y += vetorDeAproximacao.y *eixoZ.y * velY * Difftime / 1000.0f; // Z += vetorDeAproximacao.z * eixoZ.z * velZ * Difftime / 1000.0f; // if(vetorDeAproximacao.x > eixoX.x){ // rotAngleZ = -(float) (90 * Difftime / 1000.0f); // Matrix4x4 m = new Matrix4x4(); // m.setRotate(rotAngleZ, eixoY.x, eixoY.y, eixoY.z); // m.transform(eixoZ); // m.transform(eixoY); // m.transform(eixoX); // eixoZ.Normalize(); // eixoY.Normalize(); // eixoX.Normalize(); // } if (colideCicrular(vetorDeAproximacao.x, vetorDeAproximacao.y, vetorDeAproximacao.z, 1.0f)) { encontraVetorDeAproximacao(); } break; case FUGINDO: break; } } @Override void simulaSe(double Diftime) { // TODO Auto-generated method stub // super.simulaSe(Diftime); tempo++; movimentacao(Diftime); if (playerQueDevoMatar.listaDeTiros != null) { for (int i = 0; i < playerQueDevoMatar.listaDeTiros.size(); i++) { Tiro tiro = (Tiro) playerQueDevoMatar.listaDeTiros.get(i) ; if(colideCicrular(tiro.X, tiro.Y, tiro.Z, tiro.raio)) { tomoChumbo = true; vida -= 50; playerQueDevoMatar.listaDeTiros.remove(i); }else{ tomoChumbo = false; } } } if (playerQueDevoMatar.listaDeMisseis != null) { for (int i = 0; i < playerQueDevoMatar.listaDeMisseis.size(); i++) { Missil missil = (Missil) playerQueDevoMatar.listaDeMisseis.get(i) ; if(colideCicrular(missil.X, missil.Y, missil.Z, missil.raio)) { tomoChumbo = true; vida -= 100; missil.timer=missil.tempoDaExplosão+1; }else{ tomoChumbo = false; } } } if(vida <= 0) { X = 10 - (float) (Math.random()*20); Y = 10 - (float) (Math.random()*20); Z = 10 - (float) (Math.random()*20); vida = 100; } switch (estado) { case MOVENDOSE_ALEATORIAMENTE: break; case AGRUPANDO: break; case MOVENDO_E_ATIRANDO: // if (teste) { // sÃ³ pra procurar na primeira iteraÃ§Ã£o da classe. encontraVetorDeAproximacao(); teste = false; // break; case FUGINDO: break; } IA(Diftime); } @Override void desenhaSe() { // TODO Auto-generated method stub glPushMatrix(); { glTranslatef(X, Y, Z); glScaled(0.005f, 0.005f, 0.005f); glRotatef(180, 0, 0, 0); MathUtil.rotacionaGLViaVetores(Player.eixoZ, Player.eixoY, Player.eixoX); meuModelo.desenhase(); } glPopMatrix(); } void encontraVetorDeAproximacao() { vetorDeAproximacao.x = Player.X - this.X; vetorDeAproximacao.y = Player.Y - this.Y; vetorDeAproximacao.z = Player.Z - this.Z; vetorDeAproximacao.Normalize(); } public boolean colideCicrular(float x, float y, float z, float Raio) { float difx = x - this.X; float dify = y - this.Y; float difz = z - this.Z; float dist = difx * difx + dify * dify + difz * difz; if (((Raio + this.raio) * (Raio + this.raio)) > dist) { return true; } return false; } public void trataMorte(Player player) { } }
6. ## Fun With Vectors & Matrices

forget to add, is in 3D... 2D is a kind of easy when u just deal with angles but when u use axis the story change!
7. ## Fun With Vectors & Matrices

OK, you guys may have my answer too! I need to rotate an object some way that itll be always facing another object ( my objects are ships ), like the enemy hunting the player, how should i do that? My brain is melting and im not very good in math and i cant read too much about the topic right now its some kind of urgent implementation!!! ty for the attention.
8. ## JOGL Enemy Space Ship dont point correctly to the player, HELP!

I have a big problem when im trying to point my enemy ships to the player, im braking my head to find an answer and i know its right in front of me but i cant see it! i F SOME ONE HAVE ANY CLUES OUT THERE ILL BE GLAD TO HEAR AND + i suck in math so this can be the big deal with my problem... ok down there is my whole enemy code! take a look and ask anything you guys want! the enemy already go to the player location but i did some pog to make it turn to the player... the enemy, as the player, rotate in 3 axis and this axis are 3x3 vectors what i need to know exactly is what axis i should set here MathUtil.rotacionaGLViaVetores(Player.eixoZ, Player.eixoY, Player.eixoX); what is the math i should do to find the position of the player in the world ( i know how to do that ) and how to calculate the axis for this rate math funcion! import static org.lwjgl.opengl.GL11.glColor4f; import static org.lwjgl.opengl.GL11.glPopMatrix; import static org.lwjgl.opengl.GL11.glPushMatrix; import static org.lwjgl.opengl.GL11.glRotatef; import static org.lwjgl.opengl.GL11.glScaled; import static org.lwjgl.opengl.GL11.glTranslatef; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GLContext; import matematcbase.MathUtil; import matematcbase.Matrix4x4; import matematcbase.Vector3f; import obj.ObjModel; public class Inimigo extends Entidade { public final static short MOVENDOSE_ALEATORIAMENTE = 0; public final static short AGRUPANDO = 1; public final static short MOVENDO_E_ATIRANDO = 2; public final static short FUGINDO = 3; public short estado = 0; ObjModel meuModelo; Vector3f vetorDeAproximacao; boolean tomoChumbo = false; // Tiro tiro; float mx, my; boolean freeMotion = true; public static float playerAlpha = 1.0f; int loadTiro = 0; public static float velRotation = 190.0f; Player playerQueDevoMatar; boolean teste = true; int tempo = 0; public Inimigo(float X, float Y, float Z, float raio, float velX, float velY, float velZ, String modeloDaNaveDoInimigo, Player player) { super(X, Y, Z, raio, velX, velY, velZ); // TODO Auto-generated constructor stub meuModelo = new ObjModel(); meuModelo.loadObj(modeloDaNaveDoInimigo); playerQueDevoMatar = player; vetorDeAproximacao = new Vector3f(); vivo = true; vida = 100; estado = MOVENDO_E_ATIRANDO; } void rotacionaEixos() { } public void movimentacao(double diftime) { if(Player.X>this.X+0.5){ rotAngleY = (float) -1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleY, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } if(Player.X<this.X-0.5){ rotAngleY = (float) 1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleY, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } if(Player.Y>this.Y+0.5){ rotAngleX = (float) -1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleX, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } if(Player.Y<this.Y-0.5){ rotAngleX = (float) 1; Matrix4x4 k = new Matrix4x4(); k.setRotate(rotAngleX, eixoY.x, eixoY.y, eixoY.z); k.transform(eixoZ); k.transform(eixoY); k.transform(eixoX); eixoZ.Normalize(); eixoY.Normalize(); eixoX.Normalize(); } // rotAngleX = (float) 1; // Matrix4x4 k = new Matrix4x4(); // k.setRotate(rotAngleX, eixoX.x, eixoX.y, eixoX.z); // k.transform(eixoZ); // k.transform(eixoY); // k.transform(eixoX); // eixoZ.Normalize(); // eixoY.Normalize(); // eixoX.Normalize(); // // movimenta para a esquerda e direita // rotAngleY = (float) 1; // Matrix4x4 m = new Matrix4x4(); // m.setRotate(rotAngleY, eixoY.x, eixoY.y, eixoY.z); // m.transform(eixoZ); // m.transform(eixoY); // m.transform(eixoX); // eixoZ.Normalize(); // eixoY.Normalize(); // eixoX.Normalize(); } public void IA(double Difftime) { switch (estado) { case MOVENDOSE_ALEATORIAMENTE: break; case AGRUPANDO: break; case MOVENDO_E_ATIRANDO: // // X += vetorDeAproximacao.x * velX * Difftime / 1000.0f; // Y += vetorDeAproximacao.y * velY * Difftime / 1000.0f; // Z += vetorDeAproximacao.z * velZ * Difftime / 1000.0f; // // X += vetorDeAproximacao.x *eixoZ.x * velX * Difftime / 1000.0f; // Y += vetorDeAproximacao.y *eixoZ.y * velY * Difftime / 1000.0f; // Z += vetorDeAproximacao.z * eixoZ.z * velZ * Difftime / 1000.0f; // if(vetorDeAproximacao.x > eixoX.x){ // rotAngleZ = -(float) (90 * Difftime / 1000.0f); // Matrix4x4 m = new Matrix4x4(); // m.setRotate(rotAngleZ, eixoY.x, eixoY.y, eixoY.z); // m.transform(eixoZ); // m.transform(eixoY); // m.transform(eixoX); // eixoZ.Normalize(); // eixoY.Normalize(); // eixoX.Normalize(); // } if (colideCicrular(vetorDeAproximacao.x, vetorDeAproximacao.y, vetorDeAproximacao.z, 1.0f)) { encontraVetorDeAproximacao(); } break; case FUGINDO: break; } } @Override void simulaSe(double Diftime) { // TODO Auto-generated method stub // super.simulaSe(Diftime); tempo++; movimentacao(Diftime); if (playerQueDevoMatar.listaDeTiros != null) { for (int i = 0; i < playerQueDevoMatar.listaDeTiros.size(); i++) { Tiro tiro = (Tiro) playerQueDevoMatar.listaDeTiros.get(i) ; if(colideCicrular(tiro.X, tiro.Y, tiro.Z, tiro.raio)) { tomoChumbo = true; vida -= 50; playerQueDevoMatar.listaDeTiros.remove(i); }else{ tomoChumbo = false; } } } if (playerQueDevoMatar.listaDeMisseis != null) { for (int i = 0; i < playerQueDevoMatar.listaDeMisseis.size(); i++) { Missil missil = (Missil) playerQueDevoMatar.listaDeMisseis.get(i) ; if(colideCicrular(missil.X, missil.Y, missil.Z, missil.raio)) { tomoChumbo = true; vida -= 100; missil.timer=missil.tempoDaExplosão+1; }else{ tomoChumbo = false; } } } if(vida <= 0) { X = 10 - (float) (Math.random()*20); Y = 10 - (float) (Math.random()*20); Z = 10 - (float) (Math.random()*20); vida = 100; } switch (estado) { case MOVENDOSE_ALEATORIAMENTE: break; case AGRUPANDO: break; case MOVENDO_E_ATIRANDO: // if (teste) { // sÃ³ pra procurar na primeira iteraÃ§Ã£o da classe. encontraVetorDeAproximacao(); teste = false; // break; case FUGINDO: break; } IA(Diftime); } @Override void desenhaSe() { // TODO Auto-generated method stub glPushMatrix(); { glTranslatef(X, Y, Z); glScaled(0.005f, 0.005f, 0.005f); glRotatef(180, 0, 0, 0); MathUtil.rotacionaGLViaVetores(Player.eixoZ, Player.eixoY, Player.eixoX); meuModelo.desenhase(); } glPopMatrix(); } void encontraVetorDeAproximacao() { vetorDeAproximacao.x = Player.X - this.X; vetorDeAproximacao.y = Player.Y - this.Y; vetorDeAproximacao.z = Player.Z - this.Z; vetorDeAproximacao.Normalize(); } public boolean colideCicrular(float x, float y, float z, float Raio) { float difx = x - this.X; float dify = y - this.Y; float difz = z - this.Z; float dist = difx * difx + dify * dify + difz * difz; if (((Raio + this.raio) * (Raio + this.raio)) > dist) { return true; } return false; } public void trataMorte(Player player) { } }
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!