Curso Java 3D Módulo 19-LibroTrabajoContruccionSatelite-v01
Curso Java 3D Módulo 19-LibroTrabajoContruccionSatelite-v01
Curso Java 3D Módulo 19-LibroTrabajoContruccionSatelite-v01
Satelite Básico
java3D
Prof. Andrés E. Castillo R.
EL
EL programa D
Demo Satelite
S t lit está
tá compuesto
t de:
d
• Ventana que extends de JFrame.
• Escena Grafica conformada por un SimpleUniverse.
• Rama Geometrica
Rama Geometrica conformada por un objeto
un objeto Satelite.
1 import javax.swing.*;
2 class DemoSatelite extends JFrame
3 {
4 DemoSatelite()
5 {
6 super("Demo Satelite");
7 EscenaGraficaSatelite eg = new EscenaGraficaSatelite();
8 setSize(700,500);
9 setLocation(200,200);
10 getContentPane().add("Center",eg.getCanvas3D());
11 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12 setVisible(true);
13 }
14 public static void main(String[] args)
15 {
16 DemoSatelite demo = new DemoSatelite();
17 }
18 }
19
Page 1 of 1
Escena Grafica
EscenaGraficaSatelite.java 31/01/2009 09:29 p.m.
1 import javax.media.j3d.*;
2 import com.sun.j3d.utils.universe.*;
3 import com.sun.j3d.utils.geometry.*;
4 import javax.vecmath.*;
5 import java.awt.*;
6
7
8 class EscenaGraficaSatelite
9 {
10 Canvas3D canvas3D;
11 EscenaGraficaSatelite()
12 {
13 GraphicsConfiguration config = SimpleUniverse.getPreferredConfig
14 canvas3D = new Canvas3D(config);
15 SimpleUniverse su = new SimpleUniverse(canvas3D);
16 double x,y,z;
17 double r,phi,tetha;
18 r = 25.0;
19 phi = 60.0;
20 tetha =35.0;
21 x = r*Math.cos(Math.toRadians(tetha))*Math.sin(Math.toRadians(ph
22 y = r*Math.cos(Math.toRadians(tetha))*Math.cos(Math.toRadians(ph
23 z = r*Math.sin(Math.toRadians(tetha));
24 Transform3D t3d = new Transform3D();
25 t3d.lookAt( new Point3d(x,y,z),new Point3d(0.0,0.0,0.0), new Vec
26 t3d.invert();
27 su.getViewingPlatform().getViewPlatformTransform().setTransform(
28 BranchGroup bg = new BranchGroup();
29 Satelite satelite = new Satelite();
30 satelite.rotarEjeY(45);
31 satelite.rotarEjeZ(45);
32 bg.addChild(satelite);
33 bg.compile();
34 su.addBranchGraph(bg);
35 }
36 public Canvas3D getCanvas3D()
37 {
38 return canvas3D;
39 }
40 }
41
Page 1 of 1
Satelite
Satelite.java 31/01/2009 09:27 p.m.
1 import java.awt.*;
2 import javax.swing.*;
3 import javax.media.j3d.*;
4 import javax.vecmath.*;
5 import com.sun.j3d.utils.geometry.*;
6 import com.sun.j3d.utils.universe.*;
7 import com.sun.j3d.utils.behaviors.keyboard.*;
8
9 public class Satelite extends BranchGroup
10 {
11
12 private float x,y,z;
13 private TransformGroup rotacionAlas,rotacionCilindro;
14 private TransformGroup rotacion;
15 private TransformGroup traslacionSatelite;
16 private TransformGroup traslacionAla1,traslacionAla2;
17 private Patron1 patronAnt1,patronAnt2,patronAnt3;
18 private Conoide conoAnt1,conoAnt2,conoAnt3;
19 private Paraboloide paraboloide1,paraboloide2,paraboloide3;
20 private TransformGroup traslacionParaboloide1,traslacionParaboloide
21 private TransformGroup cambiarTamaño;
22 private BranchGroup sat;
23 private Transform3D rot ;
24 private double refZ,refX,refY;
25 private Transform3D utility,utility2,utility3,utility4,utility5,uti
26 private TransparencyAttributes ta;
27 public Satelite()
28 {
29 //Paraboloides
30 utility = new Transform3D();
31 utility2 = new Transform3D();
32 utility3 = new Transform3D();
33 utility4 = new Transform3D();
34 utility5 = new Transform3D();
35 utility6 = new Transform3D();
36 traslacionParaboloide1 = new TransformGroup();
37 traslacionParaboloide2 = new TransformGroup();
38 traslacionParaboloide3 = new TransformGroup();
39 paraboloide1 = new Paraboloide(1.0,0.35,100,100);
40 paraboloide2 = new Paraboloide(1.0,0.35,100,100);
41 paraboloide3 = new Paraboloide(1.0,0.35,100,100);
42 patronAnt1 = new Patron1(8.0,7,7,100,100,1.0f);
43 patronAnt2 = new Patron1(8.0,7,7,100,100,1.0f);
44 patronAnt3 = new Patron1(8.0,7,7,100,100,1.0f);
45 conoAnt1 = new Conoide(12.0f,10.0f,5,180,0.7f);
46 conoAnt2 = new Conoide(12.0f,10.0f,5,180,0.7f);
47 conoAnt3 = new Conoide(12.0f,10.0f,5,180,0.7f);
48 traslacionParaboloide1.addChild(paraboloide1);
49 traslacionParaboloide2.addChild(paraboloide2);
50 traslacionParaboloide3.addChild(paraboloide3);
51 traslacionParaboloide1.addChild(patronAnt1);
Page 1 of 8
Satelite.java 31/01/2009 09:27 p.m.
52 traslacionParaboloide2.addChild(patronAnt2);
53 traslacionParaboloide3.addChild(patronAnt3);
54 traslacionParaboloide1.addChild(conoAnt1);
55 traslacionParaboloide2.addChild(conoAnt2);
56 traslacionParaboloide3.addChild(conoAnt3);
57
58
59 Transform3D traslacionP1 = new Transform3D();
60 traslacionP1.setTranslation(new Vector3f(0.0f,0.0f,0.6f));
61 traslacionParaboloide1.setTransform(traslacionP1);
62 Transform3D traslacionP2 = new Transform3D();
63 traslacionP2.setTranslation(new Vector3f(0.0f,1.20f,-0.5f));
64 traslacionParaboloide2.setTransform(traslacionP2);
65 Transform3D traslacionP3 = new Transform3D();
66 traslacionP3.setTranslation(new Vector3f(0.0f,-1.20f,-0.5f));
67 traslacionParaboloide3.setTransform(traslacionP3);
68 rot = new Transform3D();
69 rotacion = new TransformGroup();
70 refZ = 0.0;
71 refX = 0.0;
72 refY = 0.0;
73 float r = 1.0f;
74 float tetha = 90.0f;
75 float phi = 0.0f;
76 this.x =r*(float)(Math.sin(tetha*Math.PI/180.0)*Math.cos(phi*Ma
77 this.y =r*(float)(Math.sin(tetha*Math.PI/180.0)*Math.sin(phi*Ma
78 this.z =r*(float)(Math.cos(tetha*Math.PI/180));
79
80 traslacionSatelite = new TransformGroup();
81 moverSatelite(this.x,this.y,this.z);
82 rotacionAlas = new TransformGroup();
83 traslacionAla1 = new TransformGroup();
84 traslacionAla2 = new TransformGroup();
85 cambiarTamaño = new TransformGroup();
86
87 rotacionAlas.setCapability(TransformGroup.ALLOW_TRANSFORM_READ)
88 rotacionAlas.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE
89 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
90 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
91 traslacionSatelite.setCapability(TransformGroup.ALLOW_TRANSFORM
92 traslacionSatelite.setCapability(TransformGroup.ALLOW_TRANSFORM
93 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_READ
94 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_WRIT
95 com.sun.j3d.utils.geometry.Box caja =
96 new com.sun.j3d.utils.geometry.Box(0.5f,
97 0.5f,0.
98 Appearance colorCaja = new Appearance();
99 colorCaja.setColoringAttributes(new ColoringAttributes(1.0f,0.0
100 ColoringAttributes.SHADE_G
101
102
Page 2 of 8
Satelite.java 31/01/2009 09:27 p.m.
Page 3 of 8
Satelite.java 31/01/2009 09:27 p.m.
Page 4 of 8
Satelite.java 31/01/2009 09:27 p.m.
205 //rotacionY.rotY((giroEjeY-refY)*Math.PI/180.0d);
206 //rot.mul(rotacionY);
207 //Transform3D rotacionY = new Transform3D();
208 utility3.rotY((giroEjeY-refY)*Math.PI/180.0d);
209 rot.mul(utility3);
210 this.rotacion.setTransform(rot);
211 refY = giroEjeY;
212 }
213
214 public void rotarEjeX(double giroEjeX)
215 {
216 //Transform3D rotacionX = new Transform3D();
217 //rotacionX.rotX((giroEjeX-refX)*Math.PI/180.0d);
218 //rot.mul(rotacionX);
219 utility4.rotX((giroEjeX-refX)*Math.PI/180.0d);
220 rot.mul(utility4);
221 this.rotacion.setTransform(rot);
222 refX = giroEjeX;
223 }
224
225 public void rotarAlas(double giroAlas)
226 {
227 //Transform3D rotacion = new Transform3D();
228 //rotacion.rotX(giroAlas*Math.PI/180.0d);
229 //Transform3D rotacion = new Transform3D();
230 utility5.rotX(giroAlas*Math.PI/180.0d);
231 this.rotacionAlas.setTransform(utility5);
232 }
233 public void escalar(double tamaño)
234 {
235 //Transform3D cambioTamaño = new Transform3D();
236 //cambioTamaño.setScale(tamaño);
237 utility6.setScale(tamaño);
238 cambiarTamaño.setTransform(utility6);
239 }
240 public void setX(float x)
241 {
242 this.x = x;
243 moverSatelite(this.x, this.y, this.z);
244
245 }
246 public void setY(float y)
247 {
248 this.y = y;
249 moverSatelite(this.x, this.y, this.z);
250
251 }
252 public void setZ(float z)
253 {
254 this.z = z;
255 moverSatelite(this.x, this.y, this.z);
Page 5 of 8
Satelite.java 31/01/2009 09:27 p.m.
256 }
257 public double getX()
258 {
259 return this.x;
260 }
261 public double getY()
262 {
263 return this.y;
264 }
265 public double getZ()
266 {
267 return this.z;
268 }
269 public float getR()
270 {
271 return (float) Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2)+
272 }
273 public float getPhi()
274 {
275 float aux = 0.0f;
276 if(this.x == 0)
277 {
278 if(this.y >= 0)
279 {
280 aux = 90.0f;
281 }
282 else
283 {
284 aux = 270.0f;
285 }
286 }
287 if(this.x > 0)
288 {
289 if(this.y>=0)
290 {
291
292 aux = (float) ( Math.atan(Math.abs(this.y/this.x))*180.
293 System.out.println("Llamaron a getPhi() cuadro I: " +
294 }
295 else
296 {
297 aux = 360.0f-(float) ( Math.atan(Math.abs(this.y/this.x
298 System.out.println("Llamaron a getPhi() cuadro IV: " +
299 }
300 }
301 if(this.x < 0)
302 {
303 if(this.y>=0)
304 {
305 aux = 180.0f-(float) ( Math.atan(Math.abs(this.y/this.x
306 System.out.println("Llamaron a getPhi() cuadro II: " +
Page 6 of 8
Satelite.java 31/01/2009 09:27 p.m.
307 }
308 else
309 {
310 aux = 180.0f+(float) ( Math.atan(Math.abs(this.y/this.x
311 System.out.println("Llamaron a getPhi() cuadro III: "
312 }
313 }
314
315 return aux;
316
317 }
318 public float getTetha()
319 {
320 return (float) ( Math.acos(this.z/getR())*180.0/Math.PI);
321 }
322 public void set_R_Phi_Tetha(float r, float phi, float tetha)
323 {
324 this.x =r*(float)(Math.sin(Math.toRadians(tetha))*Math.cos(Math
325 this.y =r*(float)(Math.sin(Math.toRadians(tetha))*Math.sin(Math
326 this.z =r*(float)(Math.cos(Math.toRadians(tetha)));
327 moverSatelite(this.x, this.y, this.z);
328 }
329 public void setR(float r)
330 {
331 set_R_Phi_Tetha(r,getPhi(),getTetha());
332 }
333 public void setPhi(float phi)
334 {
335 set_R_Phi_Tetha(getR(),phi,getTetha());
336 }
337 public void setTetha(float tetha)
338 {
339 set_R_Phi_Tetha(getR(),getPhi(),tetha);
340 }
341
342 public Paraboloide getParaboloide1()
343 {
344 return paraboloide1;
345 }
346
347 public Paraboloide getParaboloide2()
348 {
349 return paraboloide2;
350 }
351
352 public Paraboloide getParaboloide3()
353 {
354 return paraboloide3;
355 }
356 public Patron1 getPatronAnt1()
357 {
Page 7 of 8
Satelite.java 31/01/2009 09:27 p.m.
Page 8 of 8
Paraboloide
Paraboloide.java 31/01/2009 09:27 p.m.
1 import javax.media.j3d.*;
2 import javax.vecmath.*;
3
4 public class Paraboloide extends BranchGroup
5 {
6 double diametro, rfd, giroX,giroY,giroZ,giroPlato,x,y,z;
7 int n,m;
8 TransformGroup rotacion,traslacion,cambiarTamaño,girarPlato;
9 Transform3D rot,rotarPlato,utility;
10
11 public Paraboloide(double diametro, double rfd, int n , int m)
12 {
13 utility = new Transform3D();
14 rot = new Transform3D();
15 girarPlato = new TransformGroup();
16 rotarPlato = new Transform3D();
17 girarPlato.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
18 girarPlato.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
19 this.x = 0.0;
20 this.y = 0.0;
21 this.z = 0.0;
22 giroX = 0.0;
23 giroY = 0.0;
24 giroZ = 0.0;
25 giroPlato = 0.0;
26 this.diametro = diametro;
27 this.rfd = rfd;
28 this.m = m;
29 this.n = n;
30 int[] verticeporTiras = new int[n];
31 int formato = TriangleStripArray.COORDINATES | TriangleStripArr
32 Point3d punto = new Point3d();
33 double posX,posY,posZ;
34 double deltaPhi = 360.0/(this.n-1);
35 double deltaRho = this.diametro/(2*(m-1));
36 double foco = rfd*this.diametro;
37 Color3f amarillo = new Color3f(0.7f,1.7f,0.7f);
38 Color3f verde = new Color3f(0.4f,0.4f,0.4f);
39 for (int s = 0;s < n ;s++ )
40 {
41 verticeporTiras[s] = 2*m;
42 }
43 TriangleStripArray geoPar1 = new TriangleStripArray(2*m*n,forma
44 TriangleStripArray geoPar2 = new TriangleStripArray(2*m*n,forma
45
46 for (int i = 0; i < n ;i++ )
47 for (int j = 0; j<m ;j++ )
48 for(int k = 0; k<2;k++)
49
50 {
51 posX = (j*deltaRho)*Math.cos((i+k)*deltaPhi*Math.PI/180.0);
Page 1 of 4
Paraboloide.java 31/01/2009 09:27 p.m.
52 posY = (j*deltaRho)*Math.sin((i+k)*deltaPhi*Math.PI/180.0);
53 posZ =(Math.pow(posX,2)+Math.pow(posY,2))/(4*foco);
54 punto = new Point3d(posX,posY,posZ);
55 geoPar1.setCoordinate(i*2*m+2*j+k,punto);
56 geoPar1.setColor(i*2*m+2*j+k,verde);
57 }
58
59 for (int i = 0; i < n ;i++ )
60 for (int j = 0; j<m ;j++ )
61 for(int k = 0; k<2;k++)
62
63 {
64 posX = (j*deltaRho)*Math.cos((i+k)*deltaPhi*Math.PI/180.0);
65 posY = (j*deltaRho)*Math.sin((i+k)*deltaPhi*Math.PI/180.0);
66 posZ =(Math.pow(posX,2)+Math.pow(posY,2))/(4*foco);
67 punto = new Point3d(posX,posY,posZ);
68 geoPar2.setCoordinate(i*2*m+2*j+k,punto);
69 geoPar2.setColor(i*2*m+2*j+k,amarillo);
70 }
71
72 PolygonAttributes apPoly = new PolygonAttributes();
73 apPoly.setCullFace(PolygonAttributes.CULL_NONE);
74 Appearance dosCaras = new Appearance();
75 dosCaras.setPolygonAttributes(apPoly);
76
77 PolygonAttributes apPol1 = new PolygonAttributes();
78 apPol1.setCullFace(PolygonAttributes.CULL_BACK);
79 Appearance caraAnterior = new Appearance();
80 caraAnterior.setPolygonAttributes(apPol1);
81
82 PolygonAttributes apPol2 = new PolygonAttributes();
83 apPol2.setCullFace(PolygonAttributes.CULL_FRONT);
84 Appearance caraPosterior= new Appearance();
85 caraPosterior.setPolygonAttributes(apPol2);
86
87 Shape3D parabolica1 = new Shape3D(geoPar1,caraPosterior);
88 Shape3D parabolica2 = new Shape3D(geoPar2,caraAnterior);
89 rotacion = new TransformGroup();
90 traslacion = new TransformGroup();
91 cambiarTamaño = new TransformGroup();
92 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
93 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
94 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
95 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
96 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_WRIT
97 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_READ
98 BranchGroup parabolica = new BranchGroup();
99 parabolica.addChild(parabolica1);
100 parabolica.addChild(parabolica2);
101 girarPlato.addChild(parabolica);
102 rotacion.addChild(girarPlato);
Page 2 of 4
Paraboloide.java 31/01/2009 09:27 p.m.
103 traslacion.addChild(rotacion);
104 LineArray ejeZ = new LineArray(2,LineArray.COORDINATES);
105 ejeZ.setCoordinate(0,new Point3f(0.0f,0.0f,-3.0f));
106 ejeZ.setCoordinate(1,new Point3f(0.0f,0.0f,3.0f));
107 LineArray ejeY = new LineArray(2,LineArray.COORDINATES);
108 ejeY.setCoordinate(0,new Point3f(0.0f,-3.0f,-0.0f));
109 ejeY.setCoordinate(1,new Point3f(0.0f,3.0f,0.0f));
110
111 LineArray ejeY2 = new LineArray(2,LineArray.COORDINATES);
112 ejeY2.setCoordinate(0,new Point3f(0.0f,-3.0f,-0.0f));
113 ejeY2.setCoordinate(1,new Point3f(0.0f,3.0f,0.0f));
114
115 this.addChild(traslacion);
116 this.compile();
117 }
118
119 public void girarX(double alfa)
120 {
121 giroX = alfa-giroX;
122 //Transform3D girarEjeX = new Transform3D();
123 utility.rotX(giroX*Math.PI/180.0d);
124 rot.mul(utility);
125 rotacion.setTransform(rot);
126 giroX = alfa;
127 }
128
129 public void girarY(double alfa)
130 {
131 giroY = alfa-giroY;
132 //Transform3D girarEjeY = new Transform3D();
133 //girarEjeY.rotY(giroY*Math.PI/180.0d);
134 //rot.mul(girarEjeY);
135 utility.rotY(giroY*Math.PI/180.0d);
136 rot.mul(utility);
137 rotacion.setTransform(rot);
138 giroY = alfa;
139 }
140 public void girarZ(double alfa)
141 {
142 giroZ = alfa-giroZ;
143 //Transform3D girarEjeZ = new Transform3D();
144 //girarEjeZ.rotZ(giroZ*Math.PI/180.0d);
145 //rot.mul(girarEjeZ);
146 utility.rotZ(giroZ*Math.PI/180.0d);
147 rot.mul(utility);
148 rotacion.setTransform(rot);
149 giroZ = alfa;
150 }
151
152 public void girarParaboloide(double alfa)
153 {
Page 3 of 4
Paraboloide.java 31/01/2009 09:27 p.m.
Page 4 of 4
Conoide
Conoide.java 31/01/2009 09:28 p.m.
1 //package patrones;
2
3 import javax.media.j3d.*;
4 import javax.vecmath.Color3f;
5 import javax.vecmath.Point3d;
6 import javax.vecmath.Vector3f;
7
8 public class Conoide extends BranchGroup
9 {
10 double alcance, anchoHaz,x,y,z;
11 int n,m;
12 TransformGroup rotacion,traslacion,cambiarTamaño;
13 double refZ,refX,refY;
14 Transform3D rot,
15 utility,utility2,utility3,utility4,utility5,utility6;
16 TransparencyAttributes ta;
17 Shape3D conoExterior;
18 Color3f amarillo;
19 float transparencia;
20 public Conoide(double altura, double anchoHaz, int m, int n, float
21 {
22 this.m = m;
23 this.n = n;
24 this.alcance = altura;
25 this.anchoHaz = anchoHaz;
26 this.transparencia = transparencia;
27 utility = new Transform3D();
28 utility2 = new Transform3D();
29 utility3 = new Transform3D();
30 utility4 = new Transform3D();
31 utility5 = new Transform3D();
32 utility6 = new Transform3D();
33
34 refX = 0.0;
35 refY = 0.0;
36 refZ = 0.0;
37 rot = new Transform3D();
38 this.x = 0.0;
39 this.y = 0.0;
40 this.z = 0.0;
41
42 ta = new TransparencyAttributes(TransparencyAttributes.SCREEN_D
43 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
44 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
45
46
47
48 amarillo = new Color3f(1.0f,1.0f,0.0f);
49 Color3f amarilloClaro = new Color3f(1.0f,1.0f,0.0f);
50
51 conoExterior = new Shape3D();
Page 1 of 5
Conoide.java 31/01/2009 09:28 p.m.
52 conoExterior.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
53 conoExterior.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
54 this.crearCono(this.alcance,this.anchoHaz,this.m,this.n,amarill
55
56
57 rotacion = new TransformGroup();
58 traslacion = new TransformGroup();
59 cambiarTamaño = new TransformGroup();
60 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
61 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
62 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
63 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
64 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_WRIT
65 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_READ
66 rotacion.addChild(conoExterior);
67 traslacion.addChild(rotacion);
68 this.addChild(traslacion);
69 this.compile();
70 }
71
72 public void girarX(double giroX)
73 {
74 /*Transform3D rotacionX = new Transform3D();
75 rotacionX.rotX((giroX-refX)*Math.PI/180.0d);
76 rot.mul(rotacionX);*/
77 utility.rotX((giroX-refX)*Math.PI/180.0d);
78 rot.mul(utility);
79 this.rotacion.setTransform(rot);
80 refX = giroX;
81 }
82
83 public void girarZ(double giroZ)
84 {
85
86 /*Transform3D rotacionZ = new Transform3D();
87 rotacionZ.rotZ((giroZ-refZ)*Math.PI/180.0d);
88 rot.mul(rotacionZ);*/
89 utility2.rotZ((giroZ-refZ)*Math.PI/180.0d);
90 rot.mul(utility2);
91 this.rotacion.setTransform(rot);
92 refZ = giroZ;
93 }
94
95 public void girarY(double giroY)
96 {
97 /*Transform3D rotacionY = new Transform3D();
98 rotacionY.rotY((giroY-refY)*Math.PI/180.0d);
99 rot.mul(rotacionY);*/
100 utility3.rotY((giroY-refY)*Math.PI/180.0d);
101 rot.mul(utility3);
102 this.rotacion.setTransform(rot);
Page 2 of 5
Conoide.java 31/01/2009 09:28 p.m.
Page 3 of 5
Conoide.java 31/01/2009 09:28 p.m.
154 }
155 }
156 public double getF2(int i, int k, double deltaPhi)
157 {
158 if (Math.abs((i+k)*deltaPhi) <= 360)
159 {
160 double PI = Math.PI;
161 return 1;
162 }
163 else
164 {
165 return 0.0;
166 }
167 }
168
169 public void ajustarTransparencia(float valorTransparencia)
170 {
171 ta.setTransparency(valorTransparencia);
172
173 }
174
175 private void crearCono(double altura,double anchoHaz, int m, int n,
176 Color3f color, float transparencia)
177 {
178 this.alcance = altura;
179 this.anchoHaz = anchoHaz;
180 this.m = m;
181 this.n = n;
182 double PI = Math.PI;
183 double deltaPhi = 360d/(this.n-1);
184 double tetha = this.anchoHaz/2.0;
185 double rmax = altura/Math.cos(tetha*PI/180.0);
186 double deltaRho = rmax/(this.m-1);
187 double posX,posY,posZ;
188 int formato = TriangleStripArray.COORDINATES | TriangleStripArr
189 Point3d punto = new Point3d();
190
191 int[] verticeporTiras = new int[this.n];
192 for (int s = 0;s < this.n ;s++ )
193 {
194 verticeporTiras[s] = 2*this.m;
195 }
196 TriangleStripArray geoPat1 =
197 new TriangleStripArray(2*this.m*this.n,formato,verticepo
198 for (int i = 0; i < n-1 ;i++ )
199 for (int j = 0; j< m-1;j++ )
200 for(int k = 0; k<2;k++)
201 {
202 posX = j*deltaRho*Math.sin(tetha*PI/180.0)*Math.cos((i+k)*d
203 posY = j*deltaRho*Math.sin(tetha*PI/180.0)*Math.sin((i+k)*d
204 posZ = j*deltaRho*Math.cos(tetha*PI/180.0);
Page 4 of 5
Conoide.java 31/01/2009 09:28 p.m.
Page 5 of 5
Cono Luminoso
ConoLuminoso.java 31/01/2009 09:28 p.m.
1 import javax.media.j3d.*;
2 import javax.vecmath.*;
3
4 public class ConoLuminoso extends BranchGroup
5 {
6 TransformGroup rotacion,desplazarY;
7 Transform3D rot, utility,utility2,utility3,utility4,utility5,utilit
8 double giroX,giroY,giroZ;
9 TransparencyAttributes transparencia;
10
11 public ConoLuminoso(float angulo,float altura, float valorTranspare
12 {
13 utility = new Transform3D();
14 utility2 = new Transform3D();
15 utility3 = new Transform3D();
16 utility4 = new Transform3D();
17 utility5 = new Transform3D();
18 utility6 = new Transform3D();
19 giroX = 0.0;
20 giroY = 0.0;
21 giroZ = 0.0;
22 rotacion = new TransformGroup();
23 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
24 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
25 Transform3D rotar90 = new Transform3D();
26 rotar90.rotX(270.0*Math.PI/180.0d);
27 rot = new Transform3D();
28
29 TransformGroup rotX = new TransformGroup();
30 rotX.setTransform(rotar90);
31 Transform3D desplazamientoY = new Transform3D();
32 desplazamientoY.setTranslation(new Vector3f(0.0f,-altura/2.0f,0
33 desplazarY = new TransformGroup();
34 desplazarY.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
35 desplazarY.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
36 desplazarY.setTransform(desplazamientoY);
37
38
39 Appearance apariencia = new Appearance();
40 ColoringAttributes amarillo = new ColoringAttributes
41 (new Color3f(1.0f,1.0f,0.0f),
42 ColoringAttributes.SHADE_GOURAUD)
43
44 transparencia =
45 new TransparencyAttributes(TransparencyAttributes.BLENDED,
46 valorTransparencia);
47 transparencia.setCapability(TransparencyAttributes.ALLOW_VA
48 transparencia.setCapability(TransparencyAttributes.ALLOW_VA
49 apariencia.setColoringAttributes(amarillo);
50 apariencia.setTransparencyAttributes(transparencia);
51 com.sun.j3d.utils.geometry.Cone cono =
Page 1 of 3
ConoLuminoso.java 31/01/2009 09:28 p.m.
Page 2 of 3
ConoLuminoso.java 31/01/2009 09:28 p.m.
Page 3 of 3
Patron1
Patron1.java 31/01/2009 10:07 p.m.
1 //package patrones;
2
3 import javax.media.j3d.*;
4 import javax.vecmath.Color3f;
5 import javax.vecmath.Point3d;
6 import javax.vecmath.Vector3f;
7
8 public class Patron1 extends BranchGroup
9 {
10 double diametro, rfd,x,y,z;
11 int n,m;
12 TransformGroup rotacion,traslacion,cambiarTamaño;
13 double refZ,refX,refY;
14 Transform3D rot, utility,utility2,utility3,utility4,utility5,utilit
15 TransparencyAttributes ta;
16
17 public Patron1(double A, double potPhi,double potTetha, int n , int
18 {
19 utility = new Transform3D();
20 utility2 = new Transform3D();
21 utility3 = new Transform3D();
22 utility4 = new Transform3D();
23 utility5 = new Transform3D();
24 utility6 = new Transform3D();
25 refX = 0.0;
26 refY = 0.0;
27 refZ = 0.0;
28 rot = new Transform3D();
29 this.x = 0.0;
30 this.y = 0.0;
31 this.z = 0.0;
32 this.diametro = diametro;
33 this.rfd = rfd;
34 this.m = m;
35 this.n = n;
36 int[] verticeporTiras = new int[n];
37 int formato = TriangleStripArray.COORDINATES | TriangleStripArr
38 Point3d punto = new Point3d();
39 double posX,posY,posZ;
40 double deltaPhi = 360/(this.n-1);
41 double deltaTetha = 180/(this.m-1);
42 Color3f azul = new Color3f(0.0f,0.0f,1.0f);
43 for (int s = 0;s < n ;s++ )
44 {
45 verticeporTiras[s] = 2*m;
46 }
47 TriangleStripArray geoPat = new TriangleStripArray(2*m*n,format
48
49 double PI = Math.PI;
50 double r,f1,f2;
51
Page 1 of 4
Patron1.java 31/01/2009 10:07 p.m.
Page 2 of 4
Patron1.java 31/01/2009 10:07 p.m.
103
104 public void girarZ(double giroZ)
105 {
106
107 /*Transform3D rotacionZ = new Transform3D();
108 rotacionZ.rotZ((giroZ-refZ)*Math.PI/180.0d);
109 rot.mul(rotacionZ);*/
110 utility2.rotZ((giroZ-refZ)*Math.PI/180.0d);
111 rot.mul(utility2);
112 this.rotacion.setTransform(rot);
113 refZ = giroZ;
114 }
115
116 public void girarY(double giroY)
117 {
118 /*Transform3D rotacionY = new Transform3D();
119 rotacionY.rotY((giroY-refY)*Math.PI/180.0d);*/
120 utility3.rotY((giroY-refY)*Math.PI/180.0d);
121 rot.mul(utility3);
122 this.rotacion.setTransform(rot);
123 refY = giroY;
124
125 }
126
127 public void traslacion(double x, double y, double z)
128 {
129
130 }
131 public void escalar(double tamaño)
132 {
133 /*Transform3D cambioTamaño = new Transform3D();
134 cambioTamaño.setScale(tamaño);*/
135 utility4.setScale(tamaño);
136 cambiarTamaño.setTransform(utility4);
137 }
138 public void moverXYZ(float x, float y, float z)
139 {
140 this.x = x;
141 this.y = y;
142 this.z = z;
143 /*Transform3D trasladar = new Transform3D();
144 trasladar.setTranslation(new Vector3f(x,y,z));*/
145 utility6.setTranslation(new Vector3f(x,y,z));
146 traslacion.setTransform(utility6);
147 }
148 public void moverX( float x)
149 {
150 this.x = x;
151 moverXYZ((float)this.x,(float)this.y,(float)this.z);
152 }
153
Page 3 of 4
Patron1.java 31/01/2009 10:07 p.m.
Page 4 of 4