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
|
package tesseract.objects;
import java.awt.Color;
import javax.media.j3d.*;
import javax.vecmath.*;
import common.CollidableObject;
/**
* Sphere.
* @author ?
*
*/
public class Sphere extends PhysicalObject {
/**
*
*/
private static final long serialVersionUID = -8407634448268590714L;
/**
* Default Object color.
*/
private static final Color3f DEFAULT_COLOR = new Color3f(0.7f, 0.7f, 1);
/**
* Default divisions.
*/
private static final int DEFAULT_DIVISIONS = 22;
/**
* User definable color.
*/
private final Color3f myColor;
/**
* radius of sphere.
*/
public float radius;
/**
* Constructor.
* @param theRadius of sphere.
* @param position to start.
*/
public Sphere(final float theRadius, final Vector3f position) {
this(1, theRadius, position, DEFAULT_COLOR.get());
}
/**
* constructor.
* @param mass of object.
* @param theRadius of sphere.
* @param position of sphere.
* @param theColor of sphere.
*/
public Sphere(final float mass, final float theRadius,
final Vector3f position, final Color theColor) {
super(position, mass);
myColor = new Color3f(theColor);
setShape(createShape(DEFAULT_DIVISIONS));
radius = theRadius;
if (inverseMass != 0) {
inverseInertiaTensor.m00 = 2f / 5 / inverseMass
* radius * radius;
inverseInertiaTensor.m11 = inverseInertiaTensor.m00;
inverseInertiaTensor.m22 = inverseInertiaTensor.m00;
inverseInertiaTensor.invert();
}
updateTransformGroup();
}
/**
* createShape.
* @param divisions
* @return node
*/
protected Node createShape(final int divisions) {
Appearance appearance = new Appearance();
Material material = new Material();
material.setDiffuseColor(myColor);
appearance.setMaterial(material);
return new com.sun.j3d.utils.geometry.Sphere(radius,
com.sun.j3d.utils.geometry.Sphere.GENERATE_NORMALS,
divisions, appearance);
}
}
|