use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.
the class Tree method init.
@Override
protected void init() {
super.init();
switch(treeType) {
case COTTONWOOD:
treeWidth = 80;
treeHeight = 100;
break;
case LINDEN:
treeWidth = 90;
treeHeight = 120;
break;
case OAK:
treeWidth = 70;
treeHeight = 80;
break;
case ELM:
treeWidth = 60;
treeHeight = 75;
break;
case MAPLE:
treeWidth = 30;
treeHeight = 60;
break;
case PINE:
treeWidth = 30;
treeHeight = 80;
break;
default:
treeWidth = 30;
treeHeight = 40;
}
mesh = new Quad("Tree Quad", treeWidth, treeHeight);
mesh.setModelBound(new BoundingBox());
mesh.updateModelBound();
mesh.setRotation(new Matrix3().fromAngles(Math.PI / 2, 0, 0));
mesh.setTranslation(0, 0, treeHeight / 2.0);
mesh.getSceneHints().setPickingHint(PickingHint.Pickable, false);
final BlendState bs = new BlendState();
bs.setEnabled(true);
bs.setBlendEnabled(false);
bs.setTestEnabled(true);
bs.setTestFunction(TestFunction.GreaterThan);
bs.setReference(0.7f);
mesh.setRenderState(bs);
mesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
billboard = new BillboardNode("Billboard");
billboard.setAlignment(BillboardAlignment.AxialZ);
billboard.attachChild(mesh);
root.attachChild(billboard);
switch(treeType) {
case PINE:
// axis samples, radial samples, radius, height, closed
crown = new Cone("Tree Crown", 2, 6, 18, 20, false);
break;
default:
// z samples, radial samples, radius
crown = new Sphere("Tree Crown", 4, 8, 14);
}
crown.setModelBound(new BoundingSphere());
crown.updateModelBound();
final Cylinder trunk = new Cylinder("Tree Trunk", 10, 10, 1, 20);
trunk.setModelBound(new BoundingBox());
trunk.updateModelBound();
switch(treeType) {
case COTTONWOOD:
crown.setScale(3, 3, 3.5);
crown.setTranslation(0, 0, 55);
trunk.setScale(8, 8, 2);
trunk.setTranslation(0, 0, 20);
break;
case LINDEN:
crown.setScale(3.5, 3.5, 4);
crown.setTranslation(0, 0, 65);
trunk.setScale(5, 5, 2);
trunk.setTranslation(0, 0, 20);
break;
case OAK:
crown.setScale(2.5, 2.5, 3);
crown.setTranslation(0, 0, 45);
trunk.setScale(5, 5, 2);
trunk.setTranslation(0, 0, 20);
break;
case ELM:
crown.setScale(2, 2, 2.5);
crown.setTranslation(0, 0, 40);
trunk.setScale(2, 2, 2);
trunk.setTranslation(0, 0, 20);
break;
case MAPLE:
crown.setScale(1, 1, 2.1);
crown.setTranslation(0, 0, 32);
trunk.setTranslation(0, 0, 10);
break;
case PINE:
crown.setScale(1, 1, -4.0);
crown.setTranslation(0, 0, 45);
trunk.setTranslation(0, 0, 10);
break;
default:
crown.setScale(1, 1, 1.2);
crown.setTranslation(0, 0, 24);
trunk.setTranslation(0, 0, 10);
break;
}
collisionRoot = new Node("Tree Collision Root");
collisionRoot.attachChild(crown);
collisionRoot.attachChild(trunk);
if (points.size() > 0) {
collisionRoot.setTranslation(getAbsPoint(0));
}
collisionRoot.updateWorldTransform(true);
collisionRoot.updateWorldBound(true);
collisionRoot.getSceneHints().setCullHint(showPolygons ? CullHint.Never : CullHint.Always);
root.attachChild(collisionRoot);
crown.setUserData(new UserData(this));
trunk.setUserData(new UserData(this));
updateTextureAndColor();
}
use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.
the class SceneManager method createSky.
private Mesh createSky() {
final Dome sky = new Dome("Sky", 100, 100, SKY_RADIUS);
sky.setRotation(new Matrix3().fromAngles(Math.PI / 2, 0, 0));
sky.getSceneHints().setLightCombineMode(LightCombineMode.Off);
sky.getSceneHints().setAllPickingHints(false);
sky.updateModelBound();
sky.updateWorldBound(true);
final TextureState ts = new TextureState();
ts.setTexture(TextureManager.load("daysky.jpg", Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessNoCompressedFormat, true));
sky.setRenderState(ts);
return sky;
}
use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.
the class SceneManager method createEarth.
private Node createEarth() throws IOException {
final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "earth.dae");
final ColladaImporter colladaImporter = new ColladaImporter();
final ColladaStorage storage = colladaImporter.load(source);
final Node earth = storage.getScene();
final DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3(0, 0, -1));
light.setEnabled(true);
final LightState lightState = new LightState();
lightState.attach(light);
earth.setRenderState(lightState);
earth.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
earth.updateWorldRenderStates(true);
final Node node = new Node();
node.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
node.attachChild(earth);
earth.addController(new SpatialController<Spatial>() {
@Override
public void update(final double time, final Spatial caller) {
final Vector3 direction = getCamera().getDirection().normalize(null);
direction.setZ(0);
direction.normalizeLocal();
double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
if (direction.dot(Vector3.UNIT_X) > 0) {
angle = -angle;
}
angle -= MathUtils.HALF_PI;
earth.setRotation(new Matrix3().fromAngles(0, 0, angle));
}
});
return node;
}
use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.
the class SceneManager method update.
@Override
public void update(final ReadOnlyTimer timer) {
final double tpf = timer.getTimePerFrame();
passManager.updatePasses(tpf);
taskManager.getQueue(GameTaskQueue.UPDATE).setExecuteMultiple(executeAllTask);
taskManager.getQueue(GameTaskQueue.UPDATE).execute(canvas.getCanvasRenderer().getRenderer());
if (operationFlag) {
executeOperation();
}
if (mouseState != null) {
mouseMoved();
}
if (Scene.isRedrawAll()) {
Scene.getInstance().redrawAllNow();
}
if (rotAnim && viewMode == ViewMode.NORMAL && canvas.getCanvasRenderer() != null) {
final Matrix3 rotate = new Matrix3();
rotate.fromAngleNormalAxis(45 * tpf * MathUtils.DEG_TO_RAD, Vector3.UNIT_Z);
final Camera camera = getCamera();
camera.setLocation(rotate.applyPre(camera.getLocation(), null));
camera.lookAt(0, 0, 1, Vector3.UNIT_Z);
getCameraNode().updateFromCamera();
Scene.getInstance().updateEditShapes();
}
final Heliodon heliodon = Heliodon.getInstance();
if (heliodon != null) {
if (sunAnim) {
heliodon.setHourAngle(heliodon.getHourAngle() + tpf * 0.5, true, true, false);
SceneManager.getInstance().changeSkyTexture();
SceneManager.getInstance().setShading(heliodon.isNightTime());
final boolean night = Heliodon.getInstance().isNightTime();
for (final HousePart part : Scene.getInstance().getParts()) {
if (part instanceof Mirror) {
final Mirror m = (Mirror) part;
if (night) {
// call this so that the light beams can be set invisible
m.drawSunBeam();
} else {
if (m.getReceiver() != null) {
m.draw();
}
}
} else if (part instanceof ParabolicTrough) {
final ParabolicTrough t = (ParabolicTrough) part;
if (night) {
// call this so that the light beams can be set invisible
t.drawSunBeam();
} else {
t.draw();
}
} else if (part instanceof ParabolicDish) {
final ParabolicDish d = (ParabolicDish) part;
if (night) {
// call this so that the light beams can be set invisible
d.drawSunBeam();
} else {
d.draw();
}
} else if (part instanceof FresnelReflector) {
final FresnelReflector f = (FresnelReflector) part;
if (night) {
// call this so that the light beams can be set invisible
f.drawSunBeam();
} else {
f.draw();
}
} else if (part instanceof SolarPanel) {
final SolarPanel sp = (SolarPanel) part;
if (!night && sp.getTracker() != Trackable.NO_TRACKER) {
sp.draw();
}
if (sp.isSunBeamVisible()) {
sp.drawSunBeam();
}
} else if (part instanceof Rack) {
final Rack rack = (Rack) part;
if (!night && rack.getTracker() != Trackable.NO_TRACKER) {
rack.draw();
}
if (rack.isSunBeamVisible()) {
rack.drawSunBeam();
}
}
}
}
heliodon.update();
}
if (cameraControl != null && cameraControl.isAnimating()) {
cameraControl.animate();
}
root.updateGeometricState(tpf);
}
use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.
the class Window method drawAnnotations.
@Override
public void drawAnnotations() {
if (points.size() < 4) {
return;
}
int annotCounter = 0;
Vector3 p0 = getAbsPoint(0);
Vector3 p1 = getAbsPoint(1);
Vector3 p2 = getAbsPoint(2);
Vector3 p3 = getAbsPoint(3);
final int vIndex = getNormal().equals(Vector3.UNIT_Z) ? 1 : 2;
if (!Util.isEqual(p0.getValue(vIndex), p2.getValue(vIndex))) {
final Vector3 tmp = p0;
p0 = p2;
p2 = p3;
p3 = p1;
p1 = tmp;
}
if (p0.getValue(vIndex) > p1.getValue(vIndex)) {
swap(p0, p1);
swap(p2, p3);
}
final Vector3 p01 = p1.subtract(p0, null).normalizeLocal();
if (p2.subtract(p0, null).normalizeLocal().dot(p01.cross(getNormal(), null)) < 0) {
swap(p0, p2);
swap(p1, p3);
}
final Vector3 cornerXY = p0.subtract(container.getAbsPoint(0), null);
cornerXY.setZ(0);
final ReadOnlyVector3 faceDirection = getNormal();
if (container instanceof Wall) {
final ReadOnlyVector3 v02 = container.getAbsPoint(2).subtract(container.getAbsPoint(0), null);
final boolean reversedFace = v02.normalize(null).crossLocal(container.getNormal()).dot(Vector3.NEG_UNIT_Z) < 0.0;
double xy = cornerXY.length();
if (reversedFace) {
xy = v02.length() - xy;
}
label1.setText("(" + Math.round(Scene.getInstance().getAnnotationScale() * 10 * xy) / 10.0 + ", " + Math.round(Scene.getInstance().getAnnotationScale() * 10.0 * (p0.getZ() - container.getAbsPoint(0).getZ())) / 10.0 + ")");
label1.setTranslation(p0);
label1.setRotation(new Matrix3().fromAngles(0, 0, -Util.angleBetween(v02.normalize(null).multiplyLocal(reversedFace ? -1 : 1), Vector3.UNIT_X, Vector3.UNIT_Z)));
}
final ReadOnlyVector3 center = getCenter();
final float lineWidth = original == null ? 1f : 2f;
SizeAnnotation annot = fetchSizeAnnot(annotCounter++);
annot.setRange(p0, p1, center, faceDirection, false, Align.Center, true, true, false);
annot.setLineWidth(lineWidth);
annot = fetchSizeAnnot(annotCounter++);
annot.setRange(p0, p2, center, faceDirection, false, Align.Center, true, false, false);
annot.setLineWidth(lineWidth);
}
Aggregations