diff options
author | Sven Gothel <[email protected]> | 2014-06-06 19:56:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-06-06 19:56:03 +0200 |
commit | 548fee0b3d65605ff5cbcbe750564eda1bc611d7 (patch) | |
tree | 5057236c8578ebdd17b16893cb4e82b56edbf23e /src/demos | |
parent | 6ee1f0641fbefbb309217401708e61d0c7f248e9 (diff) |
Adapt to JOGL commit ebe980ad6ac40148bc84913d1ba1f7adf6200490 (Bug 741 HiDPI)
AWTMouseAdapter and AWTMouseAdapter ctor have been changed ..
Diffstat (limited to 'src/demos')
-rw-r--r-- | src/demos/gears/Gears.java | 15 | ||||
-rw-r--r-- | src/demos/tennis/Tennis.java | 353 |
2 files changed, 181 insertions, 187 deletions
diff --git a/src/demos/gears/Gears.java b/src/demos/gears/Gears.java index b477ffc..51c118d 100644 --- a/src/demos/gears/Gears.java +++ b/src/demos/gears/Gears.java @@ -32,7 +32,6 @@ private final float view_rotz = 0.0f; private float angle = 0.0f; private final int swapInterval; - private boolean mouseRButtonDown = false; private int prevMouseX, prevMouseY; public static void main(String[] args) { @@ -178,8 +177,8 @@ public void init(GLAutoDrawable drawable) { window.addKeyListener(gearsKeys); } else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) { java.awt.Component comp = (java.awt.Component) drawable; - new AWTMouseAdapter(gearsMouse).addTo(comp); - new AWTKeyAdapter(gearsKeys).addTo(comp); + new AWTMouseAdapter(gearsMouse, drawable).addTo(comp); + new AWTKeyAdapter(gearsKeys, drawable).addTo(comp); } } @@ -398,22 +397,16 @@ public void display(GLAutoDrawable drawable) { public void mousePressed(MouseEvent e) { prevMouseX = e.getX(); prevMouseY = e.getY(); - if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { - mouseRButtonDown = true; - } } @Override public void mouseReleased(MouseEvent e) { - if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { - mouseRButtonDown = false; - } } @Override public void mouseDragged(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); + final int x = e.getX(); + final int y = e.getY(); int width=0, height=0; Object source = e.getSource(); if(source instanceof Window) { diff --git a/src/demos/tennis/Tennis.java b/src/demos/tennis/Tennis.java index 1eb1b6a..7cbd9a0 100644 --- a/src/demos/tennis/Tennis.java +++ b/src/demos/tennis/Tennis.java @@ -48,26 +48,27 @@ import java.awt.image.BufferedImage; * Tennis.java <BR>
* author: Fofonov Alexey <P>
*/
-
+
public class Tennis implements GLEventListener {
static {
GLProfile.initSingleton();
}
- private float view_rotx = 0.0f, view_roty = 0.0f, view_rotz = 0.0f; //View angles
+ private float view_rotx = 0.0f, view_roty = 0.0f; //View angles
+private final float view_rotz = 0.0f;
private float sx = 0.0f, sy = 0.0f; //X, Y coords of Mydesk
private float spx,spy,spz; //Speed of the ball
private float BallCx = 0.0f, BallCy = 0.0f, BallCz = 0.0f; //Coords of the ball
private float EnDeskCx = 0.0f, EnDeskCy = 0.0f; //X, Y coords of Endesk
- private int cube=0, mydesk=0, endesk=0, ball=0, box=0; //Flags of the existence
- private int swapInterval;
+ private int cube=0, mydesk=0, endesk=0, ball=0, box=0; //Flags of the existence
+ private final int swapInterval;
private static Texture[] texture;
private float Bax=0, Bay=0; //Acceleration summands
private float Vec=3; //Balls direction
private boolean CanF=false; //Ready for play
-
- private int WindowW=0, WindowH=0;
-
- private float LPositionDX=0, NPositionDX=0; //Mouse positions
+
+ private int WindowW=0, WindowH=0;
+
+ private float LPositionDX=0, NPositionDX=0; //Mouse positions
private float LPositionDY=0, NPositionDY=0; //
private float DspeedX=0, DspeedY=0; //Speed of Mydesk
@@ -77,7 +78,7 @@ public class Tennis implements GLEventListener { public static void main(String[] args) {
// set argument 'NotFirstUIActionOnProcess' in the JNLP's application-desc tag for example
// <application-desc main-class="demos.j2d.TextCube"/>
- // <argument>NotFirstUIActionOnProcess</argument>
+ // <argument>NotFirstUIActionOnProcess</argument>
// </application-desc>
// boolean firstUIActionOnProcess = 0==args.length || !args[0].equals("NotFirstUIActionOnProcess") ;
@@ -110,7 +111,7 @@ public class Tennis implements GLEventListener { frame.add(canvas, java.awt.BorderLayout.CENTER);
frame.validate();
-
+
//Hide the mouse cursor
Toolkit t = Toolkit.getDefaultToolkit();
Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
@@ -120,7 +121,7 @@ public class Tennis implements GLEventListener { frame.setVisible(true);
animator.start();
}
-
+
public Tennis(int swapInterval) {
this.swapInterval = swapInterval;
}
@@ -148,14 +149,14 @@ public class Tennis implements GLEventListener { { 25.0f };
float light_position[] =
{ 1.0f, 1.0f, 1.0f, 0.0f };
-
+
float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
float yellow[] = { 0.8f, 0.75f, 0.0f, 0.7f };
float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
float brown[] = { 0.8f, 0.4f, 0.1f, 0.7f };
-
+
texture = new Texture[5];
-
+
//Load textures
try {
System.err.println("Loading texture...");
@@ -195,23 +196,23 @@ public class Tennis implements GLEventListener { gl.glClearDepth(1.0f); // Depth Buffer Setup
gl.glEnable(GL2.GL_DEPTH_TEST); // Enables Depth Testing
gl.glDepthFunc(GL2.GL_LEQUAL); // The Type Of Depth Testing To Do
-
+
// Really Nice Perspective Calculations
- gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
+ gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
gl.glEnable(GL2.GL_TEXTURE_2D);
-
+
// Texture filter
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NONE);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NONE);
-
+
// Light and material
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, mat_specular, 0);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, mat_specular, 0);
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SHININESS, mat_shininess, 0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_position, 0);
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
-
-
+
+
/* make the objects */
if(0>=cube) {
cube = gl.glGenLists(1);
@@ -223,7 +224,7 @@ public class Tennis implements GLEventListener { } else {
System.err.println("cube list reused: "+cube);
}
-
+
if(0>=box) {
box = gl.glGenLists(1);
gl.glNewList(box, GL2.GL_COMPILE);
@@ -234,7 +235,7 @@ public class Tennis implements GLEventListener { } else {
System.err.println("box list reused: "+box);
}
-
+
if(0>=mydesk) {
mydesk = gl.glGenLists(1);
gl.glNewList(mydesk, GL2.GL_COMPILE);
@@ -245,7 +246,7 @@ public class Tennis implements GLEventListener { } else {
System.err.println("mydesk list reused: "+mydesk);
}
-
+
if(0>=endesk) {
endesk = gl.glGenLists(1);
gl.glNewList(endesk, GL2.GL_COMPILE);
@@ -256,7 +257,7 @@ public class Tennis implements GLEventListener { } else {
System.err.println("endesk list reused: "+endesk);
}
-
+
if(0>=ball) {
ball = gl.glGenLists(1);
gl.glNewList(ball, GL2.GL_COMPILE);
@@ -267,10 +268,10 @@ public class Tennis implements GLEventListener { } else {
System.err.println("ball list reused: "+ball);
}
-
+
gl.glEnable(GL2.GL_NORMALIZE);
-
- MouseListener tennisMouse = new TennisMouseAdapter();
+
+ MouseListener tennisMouse = new TennisMouseAdapter();
KeyListener tennisKeys = new TennisKeyAdapter();
if (drawable instanceof Window) {
@@ -279,9 +280,9 @@ public class Tennis implements GLEventListener { window.addKeyListener(tennisKeys);
} else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) {
java.awt.Component comp = (java.awt.Component) drawable;
- new AWTMouseAdapter(tennisMouse).addTo(comp);
- new AWTKeyAdapter(tennisKeys).addTo(comp);
- }
+ new AWTMouseAdapter(tennisMouse, drawable).addTo(comp);
+ new AWTKeyAdapter(tennisKeys, drawable).addTo(comp);
+ }
}
public void dispose(GLAutoDrawable drawable) {
@@ -292,7 +293,7 @@ public class Tennis implements GLEventListener { // Get the GL corresponding to the drawable we are animating
GL2 gl = drawable.getGL().getGL2();
-
+
if (mouseButtonDown == false && control == true)
MovMydesk();
MoveSphere();
@@ -302,7 +303,7 @@ public class Tennis implements GLEventListener { // Special handling for the case where the GLJPanel is translucent
// and wants to be composited with other Java 2D content
- if (GLProfile.isAWTAvailable() &&
+ if (GLProfile.isAWTAvailable() &&
(drawable instanceof javax.media.opengl.awt.GLJPanel) &&
!((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() &&
((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
@@ -310,69 +311,69 @@ public class Tennis implements GLEventListener { } else {
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
}
-
+
// Place the box and call its display list
gl.glDisable(GL2.GL_DEPTH_TEST);
gl.glCallList(box);
gl.glEnable(GL2.GL_DEPTH_TEST);
-
+
// Rotate the entire assembly of tennis based on how the user
// dragged the mouse around
gl.glPushMatrix();
gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
-
+
// Place the cube and call its display list
gl.glPushMatrix();
gl.glTranslatef(0.0f, 0.0f, 0.0f);
gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
gl.glCallList(cube);
gl.glPopMatrix();
-
+
// Place the mydesk and call its display list
gl.glPushMatrix();
gl.glTranslatef(sx, sy, 3.0f);
gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
gl.glCallList(mydesk);
gl.glPopMatrix();
-
+
// Place the endesk and call its display list
gl.glPushMatrix();
gl.glTranslatef(EnDeskCx, EnDeskCy, -3.0f);
gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
gl.glCallList(endesk);
gl.glPopMatrix();
-
+
// Place the ball and call its display list
gl.glPushMatrix();
gl.glTranslatef(BallCx, BallCy, BallCz);
gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
gl.glCallList(ball);
gl.glPopMatrix();
-
+
// Remember that every push needs a pop; this one is paired with
// rotating the entire tennis assembly
gl.glPopMatrix();
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
-
+
System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height);
GL2 gl = drawable.getGL().getGL2();
gl.setSwapInterval(swapInterval);
float h = (float)height / (float)width;
-
+
WindowW = width;
WindowH = height;
-
+
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
-
+
if (h<1)
gl.glFrustum(-1.0f, 1.0f, -h, h, 1.0f, 60.0f);
else
@@ -380,13 +381,13 @@ public class Tennis implements GLEventListener { h = 1.0f/h;
gl.glFrustum(-h, h, -1.0f, 1.0f, 1.0f, 60.0f);
}
-
+
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -6.0f);
-
+
}
-
+
public static void cube(GL2 gl)
{
@@ -394,13 +395,13 @@ public class Tennis implements GLEventListener { /* draw left sides */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(-2.0f, -1.5f, -3.0f);
gl.glVertex3f(-2.0f, 1.5f, -3.0f);
gl.glVertex3f(-2.0f, 1.5f, 3.0f);
gl.glVertex3f(-2.0f, -1.5f, 3.0f);
-
+
gl.glNormal3f(-1.0f, 0.0f, 0.0f);
gl.glVertex3f(-2.05f, -1.55f, -3.0f);
gl.glVertex3f(-2.05f, 1.55f, -3.0f);
@@ -408,16 +409,16 @@ public class Tennis implements GLEventListener { gl.glVertex3f(-2.05f, -1.55f, 3.0f);
gl.glEnd();
-
+
if (texture[0] != null) {
texture[0].enable(gl);
texture[0].bind(gl);
gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
TextureCoords coords = texture[0].getImageTexCoords();
-
+
/* draw up sides */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(0.0f, -1.0f, 0.0f);
gl.glTexCoord2f(coords.left(), coords.top());
gl.glVertex3f(-2.0f, 1.5f, -3.0f);
@@ -427,14 +428,14 @@ public class Tennis implements GLEventListener { gl.glVertex3f( 2.0f, 1.5f, 3.0f);
gl.glTexCoord2f(coords.right(), coords.top());
gl.glVertex3f( 2.0f, 1.5f, -3.0f);
-
+
gl.glEnd();
-
+
texture[0].disable(gl);
- }
-
+ }
+
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(0.0f, 1.0f, 0.0f);
gl.glVertex3f(-2.05f, 1.55f, -3.0f);
gl.glVertex3f(-2.05f, 1.55f, 3.0f);
@@ -442,16 +443,16 @@ public class Tennis implements GLEventListener { gl.glVertex3f( 2.05f, 1.55f, -3.0f);
gl.glEnd();
-
+
/* draw right sides */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(-1.0f, 0.0f, 0.0f);
gl.glVertex3f(2.0f, -1.5f, -3.0f);
gl.glVertex3f(2.0f, 1.5f, -3.0f);
gl.glVertex3f(2.0f, 1.5f, 3.0f);
gl.glVertex3f(2.0f, -1.5f, 3.0f);
-
+
gl.glNormal3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(2.05f, -1.55f, -3.0f);
gl.glVertex3f(2.05f, 1.55f, -3.0f);
@@ -459,16 +460,16 @@ public class Tennis implements GLEventListener { gl.glVertex3f(2.05f, -1.55f, 3.0f);
gl.glEnd();
-
+
if (texture[1] != null) {
texture[1].enable(gl);
texture[1].bind(gl);
gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
TextureCoords coords = texture[1].getImageTexCoords();
-
+
/* draw down sides */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(0.0f, 1.0f, 0.0f);
gl.glTexCoord2f(coords.left(), coords.top());
gl.glVertex3f(-2.0f, -1.5f, -3.0f);
@@ -478,7 +479,7 @@ public class Tennis implements GLEventListener { gl.glVertex3f( 2.0f, -1.5f, 3.0f);
gl.glTexCoord2f(coords.right(), coords.top());
gl.glVertex3f( 2.0f, -1.5f, -3.0f);
-
+
gl.glNormal3f(0.0f, -1.0f, 0.0f);
gl.glVertex3f(-2.05f, -1.55f, -3.0f);
gl.glVertex3f(-2.05f, -1.55f, 3.0f);
@@ -486,81 +487,81 @@ public class Tennis implements GLEventListener { gl.glVertex3f( 2.05f, -1.55f, -3.0f);
gl.glEnd();
-
+
texture[1].disable(gl);
}
-
+
/* draw back sides */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(0.0f, 0.0f, -1.0f);
-
+
gl.glVertex3f(-2.05f, 1.55f, -3.0f);
gl.glVertex3f( 2.05f, 1.55f, -3.0f);
gl.glVertex3f( 2.0f, 1.5f, -3.0f);
gl.glVertex3f(-2.0f, 1.5f, -3.0f);
-
+
gl.glVertex3f(-2.05f, -1.55f, -3.0f);
gl.glVertex3f( 2.05f, -1.55f, -3.0f);
gl.glVertex3f( 2.0f, -1.5f, -3.0f);
gl.glVertex3f(-2.0f, -1.5f, -3.0f);
-
+
gl.glVertex3f(-2.05f, -1.55f, -3.0f);
gl.glVertex3f(-2.05f, 1.55f, -3.0f);
gl.glVertex3f(-2.0f, 1.5f, -3.0f);
gl.glVertex3f(-2.0f, -1.5f, -3.0f);
-
+
gl.glVertex3f(2.05f, -1.55f, -3.0f);
gl.glVertex3f(2.05f, 1.55f, -3.0f);
gl.glVertex3f(2.0f, 1.5f, -3.0f);
gl.glVertex3f(2.0f, -1.5f, -3.0f);
gl.glEnd();
-
+
/* draw front sides */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(0.0f, 0.0f, 1.0f);
-
+
gl.glVertex3f(-2.05f, 1.55f, 3.0f);
gl.glVertex3f( 2.05f, 1.55f, 3.0f);
gl.glVertex3f( 2.0f, 1.5f, 3.0f);
gl.glVertex3f(-2.0f, 1.5f, 3.0f);
-
+
gl.glVertex3f(-2.05f, -1.55f, 3.0f);
gl.glVertex3f( 2.05f, -1.55f, 3.0f);
gl.glVertex3f( 2.0f, -1.5f, 3.0f);
gl.glVertex3f(-2.0f, -1.5f, 3.0f);
-
+
gl.glVertex3f(-2.05f, -1.55f, 3.0f);
gl.glVertex3f(-2.05f, 1.55f, 3.0f);
gl.glVertex3f(-2.0f, 1.5f, 3.0f);
gl.glVertex3f(-2.0f, -1.5f, 3.0f);
-
+
gl.glVertex3f(2.05f, -1.55f, 3.0f);
gl.glVertex3f(2.05f, 1.55f, 3.0f);
gl.glVertex3f(2.0f, 1.5f, 3.0f);
gl.glVertex3f(2.0f, -1.5f, 3.0f);
gl.glEnd();
-
+
}
-
+
public static void box(GL2 gl) //Usually "box" mean box, but there only one side is enough
{
-
+
gl.glShadeModel(GL2.GL_FLAT);
-
+
if (texture[4] != null) {
texture[4].enable(gl);
texture[4].bind(gl);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
-
+
/* draw the side */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(0.0f, 0.0f, 1.0f);
gl.glTexCoord2f(0, 0);
gl.glVertex3f(-8.0f, -8.0f, 0.0f);
@@ -572,15 +573,15 @@ public class Tennis implements GLEventListener { gl.glVertex3f( 8.0f, -8.0f, 0.0f);
gl.glEnd();
-
+
texture[4].disable(gl);
}
-
+
}
-
+
public static void desk(GL2 gl, int two_or_three)
{
-
+
int i;
float temp1;
@@ -592,94 +593,94 @@ public class Tennis implements GLEventListener { gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
-
+
/* draw the front */
gl.glBegin(GL2.GL_QUAD_STRIP);
-
+
gl.glNormal3f(0.0f, 0.0f, 1.0f);
for (i=0; i<25; i++)
{
temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
-
+
gl.glTexCoord2f((i-12)/40.0f, temp1/4 + 0.75f);
- gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , 0.01f + temp1/25);
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , 0.01f + temp1/25);
gl.glTexCoord2f((i-12)/40.0f, -temp1/4 + 0.25f);
- gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, 0.01f + temp1/25);
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, 0.01f + temp1/25);
}
gl.glEnd();
-
+
/* draw the back */
gl.glBegin(GL2.GL_QUAD_STRIP);
-
+
gl.glNormal3f(0.0f, 0.0f, -1.0f);
for (i=0; i<25; i++)
{
temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
-
+
gl.glTexCoord2f((i-12)/40.0f, temp1/4 + 0.75f);
- gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , -0.01f - temp1/25);
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , -0.01f - temp1/25);
gl.glTexCoord2f((i-12)/40.0f, -temp1/4 + 0.25f);
- gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, -0.01f - temp1/25);
-
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, -0.01f - temp1/25);
+
}
gl.glEnd();
-
+
texture[2].disable(gl);
}
-
+
/* draw the top side */
gl.glBegin(GL2.GL_QUAD_STRIP);
-
+
gl.glNormal3f(0.0f, 1.0f, 0.0f);
for (i=0; i<25; i++)
{
temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
-
- gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , -0.01f - temp1/25);
- gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , 0.01f + temp1/25);
+
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , -0.01f - temp1/25);
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , 0.01f + temp1/25);
}
-
+
gl.glEnd();
-
+
/* draw the bottom side */
gl.glBegin(GL2.GL_QUAD_STRIP);
-
+
gl.glNormal3f(0.0f, -1.0f, 0.0f);
for (i=0; i<25; i++)
- {
+ {
temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
-
- gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, 0.01f + temp1/25);
- gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, -0.01f - temp1/25);
+
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, 0.01f + temp1/25);
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, -0.01f - temp1/25);
}
gl.glEnd();
-
+
/* draw the left and right sides */
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glNormal3f(-1.0f, 0.0f, 0.0f);
gl.glVertex3f((-12)/40.0f, -0.1f, 0.01f);
- gl.glVertex3f((-12)/40.0f, +0.1f, 0.01f);
+ gl.glVertex3f((-12)/40.0f, +0.1f, 0.01f);
gl.glVertex3f((-12)/40.0f, +0.1f, -0.01f);
- gl.glVertex3f((-12)/40.0f, -0.1f, -0.01f);
-
+ gl.glVertex3f((-12)/40.0f, -0.1f, -0.01f);
+
gl.glNormal3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f((+12)/40.0f, -0.1f, 0.01f);
- gl.glVertex3f((+12)/40.0f, +0.1f, 0.01f);
+ gl.glVertex3f((+12)/40.0f, +0.1f, 0.01f);
gl.glVertex3f((+12)/40.0f, +0.1f, -0.01f);
- gl.glVertex3f((+12)/40.0f, -0.1f, -0.01f);
+ gl.glVertex3f((+12)/40.0f, -0.1f, -0.01f);
gl.glEnd();
-
+
}
-
+
public static void ball(GL2 gl)
{
-
+
int i,j;
float y1,y2,r1,r2,x,z;
@@ -687,21 +688,21 @@ public class Tennis implements GLEventListener { /* draw the ball */
gl.glBegin(GL2.GL_QUAD_STRIP);
-
+
for (i=0; i<20; i++)
{
y1 = (float) Math.cos((i)/20.0f*Math.PI)/10;
y2 = (float) Math.cos((i+1)/20.0f*Math.PI)/10;
r1 = (float) Math.sqrt(Math.abs(0.01f-y1*y1));
r2 = (float) Math.sqrt(Math.abs(0.01f-y2*y2));
-
+
for (j=0; j<21; j++)
{
x = (float) (r1*Math.cos((float)j/21*2.0f*Math.PI));
z = (float) (r1*Math.sin((float)j/21*2.0f*Math.PI));
gl.glNormal3f(10*x, 10*y1, 10*z);
gl.glVertex3f(x, y1, z);
-
+
x = (float) (r2*Math.cos((float)j/21*2.0f*Math.PI));
z = (float) (r2*Math.sin((float)j/21*2.0f*Math.PI));
gl.glNormal3f(10*x, 10*y2, 10*z);
@@ -710,19 +711,19 @@ public class Tennis implements GLEventListener { }
gl.glEnd();
-
+
}
-
+
public void MoveSphere()
{
-
+
// Ball out
if ((BallCz>3)||(BallCz<-3))
{
-
+
Vec=BallCz;
-
+
BallCx = 0.0f;
BallCy = 0.0f;
BallCz = 0.0f;
@@ -732,7 +733,7 @@ public class Tennis implements GLEventListener { spy=0;
CanF=false;
-
+
Bax=0;
Bay=0;
@@ -742,20 +743,20 @@ public class Tennis implements GLEventListener { if ((spz<0)&&(BallCz+spz<-2.8)&&(BallCx+spx<EnDeskCx+0.3)&&(BallCx+spx>EnDeskCx-0.3)&&(BallCy+spy<EnDeskCy+0.2)&&(BallCy+spy>EnDeskCy-0.2))
{
-
+
spz=-spz+0.002f;
spx=spx+(BallCx-EnDeskCx)/10;
- spy=spy+(BallCy-EnDeskCy)/10;
-
+ spy=spy+(BallCy-EnDeskCy)/10;
+
}
if ((spz>0)&&(BallCz+spz>2.8)&&(BallCx+spx<sx+0.3)&&(BallCx+spx>sx-0.3)&&(BallCy+spy<sy+0.2)&&(BallCy+spy>sy-0.2))
{
-
+
spz=-spz-0.002f;
spx=spx+(BallCx-sx)/10;
spy=spy+(BallCy-sy)/10;
-
+
Bax=DspeedX/100;
Bay=DspeedY/100;
@@ -775,23 +776,23 @@ public class Tennis implements GLEventListener { // Ball move
if (CanF==true)
-
+
BallCx += spx;
BallCy += spy;
BallCz += spz;
-
+
//Less the acceleration
Bax=Bax-Bax/100;
Bay=Bay-Bay/100;
-
+
}
-
+
public void MoveEnDesk()
{
//Just follow for the ball
-
+
float sx,sy;
double gip=Math.sqrt((BallCx-EnDeskCx)*(BallCx-EnDeskCx)+(BallCy-EnDeskCy)*(BallCy-EnDeskCy));
@@ -806,7 +807,7 @@ public class Tennis implements GLEventListener { sy=Math.abs((BallCy-EnDeskCy))/((float) gip)*0.07f;
}
- if ((BallCx-EnDeskCx>0)&&(EnDeskCx+sx<=1.7))
+ if ((BallCx-EnDeskCx>0)&&(EnDeskCx+sx<=1.7))
EnDeskCx += sx;
if ((BallCx-EnDeskCx<0)&&(EnDeskCx-sx>=-1.7))
@@ -819,32 +820,32 @@ public class Tennis implements GLEventListener { EnDeskCy -= sy;
}
-
+
public void MovMydesk() {
-
+
LPositionDX = sx;
LPositionDY = sy;
-
- int x = MouseInfo.getPointerInfo().getLocation().x;
+
+ int x = MouseInfo.getPointerInfo().getLocation().x;
int y = MouseInfo.getPointerInfo().getLocation().y;
- sx = sx + (float)(x-500.0f)/300.0f;
- sy = sy + (float)(400.0f-y)/300.0f;
-
+ sx = sx + (x-500.0f)/300.0f;
+ sy = sy + (400.0f-y)/300.0f;
+
//Check cube borders
-
+
if (sx<-1.7f || sx>1.7f)
- {
+ {
if (sx>0) sx = 1.7f;
else sx = -1.7f;
}
-
+
if (sy<-1.3 || sy>1.3)
- {
+ {
if (sy>0) sy = 1.3f;
else sy = -1.3f;
}
-
+
//Return the mouse back from screen borders
try {
Robot r = new Robot();
@@ -855,66 +856,66 @@ public class Tennis implements GLEventListener { NPositionDY=sy;
DspeedX=NPositionDX-LPositionDX;
- DspeedY=NPositionDY-LPositionDY;
-
+ DspeedY=NPositionDY-LPositionDY;
+
}
-
- class TennisKeyAdapter extends KeyAdapter {
+
+ class TennisKeyAdapter extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int kc = e.getKeyCode();
if(KeyEvent.VK_ESCAPE == kc) {
System.exit(0);
- }
+ }
if(KeyEvent.VK_CONTROL == kc) {
control = false;
- }
+ }
if(KeyEvent.VK_SPACE == kc) { //Ready for play
if (CanF==false)
- {
+ {
if (Vec<0)
- spz=-0.07f;
+ spz=-0.07f;
else
spz=0.07f;
}
CanF=true;
}
}
-
- public void keyReleased(KeyEvent e) { //Give the mouse control to the user
+
+ public void keyReleased(KeyEvent e) { //Give the mouse control to the user
int kc = e.getKeyCode();
if(KeyEvent.VK_CONTROL == kc) {
control = true;
- }
+ }
}
-
+
}
-
+
class TennisMouseAdapter extends MouseAdapter {
public void mousePressed(MouseEvent e) {
prevMouseX = e.getX();
prevMouseY = e.getY();
-
+
mouseButtonDown = true;
}
-
+
public void mouseReleased(MouseEvent e) {
mouseButtonDown = false;
}
-
+
public void mouseDragged(MouseEvent e) {
-
+
int x = e.getX();
int y = e.getY();
-
+
float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)WindowW);
float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)WindowH);
-
+
prevMouseX = x;
- prevMouseY = y;
-
+ prevMouseY = y;
+
view_rotx += thetaX;
view_roty += thetaY;
}
}
-
+
}
|