but in one class i have some errors which i don't understand, what is my wrong? i cannot see it.
I have attached also the errors log from eclipse as picture.
The file Animation.java has the errors, i have used the nehe lesson30 and also from physics rope.
import java.awt.*;
import java.awt.event.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.sun.opengl.util.Animator;
public abstract class Application implements GLEventListener, KeyListener {
static Animator animator = null;
GL gl;
GLU glu;
GLUquadric q;
boolean keyDown[]=new boolean[20];
long tickcount,lasttickcount;
int ESC=0,RIGHT=1,LEFT=2,UP=3,DOWN=4,HOME=5,END=6,A=7,S=8,D=9,W=10,R=11,F=12;
float ch=0.01f;
float speed=3f;
float rad=0.1f;
float cam=4; //camera distance
float camx,camy,camz,camAngle=90;
boolean paused;
float wall=5;
int texture[][] = new int[1][2]; //stores texture objects
float slowMotionRatio=1;
RopeWithBall ropeSimulation = new RopeWithBall(
33, // 33 Particles (Masses)
0.05f, // Each Particle Has A Weight Of 50 Grams
10000.0f, // springConstant In The Rope
0.05f, // Normal Length Of Springs In The Rope
0.2f, // Spring Inner Friction Constant
new Vector3D(0, -9.81f, 0), // Gravitational Acceleration
0.04f, // Air Friction Constant
100.0f, // Ground Repel Constant
0.2f, // Ground Slide Friction Constant
2.0f, // Ground Absoption Constant
-1.5f, // ground height
wall // wall distance
);
float lx,ly,lz;
float LightPos[] = { lx, 0.1f, 0.2f, 1.0f }, // Light Position
LightAmb[] = { 0.9f, 0.9f, 0.9f, 1.0f }, // Ambient Light Values
LightDif[] = { 0.6f, 0.6f, 0.6f, 1.0f }, // Diffuse Light Values
LightSpc[] = { 0.5f, 0.5f, 0.5f, 1.0f }, // Specular Light Values
MatAmb[][] = {{ 0.8f, 0.2f, 0.1f, 1.0f }, // Material - Ambient Values
{ 0.5f, 0.5f, 0.5f, 1.0f },
{ 0.4f, 0.3f, 0.3f, 1.0f }
},
MatDif[][] = {{ 0.8f, 0.2f, 0.2f, 1.0f }, // Material - Diffuse Values
{ 0.2f, 0.2f, 0.2f, 1.0f }
},
MatSpc[] = { 0.7f, 0.7f, 0.7f, 1.0f }, // Material - Specular
// Values
MatEm[] = { 0.1f, 0.1f, 0.1f, 1.0f },
MatShn[] = { 80.0f }; // Material - Shininess
void initialize () // Any GL Init Code & User Initialiazation Goes Here
{
ropeSimulation.getMass(ropeSimulation.numOfMasses - 1).vel.z = 10.0f;
lasttickcount=System.currentTimeMillis();
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
gl.glClearDepth (1.0f); // Depth Buffer Setup
gl.glShadeModel (gl.GL_SMOOTH); // Select Smooth Shading
gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST); // Set Perspective Calculations To Most Accurate
float degInRad = camAngle * (float) Math.PI / 180;
camx=(float) Math.cos(degInRad) * cam ;
camz=(float) Math.sin(degInRad) * cam ; // Return TRUE (Initialization Successful)
}
void LoadGLTextures(GL gl){
/* Load Texture*/
loadImage image1 = new loadImage(),
image2 = new loadImage(),
image3 = new loadImage(),
image4 = new loadImage();
image1.generateTextureInfo("data/marble.bmp", false);
image2.generateTextureInfo("data/wand.bmp" , false);
/* Create Texture *****************************************/
gl.glGenTextures(2, texture[0]);
gl.glBindTexture(gl.GL_TEXTURE_2D, texture[0][0]); /* 2d texture (x and y size)*/
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MAG_FILTER,gl.GL_LINEAR); /* scale linearly when image bigger than texture*/
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MIN_FILTER,gl.GL_LINEAR); /* scale linearly when image smalled than texture*/
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT);
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT);
/* 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, */
/* border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.*/
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, 3, image1.width, image1.height, 0, gl.GL_RGB,gl.GL_UNSIGNED_BYTE, image1.data);
/* Create Texture ******************************************/
gl.glBindTexture(gl.GL_TEXTURE_2D, texture[0][1]); /* 2d texture (x and y size)*/
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MAG_FILTER,gl.GL_LINEAR); /* scale linearly when image bigger than texture*/
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_MIN_FILTER,gl.GL_LINEAR); /* scale linearly when image smalled than texture*/
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT);
gl.glTexParameteri(gl.GL_TEXTURE_2D,gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT);
/* 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, */
/* border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.*/
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, 3, image2.width, image2.height, 0, gl.GL_RGB,gl.GL_UNSIGNED_BYTE, image2.data);
image1.destroy();
image2.destroy();
}
public void display(GLDrawable gLDrawable) {
//float [] LightPos = { lx, ly, lz, 1.0f };
//gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, LightPos);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity (); // Reset The Modelview Matrix
// Position Camera
glu.gluLookAt(camx, camy, camz,
0, 0, 0,
// Set The Up Vector In Y-Direction So That +X Directs To Right And +Y Directs To Up On The window.
0, 1, 0);
gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, MatAmb[1]);
gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, MatDif[1]);
// Draw A Plane To Represent The Ground (Different Colors To Create A Fade)
gl.glEnable(gl.GL_TEXTURE_2D);
//render walls(planes) with texture
gl.glBindTexture(gl.GL_TEXTURE_2D, texture[0][0]);
gl.glBegin(gl.GL_QUADS);
//gl.glColor3ui(0, 0, 255); // Set Color To Light Blue
gl.glTexCoord2f(1.0f, 0.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight, wall);
gl.glTexCoord2f(1.0f, 1.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight, -wall);
gl.glTexCoord2f(0.0f, 1.0f);gl.glVertex3f(-wall, ropeSimulation.groundHeight, -wall);
gl.glTexCoord2f(0.0f, 0.0f);gl.glVertex3f(-wall, ropeSimulation.groundHeight, wall);
//gl.glColor3ui(0, 0, 0); // Set Color To Black
gl.glEnd();
gl.glBindTexture(gl.GL_TEXTURE_2D, texture[0][1]);
gl.glBegin(gl.GL_QUADS);
//walls
//right
gl.glTexCoord2f(1.0f, 0.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight, wall);
gl.glTexCoord2f(1.0f, 1.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight+5, wall);
gl.glTexCoord2f(0.0f, 1.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight+5, -wall);
gl.glTexCoord2f(0.0f, 0.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight, -wall);
//left
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(-wall, ropeSimulation.groundHeight, -wall);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(-wall, ropeSimulation.groundHeight+5, -wall);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(-wall, ropeSimulation.groundHeight+5, wall);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(-wall, ropeSimulation.groundHeight, wall);
//back
gl.glTexCoord2f(1.0f, 0.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight, -wall);
gl.glTexCoord2f(1.0f, 1.0f);gl.glVertex3f(wall, ropeSimulation.groundHeight+5, -wall);
gl.glTexCoord2f(0.0f, 1.0f);gl.glVertex3f(-wall, ropeSimulation.groundHeight+5, -wall);
gl.glTexCoord2f(0.0f, 0.0f);gl.glVertex3f(-wall, ropeSimulation.groundHeight, -wall);
//front
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(-wall, ropeSimulation.groundHeight, wall);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(-wall, ropeSimulation.groundHeight+5, wall);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(wall, ropeSimulation.groundHeight+5, wall);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(wall, ropeSimulation.groundHeight, wall);
gl.glEnd();
gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, MatAmb[2]);
// Start Drawing Shadow Of The Rope
for (int a = 0; a < ropeSimulation.numOfMasses - 1; ++a)
{
Mass mass1 = ropeSimulation.getMass(a);
Vector3D pos1 = mass1.pos;
Mass mass2 = ropeSimulation.getMass(a + 1);
Vector3D pos2 = mass2.pos;
gl.glLineWidth(2);
gl.glBegin(gl.GL_LINES);
gl.glVertex3f(pos1.x, ropeSimulation.groundHeight, pos1.z); // Draw Shadow At groundHeight
gl.glVertex3f(pos2.x, ropeSimulation.groundHeight, pos2.z); // Draw Shadow At groundHeight
gl.glEnd();
}
//draw shadow of the ball
Mass masss = ropeSimulation.getMass(ropeSimulation.numOfMasses-1);
Vector3D poss = masss.pos;
gl.glBegin(gl.GL_POLYGON);
for (int i = 360; i > 0; i-=5) {
float degInRad = i * (float) Math.PI / 180;
float x=poss.x+(float) Math.cos(degInRad) * rad*0.9f;
float z=poss.z+(float) Math.sin(degInRad) * rad*0.9f;
gl.glVertex3f(x, ropeSimulation.groundHeight+0.001f, z);
}
gl.glEnd();
// Drawing Shadow Ends Here.
gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, MatAmb[0]);
gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, MatDif[0]);
//start drawing rope
for (int a = 0; a < ropeSimulation.numOfMasses - 2; ++a)
{
Mass mass1 = ropeSimulation.getMass(a);
Vector3D pos1 = mass1.pos;
Mass mass2 = ropeSimulation.getMass(a + 1);
Vector3D pos2 = mass2.pos;
gl.glLineWidth(3);
gl.glBegin(gl.GL_LINES);
gl.glVertex3f(pos1.x, pos1.y+0.004f, pos1.z);
gl.glVertex3f(pos2.x, pos2.y+0.004f, pos2.z);
gl.glEnd();
}
// Drawing The Rope Ends Here.
Mass mass = ropeSimulation.getMass(ropeSimulation.numOfMasses - 1);
Vector3D pos = mass.pos;
gl.glPushMatrix();
gl.glTranslatef(pos.x,pos.y,pos.z);
glu.gluSphere(q, rad, 25,25);
gl.glPopMatrix();
gl.glFlush ();
//get current time
tickcount=System.currentTimeMillis();
//find time passed
update(tickcount-lasttickcount);
lasttickcount=tickcount;
}
void update (long milliseconds) // Perform Motion Updates Here
{
Vector3D ropeConnectionVel=new Vector3D(); // Create A Temporary Vector3D
float degInRad;
// Keys Are Used To Move The Rope
if (keyDown[RIGHT]) // Is The Right Arrow Being Pressed?
ropeConnectionVel.x += speed; // Add Velocity In +X Direction
if (keyDown[LEFT]) // Is The Left Arrow Being Pressed?
ropeConnectionVel.x -= speed; // Add Velocity In -X Direction
if (keyDown[UP]) // Is The Up Arrow Being Pressed?
ropeConnectionVel.y += speed; // Add Velocity In +Z Direction
if (keyDown[DOWN]) // Is The Down Arrow Being Pressed?
ropeConnectionVel.y -= speed; // Add Velocity In -Z Direction
if (keyDown[HOME]){ // Is The Home Key Pressed?
ropeConnectionVel.z -= speed; // Add Velocity In +Y Direction
}
if (keyDown[END]) // Is The End Key Pressed?
ropeConnectionVel.z += speed; // Add Velocity In -Y Direction
if (keyDown[A])
camAngle+=0.1f;
if (keyDown[D])
camAngle-=0.1f;
if (keyDown[W])
cam-=0.005;
if (keyDown[S])
cam+=0.005;
if (keyDown[R])
camy+=0.005;
if (keyDown[F])
camy-=0.005;
//calculate camera position
degInRad = camAngle * (float) Math.PI / 180;
camx=(float) Math.cos(degInRad) * cam ;
camz=(float) Math.sin(degInRad) * cam ;
ropeSimulation.setRopeConnectionVel(ropeConnectionVel); // Set The Obtained ropeConnectionVel In The Simulation
float dt = milliseconds / 1000.0f; // Let's Convert Milliseconds To Seconds
dt /= slowMotionRatio; // Divide dt By slowMotionRatio And Obtain The New dt
float maxPossible_dt = 0.002f; // Maximum Possible dt Is 0.002 Seconds
// This Is Needed To Prevent Pass Over Of A Non-Precise dt Value
int numOfIterations = (int)(dt / maxPossible_dt) + 1; // Calculate Number Of Iterations To Be Made At This Update Depending On maxPossible_dt And dt
if (numOfIterations != 0) // Avoid Division By Zero
dt = dt / numOfIterations; // dt Should Be Updated According To numOfIterations
if(!paused)
for (int a = 0; a < numOfIterations; ++a) // We Need To Iterate Simulations "numOfIterations" Times
ropeSimulation.operate(dt);
}
public void displayChanged(GLDrawable gLDrawable, boolean modeChanged,
boolean deviceChanged) {
}
public void init(GLDrawable gLDrawable) {
gl = gLDrawable.getGL();
glu = gLDrawable.getGLU();
q = glu.gluNewQuadric();
gl.glShadeModel(gl.GL_SMOOTH); // Enable Smooth Shading
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
gl.glClearDepth(1.0f); // Depth Buffer Setup
gl.glClearStencil(0); // Stencil Buffer Setup
gl.glEnable(gl.GL_DEPTH_TEST); // Enables Depth Testing
gl.glDepthFunc(gl.GL_LEQUAL); // The Type Of Depth Testing To Do
gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST); // Really
// Nice
// Perspective
// Calculations
gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, LightPos); // Set
// Light1
// Position
gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, LightAmb); // Set
// Light1
// Ambience
gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, LightDif); // Set
// Light1
// Diffuse
gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, LightSpc); // Set
// Light1
// Specular
gl.glEnable(gl.GL_LIGHT1); // Enable Light1
gl.glEnable(gl.GL_LIGHTING); // Enable Lighting
gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, MatAmb[0]); // Set
// Material
// Ambience
gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, MatDif[0]); // Set
// Material
// Diffuse
gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, MatSpc); // Set
// Material
// Specular
gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, MatShn); // Set
// Material
// Shininess
gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION, MatEm);
gl.glCullFace(gl.GL_BACK); // Set Culling Face To Back Face
gl.glEnable(gl.GL_CULL_FACE); // Enable Culling
gl.glClearColor(0f, 0f, 0f, 1.0f); // Set Clear Color
// (Greenish Color)
gl.glEnable(gl.GL_TEXTURE_2D);
LoadGLTextures(gl);
initialize();
}
public void reshape(GLDrawable gLDrawable, int x, int y, int width,
int height) {
if (height <= 0) // avoid a divide by zero error!
height = 1;
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void keyPressed(KeyEvent e) {
float degInRad;
// Create A Temporary Vector3D
switch (e.getKeyCode()) {
case KeyEvent.VK_RIGHT:
keyDown[RIGHT]=true;
break;
case KeyEvent.VK_LEFT:
keyDown[LEFT]=true;
break;
case KeyEvent.VK_UP:
keyDown[UP]=true;
break;
case KeyEvent.VK_DOWN:
keyDown[DOWN]=true;
break;
case KeyEvent.VK_HOME:
keyDown[HOME]=true;
break;
case KeyEvent.VK_END:
keyDown[END]=true;
break;
case KeyEvent.VK_L:
slowMotionRatio = (slowMotionRatio < 8) ? 9 : 1;
break;
case KeyEvent.VK_P: //pause
paused=!paused;
break;
case KeyEvent.VK_A: //camera left
keyDown[A]=true;
break;
case KeyEvent.VK_S: //camera backward
keyDown[S]=true;
break;
case KeyEvent.VK_D: //camera right
keyDown[D]=true;
break;
case KeyEvent.VK_W: //camera forward
keyDown[W]=true;
break;
case KeyEvent.VK_R: //camera up
keyDown[R]=true;
break;
case KeyEvent.VK_F: //camera down
keyDown[F]=true;
break;
}
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
animator.stop();
System.exit(0);
}
}
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_RIGHT:
keyDown[RIGHT]=false;
break;
case KeyEvent.VK_LEFT:
keyDown[LEFT]=false;
break;
case KeyEvent.VK_UP:
keyDown[UP]=false;
break;
case KeyEvent.VK_DOWN:
keyDown[DOWN]=false;
break;
case KeyEvent.VK_HOME:
keyDown[HOME]=false;
break;
case KeyEvent.VK_END:
keyDown[END]=false;
break;
case KeyEvent.VK_A: //camera left
keyDown[A]=false;
break;
case KeyEvent.VK_S: //camera backward
keyDown[S]=false;
break;
case KeyEvent.VK_D: //camera right
keyDown[D]=false;
break;
case KeyEvent.VK_W: //camera forward
keyDown[W]=false;
break;
case KeyEvent.VK_R: //camera up
keyDown[R]=false;
break;
case KeyEvent.VK_F: //camera down
keyDown[F]=false;
break;
}
}
public void keyTyped(KeyEvent e) {
}
public static void main(String[] args) {
new Application();
}
public Application(){
Frame frame = new Frame("PHYSICS");
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(
new GLCapabilities());
canvas.addGLEventListener(this);
frame.add(canvas);
frame.setSize(800, 600);
frame.addKeyListener(this);
animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
animator.stop();
System.exit(0);
}
});
frame.show();
animator.start();
}
}

New Topic/Question
Reply



MultiQuote







|