com.jme3.scene.shape.Line Java Examples

The following examples show how to use com.jme3.scene.shape.Line. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditorRenderer.java    From OpenRTS with MIT License 6 votes vote down vote up
private void drawHeightPencil() {
	List<Tile> tiles = ToolManager.getHeightTool().pencil.getNodes();
	int index = 0;
	for (Spatial s : HeightPencilNode.getChildren()) {
		if (index < tiles.size()) {
			Point3D start = tiles.get(index).getPos();
			Point3D end = tiles.get(index).getPos().getAddition(0, 0, 0.5);
			Line l = new Line(TranslateUtil.toVector3f(start), TranslateUtil.toVector3f(end));
			l.setLineWidth(PENCIL_THICKNESS);
			((Geometry) s).setMesh(l);
			s.setLocalTranslation(Vector3f.ZERO);
			// s.setLocalTranslation(Translator.toVector3f(tiles.get(index).getPos2D(), (float)toolManager.selector.getElevation()+0.1f));
		} else {
			s.setLocalTranslation(new Vector3f(-1000, -1000, 0));
		}
		index++;
	}
}
 
Example #2
Source File: SlopeTerrainToolControl.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
public SlopeTerrainToolControl(@NotNull TerrainPaintingComponent component) {
    super(component);

    this.baseMarker = new Geometry("BaseMarker", new Sphere(8, 8, 1));
    this.baseMarker.setMaterial(createColoredMaterial(ColorRGBA.Red));
    this.targetMarker = new Geometry("TargetMarker", new Sphere(8, 8, 1));
    this.targetMarker.setMaterial(createColoredMaterial(ColorRGBA.Blue));
    this.line = new Geometry("line", new Line(Vector3f.ZERO, Vector3f.ZERO));
    this.line.setMaterial(createColoredMaterial(ColorRGBA.White));
}
 
Example #3
Source File: SlopeTerrainToolControl.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
protected void controlUpdate(float tpf) {
    super.controlUpdate(tpf);

    var baseMarker = getBaseMarker();
    var targetMarker = getTargetMarker();
    var line = getLine();

    var firstPoint = baseMarker.getLocalTranslation();
    var secondPoint = targetMarker.getLocalTranslation();

    var mesh = (Line) line.getMesh();
    mesh.updatePoints(firstPoint, secondPoint);
}
 
Example #4
Source File: ArmatureNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateBoneMesh(Geometry geom, Vector3f start, Vector3f[] ends) {
    if (geom.getMesh() instanceof ArmatureInterJointsWire) {
        ((ArmatureInterJointsWire) geom.getMesh()).updatePoints(start, ends);
    } else if (geom.getMesh() instanceof Line) {
        ((Line) geom.getMesh()).updatePoints(start, ends[0]);
    }
    geom.updateModelBound();
}
 
Example #5
Source File: Axis.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Axis(AssetManager assetManager){
    super("axis");
    Line xAxis = new Line(Vector3f.ZERO, new Vector3f(1000.0f, 0.0f, 0.0f));
    Geometry xGeometry = new Geometry("xAxis", xAxis);
    Material xMat = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    xMat.setColor("Color", ColorRGBA.Blue);
    xGeometry.setMaterial(xMat);

    Line yAxis = new Line(Vector3f.ZERO, new Vector3f(.0f, 1000.0f, 0.0f));
    Geometry yGeometry = new Geometry("yAxis", yAxis);
    Material yMat = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    yMat.setColor("Color", ColorRGBA.Cyan);
    yGeometry.setMaterial(yMat);

    Line zAxis = new Line(Vector3f.ZERO, new Vector3f(.0f, .0f, 1000.0f));
    Geometry zGeometry = new Geometry("zAxis", zAxis);
    Material zMat = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    zMat.setColor("Color", ColorRGBA.Green);
    zGeometry.setMaterial(zMat);


    attachChild(xGeometry);
    attachChild(yGeometry);
    attachChild(zGeometry);

}
 
Example #6
Source File: EditorRenderer.java    From OpenRTS with MIT License 5 votes vote down vote up
private void BuildHeightPencil() {
	for (int i = 0; i < Pencil.MAX_SIZE * Pencil.MAX_SIZE; i++) {
		Geometry g = new Geometry();
		g.setMesh(new Line(new Vector3f(-1000, -1000, 0), new Vector3f(-1000, -1000, 1)));
		g.setMaterial(MaterialManager.getColor(ColorRGBA.Orange));
		HeightPencilNode.attachChild(g);
	}
}
 
Example #7
Source File: EditorRenderer.java    From OpenRTS with MIT License 5 votes vote down vote up
private void BuildAtlasPencil() {
	for (int i = 0; i < Pencil.MAX_SIZE * 8; i++) {
		Geometry g = new Geometry();
		g.setMesh(new Line(new Vector3f(-1000, -1000, 0), new Vector3f(-1000, -1000, 1)));
		g.setMaterial(MaterialManager.getColor(ColorRGBA.Orange));
		AtlasPencilNode.attachChild(g);
	}
}
 
Example #8
Source File: MapView.java    From OpenRTS with MIT License 5 votes vote down vote up
public void drawSelectionArea(Point2D c1, Point2D c2) {
	float minX = (float) Math.min(c1.x, c2.x);
	float maxX = (float) Math.max(c1.x, c2.x);

	float minY = (float) Math.min(c1.y, c2.y);
	float maxY = (float) Math.max(c1.y, c2.y);

	guiNode.detachAllChildren();

	Geometry g1 = new Geometry();
	g1.setMesh(new Line(new Vector3f(minX, minY, 0), new Vector3f(maxX, minY, 0)));
	g1.setMaterial(MaterialManager.getColor(ColorRGBA.White));
	guiNode.attachChild(g1);

	Geometry g2 = new Geometry();
	g2.setMesh(new Line(new Vector3f(minX, maxY, 0), new Vector3f(maxX, maxY, 0)));
	g2.setMaterial(MaterialManager.getColor(ColorRGBA.White));
	guiNode.attachChild(g2);

	Geometry g3 = new Geometry();
	g3.setMesh(new Line(new Vector3f(minX, minY, 0), new Vector3f(minX, maxY, 0)));
	g3.setMaterial(MaterialManager.getColor(ColorRGBA.White));
	guiNode.attachChild(g3);

	Geometry g4 = new Geometry();
	g4.setMesh(new Line(new Vector3f(maxX, minY, 0), new Vector3f(maxX, maxY, 0)));
	g4.setMaterial(MaterialManager.getColor(ColorRGBA.White));
	guiNode.attachChild(g4);
}
 
Example #9
Source File: PMDPhysicsWorld.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void updateJointPosition(SixDofJoint constraint, Line line) {
//        constraint.getCalculatedTransformA(t1);
//        constraint.getCalculatedTransformB(t2);
//        v1.set(t1.origin.x, t1.origin.y, t1.origin.z);
//        v2.set(t2.origin.x, t2.origin.y, t2.origin.z);
//        line.updatePoints(v1, v2);
//        line.setLineWidth(3f);
//        line.setPointSize(3f);
//        System.out.println("joint "+v1+" "+v2);
    }
 
Example #10
Source File: AbstractSceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@FromAnyThread
private @NotNull Node createGrid() {

    final Node gridNode = new Node("GridNode");

    final ColorRGBA gridColor = new ColorRGBA(0.4f, 0.4f, 0.4f, 0.5f);
    final ColorRGBA xColor = new ColorRGBA(1.0f, 0.1f, 0.1f, 0.5f);
    final ColorRGBA zColor = new ColorRGBA(0.1f, 1.0f, 0.1f, 0.5f);

    final Material gridMaterial = createColorMaterial(gridColor);
    gridMaterial.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);

    final Material xMaterial = createColorMaterial(xColor);
    xMaterial.getAdditionalRenderState().setLineWidth(5);

    final Material zMaterial = createColorMaterial(zColor);
    zMaterial.getAdditionalRenderState().setLineWidth(5);

    final int gridSize = getGridSize();

    final Geometry grid = new Geometry("grid", new Grid(gridSize, gridSize, 1.0f));
    grid.setMaterial(gridMaterial);
    grid.setQueueBucket(RenderQueue.Bucket.Transparent);
    grid.setShadowMode(RenderQueue.ShadowMode.Off);
    grid.setCullHint(Spatial.CullHint.Never);
    grid.setLocalTranslation(gridSize / 2 * -1, 0, gridSize / 2 * -1);

    final Quad quad = new Quad(gridSize, gridSize);
    final Geometry gridCollision = new Geometry("collision", quad);
    gridCollision.setMaterial(createColorMaterial(gridColor));
    gridCollision.setQueueBucket(RenderQueue.Bucket.Transparent);
    gridCollision.setShadowMode(RenderQueue.ShadowMode.Off);
    gridCollision.setCullHint(Spatial.CullHint.Always);
    gridCollision.setLocalTranslation(gridSize / 2 * -1, 0, gridSize / 2 * -1);
    gridCollision.setLocalRotation(new Quaternion().fromAngles(AngleUtils.degreeToRadians(90), 0, 0));

    gridNode.attachChild(grid);
    gridNode.attachChild(gridCollision);

    // Red line for X axis
    final Line xAxis = new Line(new Vector3f(-gridSize / 2, 0f, 0f), new Vector3f(gridSize / 2 - 1, 0f, 0f));

    final Geometry gxAxis = new Geometry("XAxis", xAxis);
    gxAxis.setModelBound(new BoundingBox());
    gxAxis.setShadowMode(RenderQueue.ShadowMode.Off);
    gxAxis.setCullHint(Spatial.CullHint.Never);
    gxAxis.setMaterial(xMaterial);

    gridNode.attachChild(gxAxis);

    // Blue line for Z axis
    final Line zAxis = new Line(new Vector3f(0f, 0f, -gridSize / 2), new Vector3f(0f, 0f, gridSize / 2 - 1));

    final Geometry gzAxis = new Geometry("ZAxis", zAxis);
    gzAxis.setModelBound(new BoundingBox());
    gzAxis.setShadowMode(RenderQueue.ShadowMode.Off);
    gzAxis.setCullHint(Spatial.CullHint.Never);
    gzAxis.setMaterial(zMaterial);

    gridNode.attachChild(gzAxis);

    return gridNode;
}
 
Example #11
Source File: EditorRenderer.java    From OpenRTS with MIT License 4 votes vote down vote up
private void drawAtlasPencil() {
	Pencil s = ToolManager.getActualTool().pencil;
	PointRing pr = new PointRing();
	Point2D center = ToolManager.getActualTool().pencil.getCoord();

	if (s.shape == Pencil.SHAPE.Square || s.shape == Pencil.SHAPE.Diamond) {
		for (double i = -s.size / 2; i < s.size / 2; i += QUAD_PENCIL_SAMPLE_LENGTH) {
			pr.add(center.getAddition(i, -s.size / 2));
		}
		for (double i = -s.size / 2; i < s.size / 2; i += QUAD_PENCIL_SAMPLE_LENGTH) {
			pr.add(center.getAddition(s.size / 2, i));
		}
		for (double i = s.size / 2; i > -s.size / 2; i -= QUAD_PENCIL_SAMPLE_LENGTH) {
			pr.add(center.getAddition(i, s.size / 2));
		}
		for (double i = s.size / 2; i > -s.size / 2; i -= QUAD_PENCIL_SAMPLE_LENGTH) {
			pr.add(center.getAddition(-s.size / 2, i));
		}
		if (s.shape == Pencil.SHAPE.Diamond) {
			PointRing newPR = new PointRing();
			for (Point2D p : pr) {
				newPR.add(p.getRotation(AngleUtil.RIGHT / 2, center));
			}
			pr = newPR;
		}
	} else {
		Point2D revol = center.getAddition(s.size / 2, 0);
		for (int i = 0; i < CIRCLE_PENCIL_SAMPLE_COUNT; i++) {
			pr.add(revol.getRotation(AngleUtil.FLAT * 2 * i / CIRCLE_PENCIL_SAMPLE_COUNT, center));
		}
	}

	int index = 0;
	for (Spatial spatial : AtlasPencilNode.getChildren()) {
		if (index < pr.size() && ModelManager.getBattlefield().getMap().isInBounds(pr.get(index))
				&& ModelManager.getBattlefield().getMap().isInBounds(pr.getNext(index))) {
			Point3D start = pr.get(index).get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(pr.get(index)) + 0.1);
			Point3D end = pr.getNext(index).get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(pr.getNext(index)) + 0.1);
			Line l = new Line(TranslateUtil.toVector3f(start), TranslateUtil.toVector3f(end));
			l.setLineWidth(PENCIL_THICKNESS);
			((Geometry) spatial).setMesh(l);
			spatial.setLocalTranslation(Vector3f.ZERO);
		} else {
			spatial.setLocalTranslation(new Vector3f(-1000, -1000, 0));
		}
		index++;
	}
}
 
Example #12
Source File: CollisionTester.java    From OpenRTS with MIT License 4 votes vote down vote up
public static boolean areColliding(Asset asset1, Asset asset2, boolean debug){
		Spatial s1 = getSpatialFromAsset(asset1); 
		Spatial s2 = getSpatialFromAsset(asset2);

		PhysicsSpace space = new PhysicsSpace();
		
		RigidBodyControl ghost1 = new RigidBodyControl(getCollisionShape(asset1));
		s1.addControl(ghost1);
		space.add(ghost1);

		RigidBodyControl ghost2 = new RigidBodyControl(getCollisionShape(asset2));
		s2.addControl(ghost2);
//		ghost2.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
//		space.add(ghost2);

		space.update(1);
		
//		int numCollision = ghost1.getOverlappingCount();
//		boolean collision = numCollision > 0;
		Transform t = new Transform();
		t.setRotation(s2.getLocalRotation());
		t.setTranslation(s2.getLocalTranslation());
		boolean collision = false;
		for(ChildCollisionShape hull : getCollisionShape(asset2).getChildren())
			if(!space.sweepTest(hull.shape, Transform.IDENTITY, t).isEmpty()){
				collision = true;
				break;
			}
				
		
		space.remove(ghost1);
//		space.remove(ghost2);

//		if(!collision){
//			Spatial debugS2 = DebugShapeFactory.getDebugShape(ghost2.getCollisionShape());
//			debugS2.setLocalRotation(ghost2.getPhysicsRotation());
////			Spatial debugS2 = s2;
//			Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
//			m.getAdditionalRenderState().setWireframe(true);
//			m.setColor("Color", ColorRGBA.Red);
//			debugS2.setMaterial(m);
//			debugS2.setLocalTranslation(ghost2.getPhysicsLocation());
//			asset2.s = debugS2;
//			//EventManager.post(new GenericEvent(debugS2));
//		}
			
		if(!collision){// && debug){
			Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
			m.getAdditionalRenderState().setWireframe(true);
			m.setColor("Color", ColorRGBA.Red);
			Spatial debugS2 = DebugShapeFactory.getDebugShape(getCollisionShape(asset2));
			debugS2.setLocalTransform(t);
//			debugS2.setLocalRotation(ghost2.getPhysicsRotation());
//			debugS2.setLocalTranslation(ghost2.getPhysicsLocation());
			debugS2.setMaterial(m);

			Material m2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
			m2.getAdditionalRenderState().setWireframe(true);
			m2.setColor("Color", ColorRGBA.Blue);
			Geometry linegeom = new Geometry();
			Line l = new Line(debugS2.getLocalTranslation().add(0,  0, 1), ghost1.getPhysicsLocation().add(0,  0, 1));
			linegeom.setMesh(l);
			linegeom.setMaterial(m2);
	
			asset2.s = debugS2;
			if(l.getStart().distance(l.getEnd())<2)
				asset2.links.add(linegeom);
//			EventManager.post(new GenericEvent(debugS2));
//			EventManager.post(new GenericEvent(linegeom));
			
			
		}

		return collision; 
	}