use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class SpotLight method write.
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(direction, "direction", new Vector3f());
oc.write(position, "position", new Vector3f());
oc.write(spotInnerAngle, "spotInnerAngle", FastMath.QUARTER_PI / 8);
oc.write(spotOuterAngle, "spotOuterAngle", FastMath.QUARTER_PI / 6);
oc.write(spotRange, "spotRange", 100);
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class TestConeVSFrustum method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
TempVars vars = TempVars.get();
boolean intersect = spotLight.intersectsFrustum(frustumCam, vars);
if (intersect) {
geom.getMaterial().setColor("Diffuse", ColorRGBA.Green);
} else {
geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
}
Vector3f farPoint = vars.vect1.set(spotLight.getPosition()).addLocal(vars.vect2.set(spotLight.getDirection()).multLocal(spotLight.getSpotRange()));
//computing the radius of the base disc
float farRadius = (spotLight.getSpotRange() / FastMath.cos(spotLight.getSpotOuterAngle())) * FastMath.sin(spotLight.getSpotOuterAngle());
//computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector
Vector3f perpDirection = vars.vect2.set(spotLight.getDirection()).crossLocal(frustumCam.getWorldPlane(3).getNormal()).normalizeLocal().crossLocal(spotLight.getDirection());
//projecting the far point on the base disc perimeter
Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius));
vars.release();
// boxGeo.setLocalTranslation(spotLight.getPosition());
// boxGeo.setLocalTranslation(projectedPoint);
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class TestDepthOfField method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
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();
fpsText.setText("" + hit.getDistance());
dofFilter.setFocusDistance(hit.getDistance() / 10.0f);
}
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class TerrainQuad method createQuad.
/**
* Quadrants, world coordinates, and heightmap coordinates (Y-up):
*
* -z
* -u |
* -v 1|3
* -x ----+---- x
* 2|4 u
* | v
* z
* <code>createQuad</code> generates four new quads from this quad.
* The heightmap's top left (0,0) coordinate is at the bottom, -x,-z
* coordinate of the terrain, so it grows in the positive x.z direction.
*/
protected void createQuad(int blockSize, float[] heightMap) {
// create 4 terrain quads
int quarterSize = size >> 2;
int split = (size + 1) >> 1;
Vector2f tempOffset = new Vector2f();
offsetAmount += quarterSize;
//if (lodCalculator == null)
// lodCalculator = createDefaultLodCalculator(); // set a default one
// 1 upper left of heightmap, upper left quad
float[] heightBlock1 = createHeightSubBlock(heightMap, 0, 0, split);
Vector3f origin1 = new Vector3f(-quarterSize * stepScale.x, 0, -quarterSize * stepScale.z);
tempOffset.x = offset.x;
tempOffset.y = offset.y;
tempOffset.x += origin1.x;
tempOffset.y += origin1.z;
TerrainQuad quad1 = new TerrainQuad(getName() + "Quad1", blockSize, split, stepScale, heightBlock1, totalSize, tempOffset, offsetAmount);
quad1.setLocalTranslation(origin1);
quad1.quadrant = 1;
this.attachChild(quad1);
// 2 lower left of heightmap, lower left quad
float[] heightBlock2 = createHeightSubBlock(heightMap, 0, split - 1, split);
Vector3f origin2 = new Vector3f(-quarterSize * stepScale.x, 0, quarterSize * stepScale.z);
tempOffset = new Vector2f();
tempOffset.x = offset.x;
tempOffset.y = offset.y;
tempOffset.x += origin2.x;
tempOffset.y += origin2.z;
TerrainQuad quad2 = new TerrainQuad(getName() + "Quad2", blockSize, split, stepScale, heightBlock2, totalSize, tempOffset, offsetAmount);
quad2.setLocalTranslation(origin2);
quad2.quadrant = 2;
this.attachChild(quad2);
// 3 upper right of heightmap, upper right quad
float[] heightBlock3 = createHeightSubBlock(heightMap, split - 1, 0, split);
Vector3f origin3 = new Vector3f(quarterSize * stepScale.x, 0, -quarterSize * stepScale.z);
tempOffset = new Vector2f();
tempOffset.x = offset.x;
tempOffset.y = offset.y;
tempOffset.x += origin3.x;
tempOffset.y += origin3.z;
TerrainQuad quad3 = new TerrainQuad(getName() + "Quad3", blockSize, split, stepScale, heightBlock3, totalSize, tempOffset, offsetAmount);
quad3.setLocalTranslation(origin3);
quad3.quadrant = 3;
this.attachChild(quad3);
// 4 lower right of heightmap, lower right quad
float[] heightBlock4 = createHeightSubBlock(heightMap, split - 1, split - 1, split);
Vector3f origin4 = new Vector3f(quarterSize * stepScale.x, 0, quarterSize * stepScale.z);
tempOffset = new Vector2f();
tempOffset.x = offset.x;
tempOffset.y = offset.y;
tempOffset.x += origin4.x;
tempOffset.y += origin4.z;
TerrainQuad quad4 = new TerrainQuad(getName() + "Quad4", blockSize, split, stepScale, heightBlock4, totalSize, tempOffset, offsetAmount);
quad4.setLocalTranslation(origin4);
quad4.quadrant = 4;
this.attachChild(quad4);
}
use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.
the class BresenhamTerrainPicker method getTerrainIntersection.
public Vector3f getTerrainIntersection(Ray worldPick, CollisionResults results) {
worldPickRay.set(worldPick);
List<TerrainPickData> pickData = new ArrayList<TerrainPickData>();
root.findPick(worldPick.clone(), pickData);
Collections.sort(pickData);
if (pickData.isEmpty())
return null;
workRay.set(worldPick);
for (TerrainPickData pd : pickData) {
TerrainPatch patch = pd.targetPatch;
tracer.getGridSpacing().set(patch.getWorldScale());
tracer.setGridOrigin(patch.getWorldTranslation());
workRay.getOrigin().set(worldPick.getDirection()).multLocal(pd.cr.getDistance() - .1f).addLocal(worldPick.getOrigin());
tracer.startWalk(workRay);
final Vector3f intersection = new Vector3f();
final Vector2f loc = tracer.getGridLocation();
if (tracer.isRayPerpendicularToGrid()) {
Triangle hit = new Triangle();
checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit);
float distance = worldPickRay.origin.distance(intersection);
CollisionResult cr = new CollisionResult(intersection, distance);
cr.setGeometry(patch);
cr.setContactNormal(hit.getNormal());
results.addCollision(cr);
return intersection;
}
while (loc.x >= -1 && loc.x <= patch.getSize() && loc.y >= -1 && loc.y <= patch.getSize()) {
//System.out.print(loc.x+","+loc.y+" : ");
// check the triangles of main square for intersection.
Triangle hit = new Triangle();
if (checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit)) {
// we found an intersection, so return that!
float distance = worldPickRay.origin.distance(intersection);
CollisionResult cr = new CollisionResult(intersection, distance);
cr.setGeometry(patch);
results.addCollision(cr);
cr.setContactNormal(hit.getNormal());
return intersection;
}
// because of how we get our height coords, we will
// sometimes be off by a grid spot, so we check the next
// grid space up.
int dx = 0, dz = 0;
Direction d = tracer.getLastStepDirection();
switch(d) {
case PositiveX:
case NegativeX:
dx = 0;
dz = 1;
break;
case PositiveZ:
case NegativeZ:
dx = 1;
dz = 0;
break;
}
if (checkTriangles(loc.x + dx, loc.y + dz, workRay, intersection, patch, hit)) {
// we found an intersection, so return that!
float distance = worldPickRay.origin.distance(intersection);
CollisionResult cr = new CollisionResult(intersection, distance);
results.addCollision(cr);
cr.setGeometry(patch);
cr.setContactNormal(hit.getNormal());
return intersection;
}
tracer.next();
}
}
return null;
}
Aggregations