Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Java Game APIs & Engines / Java 3D / Re: Help Rotating around a point plz on: 2005-04-28 16:51:10
i believe that everything below is relevant, what i need is for the barrel to rotate when the user presses up/down, but at the moment i am getting the following error:

Exception in thread "main" javax.media.j3d.MultipleParentException: Group.addChi
ld: child already has a parent
       at javax.media.j3d.GroupRetained.checkValidChild(GroupRetained.java:442)

       at javax.media.j3d.GroupRetained.addChild(GroupRetained.java:451)
       at javax.media.j3d.Group.addChild(Group.java:266)
       at Cannon.createBarrelBranch(Cannon.java:103)
       at Cannon.<init>(Cannon.java:48)
       at Cannon.main(Cannon.java:244)

i need to ahnd this in 2moro, i know i have no chance of finishing it but the rotation would be better than nothing, plz somebody help!!

=======================================

public class Cannon extends JFrame implements  KeyListener
{
     BasicUniverse universe;
     TransformGroup barrelTransform;
     
     double barrelAngle = 45;
     
     public Cannon( )
     {
             setSize(600, 600);
         GraphicsConfiguration graphicsConfig = SimpleUniverse.getPreferredConfiguration();
           Canvas3D canvas = new Canvas3D(graphicsConfig);
           getContentPane().add("Center", canvas);
           
           universe = new BasicUniverse(canvas, 15.0f);
           universe.addBranchGraph(createBarrelBranch());
           universe.addBranchGraph(createAxle());
           universe.addBranchGraph(createBall());
           universe.addBranchGraph(createCannonBase());
           universe.addBranchGraph(createAxleBase());
           
           setVisible(true);
           canvas.addKeyListener(this);  
     }
     
     public void keyPressed(KeyEvent ke)
     {
            System.out.println("Key Pressed");
              if (ke.getKeyCode() == KeyEvent.VK_UP) barrelAngle--;
         else if(ke.getKeyCode() == KeyEvent.VK_DOWN) barrelAngle++; // if you press ANY key besides up, the angle will increase!
         
         Transform3D rotateBarrel = new Transform3D();
           rotateBarrel.rotX(Math.toRadians(barrelAngle));        
           barrelTransform.setTransform(rotateBarrel);            
     }

     public void      keyReleased(KeyEvent e)      { }
     public void keyTyped(KeyEvent e) { }
       
           
     public BranchGroup createBarrelBranch( )
     {
           BranchGroup barrelBranch = new BranchGroup();
       barrelTransform = new TransformGroup();
           barrelTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
           barrelBranch.addChild(barrelTransform);
       
       ColoringAttributes color = null;
           color = new ColoringAttributes(
               new Color3f(BARREL_FILL_COLOR),
                       ColoringAttributes.NICEST);  
                       
         Appearance appearance = new Appearance();  
       appearance.setColoringAttributes(color);
       
       PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
       appearance.setPolygonAttributes(pa);
       
       Cylinder barrel = new Cylinder(BARREL_RADIUS, BARREL_LENGTH);
       barrel.setAppearance(appearance);
       
       Transform3D translateBarrel = new Transform3D();
       translateBarrel.setTranslation(new Vector3f (0.0f ,((BARREL_LENGTH/2) +(2 * CANNON_BASE_YRAD)) ,0.0f ));
       Transform3D transform = new Transform3D();
       Transform3D rotationOnZ = new Transform3D();
       rotationOnZ.rotZ(Math.toRadians(-barrelAngle));
       transform.mul(translateBarrel);
       transform.mul(rotationOnZ);
       barrelTransform.setTransform(transform);    
       barrelTransform.addChild(barrel);
       barrelBranch.addChild(barrelTransform);
       return barrelBranch;
   }
2  Java Game APIs & Engines / Java 3D / Re: Help Rotating around a point plz on: 2005-04-27 08:09:56
this is my entire Cannon class, which extends Basic Universe:

import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.Box;

public class Cannon extends JFrame
{
     Color3f BARREL_FILL_COLOR = new Color3f(0.0f, 0.0f, 1.0f);
     float BARREL_RADIUS = (float)0.3; // these are dimensions in meters and yours were FAR from being realistic
     float BARREL_LENGTH = (float)2.0;
     
     Color3f AXLE_FILL_COLOR = new Color3f(0.0f, 1.0f, 0.0f);
     float AXLE_RADIUS = (float)0.1; // these are dimensions in meters and yours were FAR from being realistic
     float AXLE_LENGTH = (float)1.0;
     float BALL_RADIUS = (float)0.5;
     Color3f BALL_FILL_COLOR = new Color3f(1.0f, 0.0f, 0.0f);
     Color3f BASE_FILL_COLOR = new Color3f(0.5f, 0.5f, 0.5f);
     
     Color3f CANNON_BASE_FILL_COLOR = new Color3f(0.2f, 0.2f, 0.2f);
     float CANNON_BASE_XDIM = 2.0f;
     float CANNON_BASE_YDIM = 1.5f;
     float CANNON_BASE_ZDIM = 2.0f;
     
     Color3f AXLE_BASE_FILL_COLOR = new Color3f(0.7f, 0.7f, 0.7f);
     float AXLE_BASE_XDIM = 1.0f;
     float AXLE_BASE_YDIM = 1.0f;
     float AXLE_BASE_ZDIM = 1.0f;
     
     BasicUniverse universe;
     
     public Cannon( )
     {
             setSize(600, 600);
         GraphicsConfiguration graphicsConfig = SimpleUniverse.getPreferredConfiguration();
           Canvas3D canvas = new Canvas3D(graphicsConfig);
           getContentPane().add("Center", canvas);
         universe = new BasicUniverse(canvas, 15.0f);// view from 15 meters?
           universe.addBranchGraph(createCannon());
           universe.addBranchGraph(createAxle());
           universe.addBranchGraph(createBall());
           universe.addBranchGraph(createCannonBase());
           universe.addBranchGraph(createAxleBase());
     }
           
     public BranchGroup createCannon( )
     {
           BranchGroup objRoot = new BranchGroup();
       
       
        Appearance apperance = new Appearance();
        ColoringAttributes color = null;

        color = new ColoringAttributes(
              new Color3f(BARREL_FILL_COLOR),
                       ColoringAttributes.NICEST);      
        apperance.setColoringAttributes(color);
        PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
        apperance.setPolygonAttributes(pa);
        Cylinder barrel = new Cylinder(BARREL_RADIUS, BARREL_LENGTH);
        barrel.setAppearance(apperance);
       
        Transform3D transform = new Transform3D();
        Transform3D rotationOnZ = new Transform3D(); // same as above
        rotationOnZ.rotZ(Math.toRadians(-45)); // rotate shape counter clockwise by 12 degrees
       
        transform.mul(rotationOnZ); // and after it has been modified, apply a second modification to it on the Z axis
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objTrans.setTransform(transform);    
        objTrans.addChild(barrel);
        objRoot.addChild(objTrans); // I ADDED THIS STATEMENT - you never did add anything to objRoot - it was returning nothing
        return objRoot;
     }
     
     public BranchGroup createAxle( )
     {
           BranchGroup objRoot = new BranchGroup();
        Transform3D translateAxle = new Transform3D();
        translateAxle.setTranslation(new Vector3f (-3.0f ,-0.2f ,0.0f ));
        Appearance apperance = new Appearance();
        ColoringAttributes color = null;

        color = new ColoringAttributes(
              new Color3f(AXLE_FILL_COLOR),
                       ColoringAttributes.NICEST);      
        apperance.setColoringAttributes(color);
        PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
        apperance.setPolygonAttributes(pa);
        Cylinder axle = new Cylinder(AXLE_RADIUS, AXLE_LENGTH);
        axle.setAppearance(apperance);
       
        Transform3D transform = new Transform3D();
        Transform3D rotationOnZ = new Transform3D(); // create identity transform (does nothing)
        rotationOnZ.rotZ(Math.toRadians(-90)); // change it so that it rotates shape forward by 45 degrees
        Transform3D rotationOnX = new Transform3D(); // same as above
        rotationOnX.rotX(Math.toRadians(90)); // rotate shape counter clockwise by 12 degrees
       
        transform.mul(rotationOnZ); // now go to the transform you will use in your branch group and modify it on the X axis
        transform.mul(rotationOnX); // and after it has been modified, apply a second modification to it on the Z axis
        transform.mul(translateAxle);
       
        TransformGroup objTrans = new TransformGroup();
        objTrans.setTransform(transform);  
        objTrans.addChild(axle);
        objRoot.addChild(objTrans); // I ADDED THIS STATEMENT - you never did add anything to objRoot - it was returning nothing
        return objRoot;
     }
     
     public BranchGroup createBall( )
     {
           BranchGroup objRoot = new BranchGroup();
        Appearance apperance = new Appearance();
        ColoringAttributes color = null;
        color = new ColoringAttributes(
              new Color3f(BALL_FILL_COLOR),
                       ColoringAttributes.NICEST);      
        apperance.setColoringAttributes(color);
        PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
        apperance.setPolygonAttributes(pa);
        Sphere ball = new Sphere(BALL_RADIUS);
        ball.setAppearance(apperance);
        objRoot.addChild(ball);
        return objRoot;
     }
     
   public BranchGroup createCannonBase( )
     {
           BranchGroup objRoot = new BranchGroup();
        Appearance apperance = new Appearance();
        ColoringAttributes color = null;
        color = new ColoringAttributes(
              new Color3f(CANNON_BASE_FILL_COLOR),
                       ColoringAttributes.NICEST);  
            apperance.setColoringAttributes(color);
        PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
        apperance.setPolygonAttributes(pa);
        Box cannonBase = new Box(CANNON_BASE_XDIM, CANNON_BASE_YDIM, CANNON_BASE_ZDIM, Primitive.GENERATE_TEXTURE_COORDS,new Appearance()); // what does this do?
        cannonBase.setAppearance(apperance);
        Transform3D translateBase = new Transform3D();
        translateBase.setTranslation(new Vector3f (1.0f , 0.0f , 0.0f )); // to the right 1m
        objRoot.addChild(cannonBase);
        return objRoot;
   }
   
   public BranchGroup createAxleBase( )
     {
           BranchGroup objRoot = new BranchGroup();
        Appearance apperance = new Appearance();
        ColoringAttributes color = null;
        color = new ColoringAttributes(
              new Color3f(AXLE_BASE_FILL_COLOR),
                       ColoringAttributes.NICEST);  
            apperance.setColoringAttributes(color);
        PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
        apperance.setPolygonAttributes(pa);
        Box axleBase = new Box(AXLE_BASE_XDIM, AXLE_BASE_YDIM, AXLE_BASE_ZDIM, Primitive.GENERATE_TEXTURE_COORDS,new Appearance()); // what does this do?
        axleBase.setAppearance(apperance);
        Transform3D translateBase = new Transform3D();
        translateBase.setTranslation(new Vector3f (1.0f , 0.0f , 0.0f )); // to the right 1m
        objRoot.addChild(axleBase);
        return objRoot;
   }
     
     
     
 private void exitForm(WindowEvent event)
 {
   System.exit(0);
 }


 public static void main(String args[])
 {
   Cannon cannon = new Cannon();
   cannon.show();
 }


====================================
Can anyone tell me why my xyz directions would not be correct, i.e. with the axle, i am translating to the left, however it doesnt go very far left, instead it goes really far on the y axis(straight up)...can anyone help me out?

if anyone ca help, i would like to get the axle base to sit on the cannon base, and then the axle to go through the cannon barrel, somewhere close to the base of the barrel so that it can be rotated around the axle, like a real cannon i guess!

thanks to anyone who can help
3  Java Game APIs & Engines / Java 3D / Re: Help Rotating around a point plz on: 2005-04-25 17:25:22
is there another forum that i can ask for help?
thanks
4  Java Game APIs & Engines / OpenGL Development / Re: Will there ever be LWJGL/OpenGL on mobiles/PDA on: 2005-04-25 10:54:31
can someone plz explain to me what an nio is plz, sorry but i am new to all this graphics stuff.

are you saying that opengl es is improving so that it may be possible in the future or that it may just be possible with opengl es and the latest pda's?

thanks
5  Java Game APIs & Engines / OpenGL Development / Will there ever be LWJGL/OpenGL on mobiles/PDA? on: 2005-04-24 21:34:28
Will a Java/OpenGL based computer game ever be available on mobiles/pda's?
i have just written a game using lwjgl and opengl and was wondering if a port would ever be possible?
please feel free to discuss

thanks
6  Java Game APIs & Engines / Java 3D / Re: Help Rotating around a point plz on: 2005-04-24 21:33:12
is no-one able to help?
7  Java Game APIs & Engines / Java 3D / Re: Help Rotating around a point plz on: 2005-04-21 18:29:10
after messing around for a bit i now have:

public class Cannon extends JFrame
{
     Color3f BARREL_FILL_COLOR = new Color3f(0.0f, 0.0f, 1.0f);
     Color3f AXLE_FILL_COLOR = new Color3f(1.0f, 0.0f, 0.0f);
     float BARREL_RADIUS = (float)0.3;
     float BARREL_LENGTH = (float)2.0;
     float AXLE_LENGTH = (float)1.0;
     float AXLE_RADIUS = (float)0.1;
     TransformGroup objTrans = new TransformGroup();
     
     public Cannon( )
     {
           initComponents( );
           setSize(600, 600);
           GraphicsConfiguration graphicsConfig = // screen setup
           SimpleUniverse.getPreferredConfiguration( );
           
           Canvas3D canvas = new Canvas3D(graphicsConfig);
           getContentPane( ).add("Center", canvas);
           BasicUniverse universe = new BasicUniverse(canvas, 8.0f); // view from 8m
           BranchGroup cannon = createCannon( );
           BranchGroup pivetAxle = createAxle( );
           universe.addBranchGraph(cannon);
           universe.addBranchGraph(pivetAxle);
     }
           
     public BranchGroup createCannon( )
     {
           Appearance appearance = new Appearance();
           ColoringAttributes barrelColor = null;
           BranchGroup objRoot = new BranchGroup();
       barrelColor = new ColoringAttributes(new Color3f(BARREL_FILL_COLOR),
                       ColoringAttributes.NICEST);      
        appearance.setColoringAttributes(barrelColor);
        Cylinder barrel = new Cylinder(BARREL_RADIUS, BARREL_LENGTH);
        barrel.setAppearance(appearance);
       objRoot.addChild(barrel);
       return objRoot;
   }
   
   public BranchGroup createAxle( )
   {
         Appearance appearance = new Appearance();
           ColoringAttributes axleColor = null;
           BranchGroup objRoot = new BranchGroup();
       axleColor = new ColoringAttributes(new Color3f(AXLE_FILL_COLOR),
                       ColoringAttributes.NICEST);      
        appearance.setColoringAttributes(axleColor);
        Cylinder axle = new Cylinder(AXLE_RADIUS, AXLE_LENGTH);
        axle.setAppearance(appearance);
       objRoot.addChild(axle);
       return objRoot;
   }
   
   public void rotateAxle( )
   {
         Transform3D t3d = new Transform3D();
       // negative rotation so we go clockwise
       t3d.rotZ(Math.toRadians(-90));
       objTrans.setTransform(t3d);
   }

i am trying to rotate the axle so that it goes into the screen, i.e. points along the z axis, so that the axle can be placed through the barrel, i then want the barrel to rotate around the axle,

can someone plz help me out as i dont know what code i need to achieve this,
thanks
8  Java Game APIs & Engines / Java 3D / Help Rotating around a point plz on: 2005-04-21 17:47:16
I have the following to draw a barrel:

public BranchGroup createCannon( )
     {
           Appearance appearance = new Appearance();
           ColoringAttributes color = null;
           BranchGroup objRoot = new BranchGroup();
       color = new ColoringAttributes(new Color3f(BARREL_FILL_COLOR),
                       ColoringAttributes.NICEST);      
        appearance.setColoringAttributes(color);
        Cylinder barrel = new Cylinder(BARREL_RADIUS, BARREL_LENGTH);
        barrel.setAppearance(appearance);
       objRoot.addChild(barrel);
       return objRoot;
   }

could someone plz help me with coding a method that will check for the user pressing the up or down arrow which will swivel the barrel around a fixed point, 1m from the base,

just trying to play about with some java3d, see if it could be used to simulate things

thanks, much appreciated Smiley
9  Java Game APIs & Engines / Java Sound & OpenAL / Re: starting out with openal on: 2005-03-15 22:17:24
have sorted this now, thanks for all the help
10  Java Game APIs & Engines / Java Sound & OpenAL / Re: starting out with openal on: 2005-03-15 18:30:46
oh i didnt realize there was a difference, is one better than the other? are there tutorials or code snippets out there for using the openal in lwjgl, i don have that installed so should my code have compiled if i have this?
thanks
11  Java Game APIs & Engines / Java Sound & OpenAL / starting out with openal on: 2005-03-15 17:57:11
i am trying to lear openal using java, lwjgl actually, cannot seem to get the following to compile which i think is just some introductary basic code:

import net.java.games.joal.*;
import net.java.games.joal.util.*;
import java.io.*;
import java.nio.ByteBuffer;

public class Sound {

static AL al = ALFactory.getAL();

// Buffers hold sound data.
static int[] buffer = new int[1];;

// Sources are points emitting sound.
static int[] source = new int[1];
}


i get:

--------------------Configuration: JDK version 1.5.0_01 <Default>--------------------
C:\Documents and Settings\Danny\Desktop\Version2.0.13\Version2.0.7\Version2.0.5\Version2.0.5\Sound.java:1: package net.java.games.joal does not exist
import net.java.games.joal.*;
^
C:\Documents and Settings\Danny\Desktop\Version2.0.13\Version2.0.7\Version2.0.5\Version2.0.5\Sound.java:2: package net.java.games.joal.util does not exist
import net.java.games.joal.util.*;
^
C:\Documents and Settings\Danny\Desktop\Version2.0.13\Version2.0.7\Version2.0.5\Version2.0.5\Sound.java:8: cannot find symbol
symbol : class AL
location: class Sound
static AL al = ALFactory.getAL();
^
C:\Documents and Settings\Danny\Desktop\Version2.0.13\Version2.0.7\Version2.0.5\Version2.0.5\Sound.java:8: cannot find symbol
symbol : variable ALFactory
location: class Sound
static AL al = ALFactory.getAL();
^
4 errors

Process completed.

any ideas, i'm sorry but i am a total newbie Sad
12  Java Game APIs & Engines / OpenGL Development / Re: Anyone able to get Timer working on: 2005-03-11 20:13:59
anyone had any luck with the timer??

    public long currentTimeMillis()
    {
          timer.tick();
          System.out.println("Timer = " + timer.getTime());
          return (long) (timer.getTime()*1000f);
       }

produces some weird results, i thought it might increment but it seems to pass between negatives and positives! :p

can the timer be used to move objects at a constant rate, and by varying it, speed them up?
thanks
13  Java Game APIs & Engines / OpenGL Development / Anyone able to get Timer working on: 2005-03-11 18:24:10
do i need a new version to use org.lwjgl.util.Timer???
package cannot be found, anyone else get this or do i need a new lwjgl??
thanks
14  Java Game APIs & Engines / OpenGL Development / Help a newbie with textures on: 2005-03-11 06:55:09
could someone plz help me load textures onto my models that i have loaded into my game. i store the vertices in a floatbuffer that have been loaded from a raw file, so the models load ok.
but i have no idea how to put textures onto my models, one of the models had a texture when loaded in 3ds but none in rhino so i dont know where that texture is.
anyway, any texture will do but i need it to look graphically good with lighting thats all
thanks
Danny
15  Java Game APIs & Engines / OpenGL Development / Re: Printing fonts on: 2005-03-02 03:25:16
ye, sorry i just did:
String scoreString = Integer.toString(playerScore);
           glPrint("Player Score = " + scoreString);
cant believe i looked in the string part of the api and not the integer,
silly me Cheesy
16  Java Game APIs & Engines / OpenGL Development / Printing fonts on: 2005-03-01 18:58:15
How can i get the following to print
glPrint(playerScore);
if glPrint requires a string and playerScore is of type int
the glPrint method is from lesson 13 of neHe's tutorials
thanks
Danny Smiley
17  Java Game APIs & Engines / OpenGL Development / Re: Could anyone plz help me finish a sentence on: 2005-02-21 18:00:39
I was hoping for something on the lines of, very easy to set up the window and the basic game loop, i.e getting the basics working, or... very difficult to initailise and set up the window and the initial openGL effects etc etc
thanks
18  Java Game APIs & Engines / OpenGL Development / Could anyone plz help me finish a sentence on: 2005-02-21 17:19:40
Initial results have shown that LWJL is a good (or bad) environment for Java Game development because ....

if anyone has made game using lwjgl coud you plz give me your view i.e how you would finish the sentence
thanks to all who reply
Danny Smiley

19  Java Game APIs & Engines / Java Sound & OpenAL / ***OpenAL*** on: 2005-02-11 08:36:01
Hi, I am attempting to write a report on OpenAl and its uses in games, is there any documentation that discusses the history of OpenAL and its uses today?
thanks
Daniel
20  Discussions / General Discussions / ***Java Games History*** on: 2005-02-10 13:34:22
Hi,i am writing a report which needs to include a bit of history of making games using java,lwjgl,& jogl,openGL and openAL, are there any docs or sites that are any good for any of these plz?
thanks
Danny
21  Java Game APIs & Engines / OpenGL Development / Re: OpenGL: C vs Java on: 2005-02-04 08:05:46
"Language Nuances. Each language may have slightly different ways of passing data around. Buffers for instance in LWJGL. "

can you tell me how C differs, passing data around?
thanks
22  Java Game APIs & Engines / OpenGL Development / OpenGL: C vs Java on: 2005-02-03 17:37:34
Hi guys, have been asked to answer a question and am hoping that a few of you may have an answer plz as it is relevant to openGL, thanks:
OpenGL was originally developed for use with the C programming language. What are the options for using OpenGL with other languages such as Java? Are there any issues e.g. speed of Java vs C?>
thanks to all who reply Smiley
23  Java Game APIs & Engines / OpenGL Development / LWJGL vs Jogl on: 2005-02-03 17:35:19
Is there any links to a thread that has comparisons between these two api's? i wish to produce a table that shows differences, advantages, disadvantages of each language, as i am using lwjgl i am hoping that it has more advantages. oh yes and the context of this question is in relation to making games but all advantages and disadvantages are welcome, thanks guys
24  Java Game APIs & Engines / OpenGL Development / Re: Model positioning problems on: 2004-12-15 08:01:34
It works, thanks so much!!! Smiley
25  Java Game APIs & Engines / OpenGL Development / Re: Model positioning problems on: 2004-12-14 23:18:17
thanks for the reply mate. changed the x value and it moved further right, changed the y and it moved higher, changed the z and it came closer so i think they are correct and unfortunately multiplying by higher numbers didn't have an effect Sad
any other idea will be greatly appreciated
thanks
26  Java Game APIs & Engines / OpenGL Development / Re: Model positioning problems on: 2004-12-14 21:55:35
Here is the relevant code from the classes incase some of you could spot the problem at a glance:
the alien class:
public Alien(float tempXCoord,float tempYCoord,float tempZCoord,boolean tempIsAlive)
{
xAlien = tempXCoord;
yAlien = tempYCoord;
zAlien = tempZCoord;
alienIsAlive = tempIsAlive;
}

public void renderTheAliens()
{
renderAliens();
}

/**
* Render a collection of aliens to the screen using the GL commands
* and the buffer we've read from the RAW file.
*/
private void renderAliens()
{
if (alienIsAlive) {
//GL11.glLoadIdentity();
GL11.glPushMatrix();                  
GL11.glTranslatef(xAlien,yAlien,zAlien); //move forward
renderAlien();
GL11.glPopMatrix();
}
}

public void update(int direction) {
//if System.timieMillis() - lasUpdateTime > 300 {
if(direction==0)
{
xAlien -=0.01f;
}
else if(direction==1)
{
xAlien +=0.01f;
}
}

/**
* Render a single alien to the screen
*/
private void renderAlien() {
//System.out.println("drawing aliens: ");

GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(3, 0, alienData);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, coords.size() / 3);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
}

and here is the code from the main class:

private boolean render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
GLU.gluLookAt(0,20,80, 0,0,0, 0,1,0);

//GL11.glTranslatef(moveOnX,0.0f,0.0f); //Move the aliens left/right
//GL11.glTranslatef(0.0f,0.0f,moveOnZ); //Move the aliens toward/away

for (int x = 0;x<aliens.length;x++) {
aliens
  • .renderTheAliens();
    }
    return true;
    }

    private void init() throws Exception {
    createWindow();
    Keyboard.create();
    initGL();

    Alien.loadTheRawFile();
    createAliens();
    }

    private void createAliens()
    {
    aliens = new Alien[18];
    for (int x = 0;x<6;x++)
    {
    for (int y = 0;y<3;y++)
    {
    aliens[(y*6)+x] = new Alien((float)x*4,0.0f, (float)y*3, IS_ALIVE);
    }
    }
    }
    private Alien aliens[];

    I am a newbie and I hope no-one minds me asking but i've been stuck on this for days and it would be nice to carry on with the movement of the models
    thanks
27  Java Game APIs & Engines / OpenGL Development / Re: Model positioning problems on: 2004-12-14 13:21:26
found out that maybe i should have the following included thanks to Enigma off another forum:
private void renderAliens()
{
     if (alienIsAlive) {
           GL11.glPushMatrix();
           GL11.glTranslatef(xAlien,yAlien,zAlien); //move forward
           renderAlien();
           GL11.glPopMatrix();
     }
}


Since translating moves the origin and not just the alien, so if you make multiple translation calls they add up. By pushing and popping the matrix you restore the old matrix after drawing each alien so the translations are independent.

unfortunately all i am seeing when i run it now is one alien.
i know that all of the aliens are created though and that their xyz
is correct as i have put trace write's in the alien constructor and each
xyz seems correct.
any ideas?
28  Java Game APIs & Engines / OpenGL Development / Model positioning problems on: 2004-12-14 08:59:16
Hi guys, I have majorly hit a brick wall with this space invaders of mine. I had my models loaded fine, and all the aliens were in rows and moved together. But now that i have to make a seperate class for the aliens, using a constructor etc, when i draw the aliens to the screen they are not placed in rows anymore.
I'm hoping that one of you guys/gals would be kind enough to have a look at my code for me and see if you can fix it so that they are placed in rows, like space invaders should be.
I have spent days on this and I just cant spot the problem, but one of you would probably be able to fix it in 5 minutes.
So if any of you have five minutes and are kind enough to have a look at my code for me, mail me and I will send it to you.
Thanks everyone
Danny
29  Java Game APIs & Engines / OpenGL Development / Re: 3d model texture/colour laoding problems-plz h on: 2004-12-01 07:16:41
i have my alien stored in a float buffer as i got the vertices from a raw file but it would be great if i could use something else just to load in the colours maybe, would it work?? i dont want to use a whole package unless i really have to
thanks guys Smiley
30  Java Game APIs & Engines / OpenGL Development / 3d model texture/colour laoding problems-plz help on: 2004-11-30 18:06:17
Hi all,
I am trying to load a 3ds file into an opengl window using lwjgl. Unfortunately I have not been given much time to do this so I have not got the time to learn as much as I would like about opengl and lwjgl before i start this, i have to jump straight in really, I have no choice icon_sad.gif
Anyway, I have managed to output the vertices by outputting to a raw file and I have managed to store these in an array and I can get the model to display. Now this is where my problems begin!

If I load the 3ds model using 3d studio max then it loads up textures, colours everything, just the way that my model alien should look but unfortunately if I load it up in Rhino which is what I'm using then no colours are displayed, only the mesh icon_sad.gif

Anyway, I was thinking that I could set the colour of the vertices as I'm drawing them but I would lose marks for this as it's a crap way of doing it. So basically I'm hoping that anyone could please help me out and tell me if there is code out there that I could use to either get my model from 3dsmax into my window and remember all of the vertex information so I know where each alien is,
OR if i there is a way that I could colour the model myself in rhino and then somehow export this data and load it into my lwjgl code
OR if I would be better off just using the jmonkey engine.
the jmonkey engine looks great but the thing is I am doing a final year project on making a game using lwjgl and if i use jmonkey then i think i might get crap marks as it does everything for me.

I need to somehow just get the code to do what i want otherwise i will just have to use jmonkey and say that i couldn't do it, I am not very good at opengl i will admit but i would really like to get this done.

If it cant be done though as I have tried loads of ideas such as outputting as obj file and such, with no luck, then i would like to know off someone who knows the capabilities but i'm hoping that someone will step in to save my skin.

Anyway if it can be done or if there is code, please please let me know, otherwise plz let me know and i'll use jmonkey, probably lose laods of marks but at least it will be completed

i am not asking anyone to do my project before anyone says that, all i want to know is what is the best approach, thanks everyone

Thanks to everyone who replies
Danny icon_smile.gif
Pages: [1] 2
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (10 views)
2014-11-28 16:25:09

PocketCrafter7 (11 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (67 views)
2014-11-26 15:20:36

toopeicgaming1999 (17 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!