use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class TestWalkingChar method createLight.
private void createLight() {
Vector3f direction = new Vector3f(-0.1f, -0.7f, -1).normalizeLocal();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(direction);
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class TestMousePick method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
shootables.collideWith(ray, results);
// }
if (results.size() > 0) {
CollisionResult closest = results.getClosestCollision();
mark.setLocalTranslation(closest.getContactPoint());
Quaternion q = new Quaternion();
q.lookAt(closest.getContactNormal(), Vector3f.UNIT_Y);
mark.setLocalRotation(q);
rootNode.attachChild(mark);
} else {
rootNode.detachChild(mark);
}
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
if (qName.equals("scene")) {
if (elementStack.size() != 0) {
throw new SAXException("dotScene parse error: 'scene' element must be the root XML element");
}
String version = attribs.getValue("formatVersion");
if (version == null || (!version.equals("1.0.0") && !version.equals("1.0.1"))) {
logger.log(Level.WARNING, "Unrecognized version number" + " in dotScene file: {0}", version);
}
} else if (qName.equals("nodes")) {
if (root != null) {
throw new SAXException("dotScene parse error: nodes element was specified twice");
}
if (sceneName == null) {
root = new com.jme3.scene.Node("OgreDotScene" + (++sceneIdx));
} else {
root = new com.jme3.scene.Node(sceneName + "-scene_node");
}
node = root;
} else if (qName.equals("externals")) {
checkTopNode("scene");
} else if (qName.equals("item")) {
checkTopNode("externals");
} else if (qName.equals("file")) {
checkTopNode("item");
// NOTE: This part of the file is ignored, it is parsed
// by SceneMaterialLoader in the first pass.
} else if (qName.equals("node")) {
String curElement = elementStack.peek();
if (!curElement.equals("node") && !curElement.equals("nodes")) {
throw new SAXException("dotScene parse error: " + "node element can only appear under 'node' or 'nodes'");
}
parseNode(attribs);
} else if (qName.equals("property")) {
if (node != null) {
String type = attribs.getValue("type");
String name = attribs.getValue("name");
String data = attribs.getValue("data");
if (type.equals("BOOL")) {
node.setUserData(name, Boolean.parseBoolean(data) || data.equals("1"));
} else if (type.equals("FLOAT")) {
node.setUserData(name, Float.parseFloat(data));
} else if (type.equals("STRING")) {
node.setUserData(name, data);
} else if (type.equals("INT")) {
node.setUserData(name, Integer.parseInt(data));
}
}
} else if (qName.equals("entity")) {
checkTopNode("node");
parseEntity(attribs);
} else if (qName.equals("camera")) {
checkTopNode("node");
parseCamera(attribs);
} else if (qName.equals("clipping")) {
checkTopNode("camera");
parseCameraClipping(attribs);
} else if (qName.equals("position")) {
if (elementStack.peek().equals("node")) {
node.setLocalTranslation(SAXUtil.parseVector3(attribs));
} else if (elementStack.peek().equals("camera")) {
cameraNode.setLocalTranslation(SAXUtil.parseVector3(attribs));
}
} else if (qName.equals("quaternion") || qName.equals("rotation")) {
node.setLocalRotation(parseQuat(attribs));
} else if (qName.equals("scale")) {
node.setLocalScale(SAXUtil.parseVector3(attribs));
} else if (qName.equals("light")) {
parseLight(attribs);
} else if (qName.equals("colourDiffuse") || qName.equals("colorDiffuse")) {
if (elementStack.peek().equals("light")) {
if (light != null) {
light.setColor(parseColor(attribs));
}
} else {
checkTopNode("environment");
}
} else if (qName.equals("colourAmbient") || qName.equals("colorAmbient")) {
if (elementStack.peek().equals("environment")) {
ColorRGBA color = parseColor(attribs);
if (!color.equals(ColorRGBA.Black) && !color.equals(ColorRGBA.BlackNoAlpha)) {
// Lets add an ambient light to the scene.
AmbientLight al = new AmbientLight();
al.setColor(color);
root.addLight(al);
}
}
} else if (qName.equals("normal") || qName.equals("direction")) {
checkTopNode("light");
parseLightNormal(attribs);
} else if (qName.equals("lightAttenuation")) {
parseLightAttenuation(attribs);
} else if (qName.equals("spotLightRange") || qName.equals("lightRange")) {
parseLightSpotLightRange(attribs);
}
elementStack.push(qName);
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class BulletVehicleDebugControl method createVehicle.
private void createVehicle() {
suspensionNode.detachAllChildren();
for (int i = 0; i < body.getNumWheels(); i++) {
VehicleWheel physicsVehicleWheel = body.getWheel(i);
Vector3f location = physicsVehicleWheel.getLocation().clone();
Vector3f direction = physicsVehicleWheel.getDirection().clone();
Vector3f axle = physicsVehicleWheel.getAxle().clone();
float restLength = physicsVehicleWheel.getRestLength();
float radius = physicsVehicleWheel.getRadius();
Arrow locArrow = new Arrow(location);
Arrow axleArrow = new Arrow(axle.normalizeLocal().multLocal(0.3f));
Arrow wheelArrow = new Arrow(direction.normalizeLocal().multLocal(radius));
Arrow dirArrow = new Arrow(direction.normalizeLocal().multLocal(restLength));
Geometry locGeom = new Geometry("WheelLocationDebugShape" + i, locArrow);
Geometry dirGeom = new Geometry("WheelDirectionDebugShape" + i, dirArrow);
Geometry axleGeom = new Geometry("WheelAxleDebugShape" + i, axleArrow);
Geometry wheelGeom = new Geometry("WheelRadiusDebugShape" + i, wheelArrow);
dirGeom.setLocalTranslation(location);
axleGeom.setLocalTranslation(location.add(direction));
wheelGeom.setLocalTranslation(location.add(direction));
locGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
dirGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
axleGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
wheelGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
suspensionNode.attachChild(locGeom);
suspensionNode.attachChild(dirGeom);
suspensionNode.attachChild(axleGeom);
suspensionNode.attachChild(wheelGeom);
}
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method getWorldIntersection.
private Vector3f getWorldIntersection() {
Vector3f origin = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.0f);
Vector3f direction = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
int numCollisions = terrain.collideWith(ray, results);
if (numCollisions > 0) {
CollisionResult hit = results.getClosestCollision();
return hit.getContactPoint();
}
return null;
}
Aggregations