Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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]
1  Java Game APIs & Engines / Java 3D / GL4Java- X,Y,Z on: 2003-06-05 13:45:37
I want to use the mouse to rotate my object.  I'm using  gluPerspective, how do I get my x,y,z values.  I can't use evt.getX because that is the coordinates of the canvas.  Can someone please help!!!!!!!!!!!
2  Java Game APIs & Engines / Java 3D / GL4Java- Rotation Problem.....HELP!!! on: 2003-06-02 13:19:28
I am trying to rotate my object using the mouse.  I am passing the values of x and y to my variables and using them in the gl.glRotatef(...,...,...).  I thought this was an accurate way of creating the rotation, however when I rotate the texture of my object gets distorted and when I ran it on the Mac the object(sphere w/texture) didn't rotate but everything else in the scene did.  Can someone please tell me what I'm doing wrong?
3  Java Game APIs & Engines / Java 3D / GL4Java on: 2003-05-29 17:26:49
I have a method objZoom that I use to pass the values from my gui to the glTranslate in the z position.  However, if I set the gui value to 6000 or below the image is upside down.  I tried doing an if statement and in there scaling the object but that doesn't work.  Can anyone assist?

//------------------------------------------------------------------------------
// void distance_textfield_actionPerformed(ActionEvent e)
//------------------------------------------------------------------------------
void distance_textfield_actionPerformed(ActionEvent e){

  String x = distance_textfield.getText();
  try{
    view= Float.parseFloat(x);
    //System.out.println(viewDistance);
    canvas.objZoom(view);
    canvas.repaint();
  }
  catch(NumberFormatException n){
    JOptionPane.showMessageDialog(null,x + "is an invalid entry","Error Occurred", JOptionPane.ERROR_MESSAGE);
  }
}


//------------------------------------------------------------------------------
// void objZoom
//------------------------------------------------------------------------------
public void objZoom(float viewDistance){
  if(viewDistance < 6000){
    gl.glScalef(0.0f,1.0f,0.0f);
    pos_z = -viewDistance;
  }
  else
    pos_z = -viewDistance;
    //gl.glTranslatef(pos_x,pos_y,pos_z);
}
4  Java Game APIs & Engines / Java 3D / GL4Java-glTranslatef.glTexture on: 2003-05-27 17:03:03
Trying to use glTranslatef to move the location of my object using the mouseDragged method.  Having problem; tranlation barely happens I tried pos += (the value of x or y) however that just increments and the object continues to move more and more in the positive and doesn't follow the mouseDragged method.  Below is some code of what I want to do.  Also having an issue with texture.  Every time I rotate the object the texture on my sphere gets distorted.  How can I fix this?Any assistance would be greatly appreciated.

public void display(){

   if( glj.gljMakeCurrent() == false ) {
                        return;}           //Make Sure GL is initiated properly




      DrawGLScene();

      solidSphere();     //Method that creates the solid sphere

     //wireSphere();    //Method that creates the wireframe sphere
     gl.glDisable(GL_TEXTURE_2D);  //Turn the texture off

      for(Iterator i = drawables.iterator(); i.hasNext()Wink
      {
        draw_Interface pic = (draw_Interface) i.next();
        pic.draw(gl);

      }

      for(Iterator i = labels.iterator(); i.hasNext()Wink
      {
        text_Interface letter = (text_Interface) i.next();
        letter.text(glf,gl);
      }

    //System.out.println("output display");


    gl.glFlush();


}


public boolean LoadGLTextures(){
   //PngTextureLoader texLoader = new PngTextureLoader(gl, glu);        //Call to load a .png image file
   AWTTextureLoader texLoader = new AWTTextureLoader(this,gl,glu);     //Call to load a .jpg image file
   texLoader.readTexture("earth.jpg");
   if(texLoader.isOk())
   {
     //Create the texture
     gl.glGenTextures(1,texture);
     gl.glBindTexture(GL_TEXTURE_2D, texture[0]);
     gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     gl.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set Up Sphere Mapping
     gl.glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     gl.glEnable(GL_BLEND);
     gl.glEnable(GL_SMOOTH);
     gl.glEnable(GL_TEXTURE_GEN_S);                   // Enable Sphere Mapping
     gl.glEnable(GL_TEXTURE_GEN_T);
     gl.glTexImage2D(GL_TEXTURE_2D,0,3,texLoader.getImageWidth(),texLoader.getImageHeight(),0,GL_RGB,GL_UNSIGNED_BYTE,texLoader.getTexture());

     return true;
   }
   return false;
 }


public void solidSphere(){

 gl.glEnable(GL_TEXTURE_2D);
 gl.glBindTexture(GL_TEXTURE_2D, texture[0]);
 glut.glutSolidSphere(earth_radius,1200,1200);

}


public void DrawGLScene(){
   gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear screen and buffer bit
   gl.glLoadIdentity();     //Reset the view

   gl.glTranslatef(pos_x,pos_y,pos_z);                   //Position the objects
   gl.glRotatef(angle_x,1.0f,0.0f,0.0f);
   gl.glRotatef(angle_y,0.0f,1.0f,0.0f);
   gl.glRotatef(angle_z,0.0f,0.0f,1.0f);
   gl.glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE);


}


public void mouseMoved(MouseEvent evt){
 angle_x = (float)evt.getX();
 angle_y = (float)evt.getY();
//System.out.println("Mouse was pressed" + evt);
 repaint();
}

public void mouseDragged(MouseEvent evt){
 pos_x = (float)evt.getX();
 pos_y = (float)evt.getY();
 repaint();
}
5  Java Game APIs & Engines / Java 3D / GL4Java-GL_LINES on: 2003-05-14 19:35:49
I want to create axis lines. in the x,y,z direction crossing at (0,0,0).  What I have produces one line in the y direction and a faint line in the x direction.  What am I missing?

//GL4Java classes
 import gl4java.*;


public class gl4java_axisLines {

 GLFunc gl;

 public gl4java_axisLines(GLFunc lib) {
   gl = lib;



   gl.glBegin(gl.GL_LINES);
      gl.glColor3f(1.0f,0.0f,0.0f);
      //gl.glTranslatef(12000.0f,0.0f,0.0f);      //X
      gl.glVertex3f(-12000.0f,0.0f,0.0f);
      gl.glVertex3f(12000.0f,0.0f,0.0f);

      gl.glColor3f(0.0f,1.0f,0.0f);
      //gl.glTranslatef(0.0f,-12000.0f,0.0f);   //Y
      gl.glVertex3f(0.0f,-12000.0f,0.0f);
      gl.glVertex3f(0.0f,12000.0f,0.0f);

      gl.glColor3f(1.0f,1.0f,0.0f);
      //gl.glTranslatef(0.0f,0.0f,12000.0f);    //Z
      gl.glVertex3f(0.0f,0.0f,-12000.0f);
      gl.glVertex3f(0.0f,0.0f,12000.0f);
      gl.glEnd();


 }

}
6  Java Game APIs & Engines / Java 3D / GL4Java-GL_LINE_STRIP on: 2003-05-14 15:21:14
I want to use the GL_LINE_STRIP to plot some data, however I'm unable to get the data to appear.  If I move the gl.glBegin(GL_LINE_STRIP) and gl.glEnd inside my for loop and run the program my entire sphere object gets turned the color that the line strip to be.  If I move the begin and end outside the for loop nothing appears.  I have attached some code below.

public void display(){

    glj.gljMakeCurrent();           solidSphere();
    //wireSphere();
    new gl4java_gcitrajectory(gl); //call to class that
                                                     //reads data from file
                                                    // and tries to plot
gl.glFlush();

}


//----------------------------------------------
// class that is suppose to plot data
//-----------------------------------------------

  public class gl4java_gcitrajectory {
  public gl4java_gcitrajectory(GLFunc ready) {
   try{
   //io stuff performed

  //-----------------------------------------------------
  // trying to plot data in red line_strip
  //-----------------------------------------------------
 gl.glColor3d(1.0,0.0,0.0);
      gl.glBegin(gl.GL_LINE_STRIP);
    for(int i = 0; i< numCoords; i++)
      {
            //System.out.println("This is the loop");
         gl.glVertex3d(coords[0],coords[1],coords[2]);
      }
       gl.glEnd();

  }
7  Java Game APIs & Engines / Java 3D / GL4Java-TextureLoader on: 2003-05-13 19:05:24
I'm having a problem with my texture loader.  I have a sphere and I bind a texture, the texture appears, but it is upside down.  I don't know what to do to remedy this problem.  Please Help.  I have attached a code that has texture loader and sphere.



//Java classes
  import java.awt.*;
  import java.awt.event.*;

// GL4Java classes
  import gl4java.GLContext;
  import gl4java.swing.GLAnimJPanel;
  import gl4java.utils.glut.*;
  import gl4java.utils.textures.*;


public class gl4java_3Dcode extends GLAnimJPanel{

GLUTFunc glut;
int texture[] = new int[1];
double earth_radius = 6378.2;
double camera_distance = 10000.0;


 public gl4java_3Dcode() {
   super(false);
 }

 public void init(){
   glut = new GLUTFuncLightImpl(gl,glu);

   if(!LoadGLTextures())
    {
      System.out.println("Failed to load Textures");
      System.exit(0);
    }

    float width = (float)getSize().width;
    float height = (float)getSize().height;

    gl.glEnable(GL_TEXTURE_2D);                  //Enable Texture Mapping
    gl.glShadeModel(GL_SMOOTH);                 //Enable Smooth Color Shading
    gl.glClearColor(0.0f,0.0f,0.0f,0.0f);      //Clears the Background to black
    gl.glClearDepth(1.0);                      //Clears the Depth Buffer
    gl.glEnable(GL_DEPTH_TEST);               // Enables Depth Testing
    gl.glDepthFunc(GL_LEQUAL);                //Type of Depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  //Nice Perspective Calculations
 }


 public void reshape(int width, int height){
   if (height ==0) height =1;
   gl.glViewport(0,0,width,height);  //Reset current Viewport and Perspective Transformation
   gl.glMatrixMode(GL_PROJECTION);   //Select the Projection Matrix
   gl.glLoadIdentity();              //Reset Projection Matrix
   glu.gluPerspective(60.0f,width/height,1.0f,75000.0f); //Calculate the Aspect Ratio of Window

   gl.glMatrixMode(GL_MODELVIEW);  //Select the Modelview Matrix
   gl.glLoadIdentity();            //Reset the Modelview Matrix
 }

 public void display(){

    glj.gljMakeCurrent();        //Make Sure GL is initiated properly
    solidSphere();
    //wireSphere();
    //new gl4java_gcitrajectory(gl);


    gl.glFlush();

}

//------------------------------------------------------------------------------
// Method to create the GLTextures
//------------------------------------------------------------------------------

 public boolean LoadGLTextures(){
   //PngTextureLoader texLoader = new PngTextureLoader(gl, glu);           //Call to load a .png image file
   AWTTextureLoader texLoader = new AWTTextureLoader(this,gl,glu);     //Call to load a .jpg image file
   texLoader.readTexture("C:/Documents and Settings/mbutler.GEN-X/jbproject/GCI_PLOT/src/gci_plot/earth.jpg");
   if(texLoader.isOk())
   {
     //Create the texture
     gl.glGenTextures(1,texture);
     gl.glBindTexture(GL_TEXTURE_2D, texture[0]);
     gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     gl.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // Set Up Sphere Mapping
     gl.glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
     gl.glEnable(GL_BLEND);
     gl.glEnable(GL_TEXTURE_GEN_S);                   // Enable Sphere Mapping
     gl.glEnable(GL_TEXTURE_GEN_T);
     gl.glTexImage2D(GL_TEXTURE_2D,0,3,texLoader.getImageWidth(),texLoader.getImageHeight(),0,GL_RGB,GL_UNSIGNED_BYTE,texLoader.getTexture());

     return true;
   }
   return false;
 }


//------------------------------------------------------------------------------
//  void solidSphere()        Method that defines solid sphere
//------------------------------------------------------------------------------

public void solidSphere(){
 gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear screen and buffer bit
 gl.glLoadIdentity();  //Reset the view
 gl.glTranslatef(0.0f,0.0f,-35000.0f);
 gl.glBindTexture(GL_TEXTURE_2D, texture[0]);
 glut.glutSolidSphere(earth_radius,12000,12000);
}
8  Java Game APIs & Engines / Java 3D / GL4Java- viewpoint manipulation on: 2003-05-08 13:13:28
I've created this earth objec, but it is not at the right raius.  I tried to use a translate to move the the camera to about 10000 and put the radius of the earth at 6378 (km), every time I try this I loose the image.  What am I doing wrong? Please help!
9  Java Game APIs & Engines / Java 3D / Re: GL4Java-GLUT Functions on: 2003-05-07 10:18:44
Thank you  Grin
10  Java Game APIs & Engines / Java 3D / GL4Java-GLUT Functions on: 2003-05-05 10:31:20
In need of assistance!
 Trying to access glutWireSphere I imported  appropriate library according to gl4java javadoc(import gl4java.utils.glut.*Wink  but unable to get access to method.  What am I doing wrong?  Please HELP!!!
11  Java Game APIs & Engines / Java 3D / Loading a Text File on: 2002-11-12 18:22:01
I am new to Java3D I am trying to read in a text File that contains x,y and z coordinates.  I want to put them into a point Array.  How do I get the points from the file so they are displayed on the scene.  This is what I tried.

   StringTokenizer st = new StringTokenizer(line);
               time = Double.valueOf(st.nextToken()).doubleValue();
               x = Double.valueOf(st.nextToken()).doubleValue();
               y = Double.valueOf(st.nextToken()).doubleValue();
               z = Double.valueOf(st.nextToken()).doubleValue();

                 PointArray par = new PointArray(vertexCount, vertexFormat);
                 Point3d[] pts1 = new Point3d[1];
                 pts1[0] = new Point3d(x,y,z);

                  Color3f[] co= {new Color3f(1.0f,0.0f,0.0f), new Color3f(1.0f,0.3f,0.5f),new Color3f(0.8f,0.3f,0.9f)};
                 par.setCoordinates(0,pts1);
                 par.setColors(0,co);

               //System.out.println(time+ ",  "+x);
                    this.addGeometry(par);

but it didn't work.  I would appreciate any assistance available.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (39 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (36 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!