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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
package demos.nurbs.curveapp;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.glu.*;
import com.jogamp.opengl.util.GLUT;
/**
* Listener raacting to OpenGL canvas events
* Listener reagující na události na OpenGL plátně
* @author Tomáš Hráský
*
*/
public class GLListener implements GLEventListener {
/**
* OpenGL object
* objekt realizující základní OpenGL funkce
*/
private GL gl;
/**
* GLU
* Objekt realizující funkce nadstavbové knihovny GLU
*/
private GLU glu;
/**
* GLUT object
* Objekt realizující funkce nadstavbové knihovny GLUT
*/
private GLUT glut;
/**
* NURBS curve object
* OpenGL Objekt NURBS křivky
*/
private GLUnurbs nurbs;
/* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#init(com.jogamp.opengl.GLAutoDrawable)
*/
public void init(GLAutoDrawable drawable) {
this.gl = drawable.getGL();
this.glu = new GLU();
this.glut=new GLUT();
this.nurbs = glu.gluNewNurbsRenderer();
gl.glClearColor(1, 1, 1, 1);
}
public void dispose(GLAutoDrawable drawable) {
this.gl = null;
this.glu = null;
this.glut=null;
this.nurbs = null;
}
/* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#display(com.jogamp.opengl.GLAutoDrawable)
*/
public void display(GLAutoDrawable drawable) {
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
gl.glLoadIdentity();
float[] knots = Curve.getInstance().getKnots();
float[] ctrlpoints = Curve.getInstance().getCtrlPoints();
gl.glEnable(GL.GL_LINE_SMOOTH);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_DONT_CARE);
gl.glLineWidth(3);
if(Curve.getInstance().isCurveFinished()){
glu.gluBeginCurve(nurbs);
glu.gluNurbsCurve(nurbs, knots.length, knots, 4, ctrlpoints, Curve.getInstance().getOrder(), GL.GL_MAP1_VERTEX_4);
glu.gluEndCurve(nurbs);
}
gl.glColor3f(0,0,0);
gl.glPointSize(5);
gl.glBegin(GL.GL_POINTS);
for (int i = 0; i < ctrlpoints.length / 4; i++) {
// if(i!=Curve.getInstance().getBodIndex())
gl.glVertex3d(ctrlpoints[i * 4]/ctrlpoints[i * 4 + 3], ctrlpoints[i * 4 + 1]/ctrlpoints[i * 4 + 3],
ctrlpoints[i * 4 + 2]/ctrlpoints[i * 4 + 3]);
}
gl.glEnd();
for (int i = 0; i < ctrlpoints.length / 4; i++) {
// if(i!=Curve.getInstance().getBodIndex())
// gl.glPushMatrix();
gl.glRasterPos2f(ctrlpoints[i * 4]/ctrlpoints[i * 4 + 3], ctrlpoints[i * 4 + 1]/ctrlpoints[i * 4 + 3]-5);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18,String.valueOf(i+1));
// gl.glPopMatrix();
}
gl.glLineWidth(1);
gl.glBegin(GL.GL_LINE_STRIP);
for (int i = 0; i < ctrlpoints.length / 4; i++) {
// if(i!=Curve.getInstance().getBodIndex())
gl.glVertex3d(ctrlpoints[i * 4]/ctrlpoints[i * 4 + 3], ctrlpoints[i * 4 + 1]/ctrlpoints[i * 4 + 3],
ctrlpoints[i * 4 + 2]/ctrlpoints[i * 4 + 3]);
}
gl.glEnd();
gl.glColor3f(0,0,1);
if(Curve.getInstance().getBodIndex()>=0){
gl.glPointSize(8);
gl.glBegin(GL.GL_POINTS);
int i=Curve.getInstance().getBodIndex();
gl.glVertex3d(ctrlpoints[i * 4]/ctrlpoints[i * 4 + 3], ctrlpoints[i * 4 + 1]/ctrlpoints[i * 4 + 3],
ctrlpoints[i * 4 + 2]/ctrlpoints[i * 4 + 3]);
gl.glEnd();
}
}
/* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#reshape(com.jogamp.opengl.GLAutoDrawable, int, int, int, int)
*/
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height) {
gl.glMatrixMode(GL2ES1.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, drawable.getWidth(), 0, drawable.getHeight(), -1, 1);
gl.glScalef(1, -1, 1);
gl.glTranslatef(0, -drawable.getHeight(), 0);
}
/* (non-Javadoc)
* @see com.jogamp.opengl.GLEventListener#displayChanged(com.jogamp.opengl.GLAutoDrawable, boolean, boolean)
*/
public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
}
}
|