1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/**
* @(#) glutplane.java
* @(#) author: Mark J. Kilgard (converted to Java by Ron Cemer)
*/
/* This program is freely distributable without licensing fees
and is provided without guarantee or warrantee expressed or
implied. This program is -not- in the public domain. */
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.util.*;
import gl4java.GLContext;
import gl4java.GLFunc;
import gl4java.GLUFunc;
import gl4java.GLEnum;
import gl4java.GLUEnum;
import gl4java.awt.GLAnimCanvas;
import gl4java.applet.SimpleGLAnimApplet1;
public class GlutPlaneObj
implements GLEnum, GLUEnum
{
float speed = 0.0f; /* zero speed means not flying */
float red = 0.0f, green = 0.0f, blue = 0.0f;
float theta = 0.0f;
public float x = 0.0f, y = 0.0f, z = 0.0f, angle = 0.0f;
public void setPosition(float x, float y, float z)
{
this.x=x;
this.y=y;
this.z=z;
}
public void setColor(float r, float g, float b)
{
red = r;
green = g;
blue = b;
}
private final double M_PI = 3.14159265;
private final double M_PI_2 = 1.57079632;
GLFunc gl;
GLUFunc glu;
public GlutPlaneObj(GLFunc gl, GLUFunc glu)
{
this.gl=gl;
this.glu=glu;
}
public void display()
{
if (speed != 0.0f)
{
tick();
// System.out.println("plane: ("+x+"/"+y+"/"+z+")");
gl.glPushMatrix();
gl.glTranslatef(x, y, z);
gl.glRotatef(290.0f, 1.0f, 0.0f, 0.0f);
gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
// gl.glScalef(1.0f / 3.0f, 1.0f / 4.0f, 1.0f / 4.0f);
gl.glScalef(5.0f, 5.0f, 5.0f);
gl.glTranslatef(0.0f, -4.0f, -1.5f);
gl.glBegin(GL_TRIANGLE_STRIP);
/* left wing */
gl.glVertex3f(-7.0f, 0.0f, 2.0f);
gl.glVertex3f(-1.0f, 0.0f, 3.0f);
gl.glColor3f(red,green,blue);
gl.glVertex3f(-1.0f, 7.0f, 3.0f);
/* left side */
gl.glColor3f(0.6f * red, 0.6f * green, 0.6f * blue);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glVertex3f(0.0f, 8.0f, 0.0f);
/* right side */
gl.glVertex3f(1.0f, 0.0f, 3.0f);
gl.glVertex3f(1.0f, 7.0f, 3.0f);
/* final tip of right wing */
gl.glColor3f(red, green, blue);
gl.glVertex3f(7.0f, 0.0f, 2.0f);
gl.glEnd();
gl.glPopMatrix();
}
}
public void tick()
{
/*
posx = 4500.0f;
posy = 256.0f;
posz = 4500.0f;
*/
theta += speed;
z = 4500.0f + 600.0f * (float)Math.cos(theta);
x = 4500.0f + 600.0f * (float)Math.sin(2.0f * theta);
y = 280.0f + (float)Math.sin(theta / 3.4f) * 20.0f;
angle = (float)
(((Math.atan(2.0) + M_PI_2) * Math.sin(theta) - M_PI_2) *
180.0 / M_PI);
if (speed < 0.0f) angle += 180.0f;
}
}
|