diff --git a/msi.gama.core/src/msi/gama/metamodel/agent/MinimalAgent.java b/msi.gama.core/src/msi/gama/metamodel/agent/MinimalAgent.java index 9927fa849c..15b953e840 100644 --- a/msi.gama.core/src/msi/gama/metamodel/agent/MinimalAgent.java +++ b/msi.gama.core/src/msi/gama/metamodel/agent/MinimalAgent.java @@ -110,7 +110,7 @@ protected MinimalAgent(final IPopulation population, final int } else { // If the agent is different, we do not copy the attributes present in the shape passed as argument (see // Issue #2053). - newLocalGeom = new GamaShape((Geometry) newGeometry.getInnerGeometry().clone()); + newLocalGeom = new GamaShape(newGeometry.getInnerGeometry().copy()); newLocalGeom.copyShapeAttributesFrom(newGeometry); } topology.normalizeLocation(newGeomLocation, false); diff --git a/msi.gama.core/src/msi/gama/metamodel/shape/GamaProxyGeometry.java b/msi.gama.core/src/msi/gama/metamodel/shape/GamaProxyGeometry.java index 49f0fb6da6..015d814332 100644 --- a/msi.gama.core/src/msi/gama/metamodel/shape/GamaProxyGeometry.java +++ b/msi.gama.core/src/msi/gama/metamodel/shape/GamaProxyGeometry.java @@ -1,12 +1,12 @@ /******************************************************************************************************* * - * GamaProxyGeometry.java, in msi.gama.core, is part of the source code of the - * GAMA modeling and simulation platform (v.1.8.2). + * GamaProxyGeometry.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform + * (v.1.8.2). * * (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. - * + * ********************************************************************************************************/ package msi.gama.metamodel.shape; @@ -70,16 +70,15 @@ public abstract class GamaProxyGeometry implements IShape, Cloneable { /** * Instantiates a new gama proxy geometry. * - * @param loc the loc + * @param loc + * the loc */ public GamaProxyGeometry(final GamaPoint loc) { setLocation(loc); } @Override - public IType getGamlType() { - return Types.GEOMETRY; - } + public IType getGamlType() { return Types.GEOMETRY; } @Override public void forEachAttribute(final BiConsumerWithPruning visitor) { @@ -104,9 +103,7 @@ public GamaPoint setLocation(final GamaPoint loc) { * @see msi.gama.common.interfaces.ILocated#getLocation() */ @Override - public GamaPoint getLocation() { - return absoluteLocation; - } + public GamaPoint getLocation() { return absoluteLocation; } /** * Method stringValue() @@ -251,14 +248,10 @@ public void setGeometry(final IShape g) { * @see msi.gama.metamodel.shape.IShape#isPoint() */ @Override - public boolean isPoint() { - return getReferenceGeometry().isPoint(); - } + public boolean isPoint() { return getReferenceGeometry().isPoint(); } @Override - public boolean isLine() { - return getReferenceGeometry().isLine(); - } + public boolean isLine() { return getReferenceGeometry().isLine(); } /** * Method getInnerGeometry() @@ -267,7 +260,7 @@ public boolean isLine() { */ @Override public Geometry getInnerGeometry() { - final Geometry copy = (Geometry) getReferenceGeometry().getInnerGeometry().clone(); + final Geometry copy = getReferenceGeometry().getInnerGeometry().copy(); translate(copy, getReferenceGeometry().getLocation(), getLocation()); return copy; } @@ -346,13 +339,12 @@ public double euclidianDistanceTo(final GamaPoint g) { public boolean intersects(final IShape g) { return getInnerGeometry().intersects(g.getInnerGeometry()); } - + @Override public boolean touches(final IShape g) { return getInnerGeometry().touches(g.getInnerGeometry()); } - - + @Override public boolean partiallyOverlaps(final IShape g) { return getInnerGeometry().overlaps(g.getInnerGeometry()); @@ -364,9 +356,7 @@ public boolean partiallyOverlaps(final IShape g) { * @see msi.gama.metamodel.shape.IShape#getPerimeter() */ @Override - public double getPerimeter() { - return getReferenceGeometry().getPerimeter(); - } + public double getPerimeter() { return getReferenceGeometry().getPerimeter(); } /** * Method setInnerGeometry() @@ -388,9 +378,7 @@ public void dispose() { } @Override - public Type getGeometricalType() { - return getReferenceGeometry().getGeometricalType(); - } + public Type getGeometricalType() { return getReferenceGeometry().getGeometricalType(); } /** * Method getPoints() @@ -401,9 +389,7 @@ public Type getGeometricalType() { public IList getPoints() { final IList result = GamaListFactory.create(Types.POINT); final Coordinate[] points = getInnerGeometry().getCoordinates(); - for (final Coordinate c : points) { - result.add(new GamaPoint(c)); - } + for (final Coordinate c : points) { result.add(new GamaPoint(c)); } return result; } @@ -423,9 +409,7 @@ public void setDepth(final double depth) { * @see msi.gama.metamodel.shape.IShape#getArea() */ @Override - public Double getArea() { - return getReferenceGeometry().getArea(); - } + public Double getArea() { return getReferenceGeometry().getArea(); } /** * Method getVolume() @@ -433,9 +417,7 @@ public Double getArea() { * @see msi.gama.metamodel.shape.IShape#getVolume() */ @Override - public Double getVolume() { - return getReferenceGeometry().getVolume(); - } + public Double getVolume() { return getReferenceGeometry().getVolume(); } /** * Method getHoles() @@ -446,8 +428,7 @@ public Double getVolume() { public IList getHoles() { final IList holes = GamaListFactory.create(Types.GEOMETRY); final Geometry g = getInnerGeometry(); - if (g instanceof Polygon) { - final Polygon p = (Polygon) g; + if (g instanceof Polygon p) { final int n = p.getNumInteriorRing(); for (int i = 0; i < n; i++) { holes.add(new GamaShape( @@ -463,9 +444,7 @@ public IList getHoles() { * @see msi.gama.metamodel.shape.IShape#getCentroid() */ @Override - public GamaPoint getCentroid() { - return absoluteLocation; - } + public GamaPoint getCentroid() { return absoluteLocation; } /** * Method getExteriorRing() @@ -483,9 +462,7 @@ public GamaShape getExteriorRing(final IScope scope) { * @see msi.gama.metamodel.shape.IShape#getWidth() */ @Override - public Double getWidth() { - return getReferenceGeometry().getWidth(); - } + public Double getWidth() { return getReferenceGeometry().getWidth(); } /** * Method getHeight() @@ -493,9 +470,7 @@ public Double getWidth() { * @see msi.gama.metamodel.shape.IShape#getHeight() */ @Override - public Double getHeight() { - return getReferenceGeometry().getHeight(); - } + public Double getHeight() { return getReferenceGeometry().getHeight(); } /** * Method getDepth() @@ -503,9 +478,7 @@ public Double getHeight() { * @see msi.gama.metamodel.shape.IShape#getDepth() */ @Override - public Double getDepth() { - return getReferenceGeometry().getDepth(); - } + public Double getDepth() { return getReferenceGeometry().getDepth(); } /** * Method getGeometricEnvelope() @@ -513,8 +486,6 @@ public Double getDepth() { * @see msi.gama.metamodel.shape.IShape#getGeometricEnvelope() */ @Override - public GamaShape getGeometricEnvelope() { - return new GamaShape(getEnvelope().toGeometry()); - } + public GamaShape getGeometricEnvelope() { return new GamaShape(getEnvelope().toGeometry()); } } diff --git a/msi.gama.core/src/msi/gama/metamodel/shape/GamaShape.java b/msi.gama.core/src/msi/gama/metamodel/shape/GamaShape.java index 9e47fabf39..c093692cb6 100644 --- a/msi.gama.core/src/msi/gama/metamodel/shape/GamaShape.java +++ b/msi.gama.core/src/msi/gama/metamodel/shape/GamaShape.java @@ -1,12 +1,11 @@ /******************************************************************************************************* * - * GamaShape.java, in msi.gama.core, is part of the source code of the - * GAMA modeling and simulation platform (v.1.8.2). + * GamaShape.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.1.8.2). * * (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. - * + * ********************************************************************************************************/ package msi.gama.metamodel.shape; @@ -58,27 +57,28 @@ public class GamaShape implements IShape { * The Class ShapeData. */ private static class ShapeData { - + /** The depth. */ private Double depth; - + /** The type. */ private Type type; } /** The geometry. */ protected Geometry geometry; - + /** The agent. */ private IAgent agent; - + /** The attributes. */ protected IMap attributes; /** * Instantiates a new gama shape. * - * @param geom the geom + * @param geom + * the geom */ public GamaShape(final Geometry geom) { setInnerGeometry(geom); @@ -90,7 +90,8 @@ public GamaShape(final Geometry geom) { /** * Instantiates a new gama shape. * - * @param env the env + * @param env + * the env */ public GamaShape(final Envelope3D env) { this(env == null ? null : env.toGeometry()); @@ -99,7 +100,8 @@ public GamaShape(final Envelope3D env) { /** * Instantiates a new gama shape. * - * @param geom the geom + * @param geom + * the geom */ public GamaShape(final IShape geom) { this(geom, null); @@ -116,7 +118,7 @@ public GamaShape(final IShape geom) { */ public GamaShape(final IShape source, final Geometry geom) { - this((Geometry) (geom == null ? source.getInnerGeometry().clone() : geom)); + this(geom == null ? source.getInnerGeometry().copy() : geom); mixAttributes(source); } @@ -130,8 +132,7 @@ private void mixAttributes(final IShape source) { if (source == null) return; // final GamaMap attr = (GamaMap) source.getAttributes(); copyShapeAttributesFrom(source); - if (source instanceof GamaShape) { - final GamaShape shape = (GamaShape) source; + if (source instanceof GamaShape shape) { if (shape.attributes != null) { getOrCreateAttributes(); shape.attributes.forEach((key, val) -> { if (val != source) { attributes.put(key, val); } }); @@ -152,8 +153,7 @@ private void mixAttributes(final IShape source) { @Override public void copyAttributesOf(final IAttributed source) { - if (source instanceof GamaShape) { - final GamaShape shape = (GamaShape) source; + if (source instanceof GamaShape shape) { if (shape.attributes != null) { getOrCreateAttributes(); attributes.putAll(shape.attributes); @@ -329,8 +329,10 @@ public GamaPoint setLocation(final GamaPoint l) { /** * Translated to. * - * @param scope the scope - * @param target the target + * @param scope + * the scope + * @param target + * the target * @return the gama shape */ public GamaShape translatedTo(final IScope scope, final GamaPoint target) { @@ -417,8 +419,7 @@ public GamaShape getExteriorRing(final IScope scope) { result = ((Polygon) result).getExteriorRing(); } else - if (result instanceof MultiPolygon) { - final MultiPolygon mp = (MultiPolygon) result; + if (result instanceof MultiPolygon mp) { final LineString lines[] = new LineString[mp.getNumGeometries()]; for (int i = 0; i < mp.getNumGeometries(); i++) { lines[i] = ((Polygon) mp.getGeometryN(i)).getExteriorRing(); @@ -432,7 +433,8 @@ public GamaShape getExteriorRing(final IScope scope) { /** * Gets the data. * - * @param createIt the create it + * @param createIt + * the create it * @return the data */ private ShapeData getData(final boolean createIt) { @@ -556,8 +558,7 @@ public int hashCode() { @Override public GamaShape copy(final IScope scope) { - final Geometry gg = (Geometry) geometry.clone(); - return new GamaShape(this, gg); + return new GamaShape(this, geometry.copy()); } /** diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/OpenGL.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/OpenGL.java index a821b108ae..5a45bf6376 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/OpenGL.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/OpenGL.java @@ -168,7 +168,10 @@ public class OpenGL extends AbstractRendererHelper implements ITesselator { private double currentObjectAlpha = 1d; /** The lighted. */ - private boolean lighted; + private boolean objectIsLighted; + + /** The display is lighted. */ + private boolean displayIsLighted; /** The in raster text mode. */ // Text @@ -548,15 +551,40 @@ public void resumeZTranslation() { * @param lighted * @return */ - public boolean setLighting(final boolean lighted) { - if (this.lighted == lighted) return lighted; - if (lighted) { + public boolean setObjectLighting(final boolean lighted) { + boolean previous = objectIsLighted; + if (lighted != previous) { + objectIsLighted = lighted; + updateLightMode(); + } + return previous; + } + + /** + * Sets the display lighting. + * + * @param lighted + * the lighted + * @return true, if successful + */ + public boolean setDisplayLighting(final boolean lighted) { + boolean previous = displayIsLighted; + if (lighted != previous) { + displayIsLighted = lighted; + updateLightMode(); + } + return previous; + } + + /** + * Update light mode. + */ + private void updateLightMode() { + if (getLighting()) { gl.glEnable(GLLightingFunc.GL_LIGHTING); } else { gl.glDisable(GLLightingFunc.GL_LIGHTING); } - this.lighted = lighted; - return !lighted; } /** @@ -564,7 +592,7 @@ public boolean setLighting(final boolean lighted) { * * @return the lighting */ - public boolean getLighting() { return lighted; } + public boolean getLighting() { return objectIsLighted && displayIsLighted; } /** * Matrix mode. @@ -855,9 +883,9 @@ public void drawClosedLine(final ICoordinates yNegatedVertices, final Color colo * the number */ public void drawLine(final ICoordinates yNegatedVertices, final int number) { - final boolean previous = this.setLighting(false); + // final boolean previous = this.setLighting(false); drawVertices(GL.GL_LINE_STRIP, yNegatedVertices, number, true); - this.setLighting(previous); + // this.setLighting(previous); } /** @@ -1245,10 +1273,10 @@ public Envelope3D getEnvelopeFor(final Object obj) { */ public void rasterText(final String s, final int font, final double x, final double y, final double z) { beginRasterTextMode(); - final boolean previous = setLighting(false); + final boolean previous = setObjectLighting(false); gl.glRasterPos3d(x, y, z); glut.glutBitmapString(font, s); - setLighting(previous); + setObjectLighting(previous); exitRasterTextMode(); } @@ -1291,20 +1319,28 @@ public void beginRasterTextMode() { * @param wireframe * the new display wireframe */ - public void setDisplayWireframe(final boolean wireframe) { - displayIsWireframe = wireframe; - updatePolygonMode(); + public boolean setDisplayWireframe(final boolean wireframe) { + boolean old = displayIsWireframe; + if (old != wireframe) { + displayIsWireframe = wireframe; + updatePolygonMode(); + } + return old; } /** - * Sets the object wireframe. + * Sets the object wireframe. Returns the previous value. * * @param wireframe * the new object wireframe */ - public void setObjectWireframe(final boolean wireframe) { - objectIsWireframe = wireframe; - updatePolygonMode(); + public boolean setObjectWireframe(final boolean wireframe) { + boolean old = objectIsWireframe; + if (old != wireframe) { + objectIsWireframe = wireframe; + updatePolygonMode(); + } + return old; } /** @@ -1403,12 +1439,12 @@ public void drawCachedGeometry(final GamaGeometryFile file, final Color border) if (border != null || isWireframe()) { final Color colorToUse = border != null ? border : getCurrentColor(); final Color old = swapCurrentColor(colorToUse); - setObjectWireframe(true); + boolean previous = setObjectWireframe(true); try { drawList(index); } finally { setCurrentColor(old); - setObjectWireframe(false); + setObjectWireframe(previous); } } } @@ -1430,12 +1466,12 @@ public void drawCachedGeometry(final IShape.Type id, /* final boolean solid, */ if (border != null || isWireframe()) { final Color colorToUse = border != null ? border : getCurrentColor(); final Color old = swapCurrentColor(colorToUse); - setObjectWireframe(true); + boolean previous = setObjectWireframe(true); try { object.draw(this); } finally { setCurrentColor(old); - setObjectWireframe(false); + setObjectWireframe(previous); } } } @@ -1456,7 +1492,8 @@ public void initializeShapeCache() { */ public boolean isTextured() { return textured && !isWireframe(); } - // COMPLEX SHAPES + /** The previous object lighting. */ + boolean previousObjectWireframe, previousObjectLighting; /** * Begin object. @@ -1468,9 +1505,9 @@ public void beginObject(final AbstractObject object, final boolean isPicking) { // DEBUG.OUT("Object " + object + " begin and is " + (object.getAttributes().isEmpty() ? "empty" : "filled")); DrawingAttributes att = object.getAttributes(); if (isPicking) { registerForSelection(att.getIndex()); } - setLighting(att.isLighting()); boolean empty = att.isEmpty(); - setObjectWireframe(empty); + previousObjectWireframe = setObjectWireframe(empty); + previousObjectLighting = setObjectLighting(att.isLighting()); setLineWidth(att.getLineWidth()); setCurrentTextures(object.getPrimaryTexture(this), object.getAlternateTexture(this)); setCurrentColor(att.getColor()); @@ -1492,24 +1529,28 @@ public void endObject(final AbstractObject object, final boolean isPicking) { if (object.isFilled() && !object.getAttributes().isSynthetic()) { gl.glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_MODULATE); } - // setObjectWireframe(false); + setObjectLighting(previousObjectLighting); + setObjectWireframe(previousObjectWireframe); if (isPicking) { renderer.getPickingHelper().tryPick(object.getAttributes()); } } + /** The previous display lighting. */ + boolean previousDisplayWireframe, previousDisplayLighting; + /** * Begin scene. * * @return the pass */ public Pass beginScene() { - setDisplayWireframe(getData().isWireframe()); + previousDisplayWireframe = setDisplayWireframe(getData().isWireframe()); + previousDisplayLighting = setDisplayLighting(getData().isLightOn()); processUnloadedCacheObjects(); final Color backgroundColor = getData().getBackgroundColor(); gl.glClearColor(backgroundColor.getRed() / 255.0f, backgroundColor.getGreen() / 255.0f, backgroundColor.getBlue() / 255.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); gl.glClearDepth(1.0f); - setLighting(getData().isLightOn()); resetMatrix(GLMatrixFunc.GL_PROJECTION); updatePerspective(gl); resetMatrix(GLMatrixFunc.GL_MODELVIEW); @@ -1518,6 +1559,22 @@ public Pass beginScene() { return endScene; } + /** + * End scene. + */ + public void endScene() { + boolean drawFPS = getData().isShowfps(); + boolean drawRotation = rotationMode && SHOULD_DRAW_ROTATION_SPHERE; + boolean drawROI = roiEnvelope != null; + if (drawFPS || drawRotation || drawROI) { disableTextures(); } + drawFPS(drawFPS); + drawROI(drawROI); + drawRotation(drawRotation); + setDisplayLighting(previousDisplayLighting); + setDisplayWireframe(previousDisplayWireframe); + gl.glFinish(); + } + /** * Process unloaded cache objects. */ @@ -1553,24 +1610,6 @@ public void rotateModel() { } } - /** - * End scene. - */ - public void endScene() { - boolean drawFPS = getData().isShowfps(); - boolean drawRotation = rotationMode && SHOULD_DRAW_ROTATION_SPHERE; - boolean drawROI = roiEnvelope != null; - if (drawFPS || drawRotation || drawROI) { - disableTextures(); - setLighting(false); - } - drawFPS(drawFPS); - drawROI(drawROI); - drawRotation(drawRotation); - // gl.glFlush(); - gl.glFinish(); - } - /** * Initialize GL states. * diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/KeystoneHelper.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/KeystoneHelper.java index 45a16c8eec..44383567da 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/KeystoneHelper.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/KeystoneHelper.java @@ -1,12 +1,12 @@ /******************************************************************************************************* * - * KeystoneHelper.java, in ummisco.gama.opengl, is part of the source code of the - * GAMA modeling and simulation platform (v.1.8.2). + * KeystoneHelper.java, in ummisco.gama.opengl, is part of the source code of the GAMA modeling and simulation platform + * (v.1.8.2). * * (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. - * + * ********************************************************************************************************/ package ummisco.gama.opengl.renderer.helpers; @@ -40,31 +40,31 @@ public class KeystoneHelper extends AbstractRendererHelper { /** The finishing helper. */ private final Pass finishingHelper = this::finishRenderToTexture; - + /** The fbo scene. */ private FrameBufferObject fboScene; - + /** The draw keystone helper. */ protected boolean drawKeystoneHelper = false; - + /** The corner hovered. */ protected int cornerSelected = -1, cornerHovered = -1; - + /** The uv mapping buffer index. */ private int uvMappingBufferIndex; - + /** The vertices buffer index. */ private int verticesBufferIndex; - + /** The index buffer index. */ private int indexBufferIndex; - + /** The shader. */ private KeystoneShaderProgram shader; - + /** The world corners. */ private boolean worldCorners = false; - + /** The Constant FILL_COLORS. */ private static final Color[] FILL_COLORS = { NamedGamaColor.getNamed("gamared").withAlpha(0.3), NamedGamaColor.getNamed("gamablue").withAlpha(0.3), NamedGamaColor.getNamed("black").withAlpha(0.3) }; @@ -75,7 +75,8 @@ public class KeystoneHelper extends AbstractRendererHelper { /** * Instantiates a new keystone helper. * - * @param r the r + * @param r + * the r */ public KeystoneHelper(final IOpenGLRenderer r) { super(r); @@ -111,23 +112,20 @@ public void initialize() { * * @return the corner selected */ - public int getCornerSelected() { - return cornerSelected; - } + public int getCornerSelected() { return cornerSelected; } /** * Gets the coords. * * @return the coords */ - public GamaPoint[] getCoords() { - return getData().getKeystone().toCoordinateArray(); - } + public GamaPoint[] getCoords() { return getData().getKeystone().toCoordinateArray(); } /** * Gets the keystone coordinates. * - * @param corner the corner + * @param corner + * the corner * @return the keystone coordinates */ public GamaPoint getKeystoneCoordinates(final int corner) { @@ -186,13 +184,20 @@ public void beginRenderToTexture() { /** * Draw rectangle. * - * @param openGL the open GL - * @param centerX the center X - * @param centerY the center Y - * @param centerZ the center Z - * @param width the width - * @param height the height - * @param fill the fill + * @param openGL + * the open GL + * @param centerX + * the center X + * @param centerY + * the center Y + * @param centerZ + * the center Z + * @param width + * the width + * @param height + * the height + * @param fill + * the fill */ private void drawRectangle(final OpenGL openGL, final double centerX, final double centerY, final double centerZ, final double width, final double height, final Color fill) { @@ -238,7 +243,7 @@ private void drawKeystoneMarks() { openGL.pushIdentity(GLMatrixFunc.GL_PROJECTION); gl.glOrtho(0, 1, 0, 1, 1, -1); - openGL.setLighting(false); + boolean previous = openGL.setObjectLighting(false); openGL.push(GLMatrixFunc.GL_MODELVIEW); vertices.visit((id, x, y, z) -> { // Basic computations on text and color @@ -262,7 +267,7 @@ private void drawKeystoneMarks() { openGL.getGlut().glutBitmapString(GLUT.BITMAP_HELVETICA_18, text); }, 4, true); openGL.pop(GLMatrixFunc.GL_MODELVIEW); - openGL.setLighting(true); + openGL.setObjectLighting(previous); openGL.pop(GLMatrixFunc.GL_PROJECTION); } @@ -270,7 +275,8 @@ private void drawKeystoneMarks() { /** * Floor 4 digit. * - * @param n the n + * @param n + * the n * @return the double */ private double floor4Digit(final double n) { @@ -325,7 +331,8 @@ public KeystoneShaderProgram getShader() { /** * Prepare shader. * - * @param shaderProgram the shader program + * @param shaderProgram + * the shader program */ private void prepareShader(final AbstractPostprocessingShader shaderProgram) { shaderProgram.loadTexture(0); @@ -389,10 +396,14 @@ public void createScreenSurface() { /** * Store attributes. * - * @param shaderAttributeType the shader attribute type - * @param bufferIndex the buffer index - * @param size the size - * @param data the data + * @param shaderAttributeType + * the shader attribute type + * @param bufferIndex + * the buffer index + * @param size + * the size + * @param data + * the data */ private void storeAttributes(final int shaderAttributeType, final int bufferIndex, final int size, final float[] data) { @@ -413,16 +424,16 @@ private void storeAttributes(final int shaderAttributeType, final int bufferInde /** * Sets the corner selected. * - * @param cornerId the new corner selected + * @param cornerId + * the new corner selected */ - public void setCornerSelected(final int cornerId) { - cornerSelected = cornerId; - } + public void setCornerSelected(final int cornerId) { cornerSelected = cornerId; } /** * Reset corner. * - * @param cornerId the corner id + * @param cornerId + * the corner id */ public void resetCorner(final int cornerId) { setKeystoneCoordinates(cornerId, LayeredDisplayData.KEYSTONE_IDENTITY.at(cornerId)); @@ -433,7 +444,8 @@ public void resetCorner(final int cornerId) { /** * Corner selected. * - * @param mouse the mouse + * @param mouse + * the mouse * @return the int */ public int cornerSelected(final GamaPoint mouse) { @@ -442,7 +454,8 @@ public int cornerSelected(final GamaPoint mouse) { return 1; else return 0; - } else if (mouse.y < getViewHeight() / 2) + } + if (mouse.y < getViewHeight() / 2) return 2; else return 3; @@ -451,7 +464,8 @@ public int cornerSelected(final GamaPoint mouse) { /** * Corner hovered. * - * @param mouse the mouse + * @param mouse + * the mouse * @return the int */ public int cornerHovered(final GamaPoint mouse) { @@ -460,7 +474,8 @@ public int cornerHovered(final GamaPoint mouse) { return 1; else return 0; - } else if (mouse.y < getViewHeight() / 2) + } + if (mouse.y < getViewHeight() / 2) return 2; else return 3; @@ -469,17 +484,18 @@ public int cornerHovered(final GamaPoint mouse) { /** * Sets the corner hovered. * - * @param cornerId the new corner hovered + * @param cornerId + * the new corner hovered */ - public void setCornerHovered(final int cornerId) { - cornerHovered = cornerId; - } + public void setCornerHovered(final int cornerId) { cornerHovered = cornerId; } /** * Sets the keystone coordinates. * - * @param cornerId the corner id - * @param p the p + * @param cornerId + * the corner id + * @param p + * the p */ public void setKeystoneCoordinates(final int cornerId, final GamaPoint p) { getData().getKeystone().replaceWith(cornerId, p.x, p.y, p.z); @@ -492,9 +508,7 @@ public void setKeystoneCoordinates(final int cornerId, final GamaPoint p) { * * @return true, if is active */ - public boolean isActive() { - return drawKeystoneHelper; - } + public boolean isActive() { return drawKeystoneHelper; } /** * Render. @@ -512,8 +526,10 @@ public Pass render() { /** * Reshape. * - * @param width the width - * @param height the height + * @param width + * the width + * @param height + * the height */ public void reshape(final int width, final int height) { if (fboScene != null) { fboScene.setDisplayDimensions(width, height); } diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/LightHelper.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/LightHelper.java index 3c5e6c6f0f..8f26d98b10 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/LightHelper.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/renderer/helpers/LightHelper.java @@ -112,9 +112,9 @@ public void updateDiffuseLightValue(final OpenGL openGL) { } if (light.isDrawing()) { // disable the lighting during the time the light is drawn - final boolean previous = openGL.setLighting(false); + final boolean previous = openGL.setObjectLighting(false); drawLight(openGL, size, worldWidth, worldHeight, light, lightPosition); - openGL.setLighting(previous); + openGL.setObjectLighting(previous); } } else { gl.glDisable(id); diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/geometry/GeometryDrawer.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/geometry/GeometryDrawer.java index a9bc9d11f5..408f1ceb97 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/geometry/GeometryDrawer.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/geometry/GeometryDrawer.java @@ -436,15 +436,15 @@ private void drawLineCylinder(final Geometry g, /* final boolean solid, */ final final GamaPoint v2 = _vertices.at(i + 1); // draw first sphere _center.setLocation(v1); - _normal.setLocation(v2); - _normal.subtract(v1); + _normal.setLocation(v2).subtract(v1); final double height = _normal.norm(); _tangent.setLocation(_normal.orthogonal()); _normal.normalize(); - if (i > 0) { - _scale.setTo(radius); - drawCachedGeometry(Type.SPHERE, /* solid, */ border); - } + // if (i > 0) { + // _scale.setTo(radius); + // drawCachedGeometry(Type.SPHERE, /* solid, */ border); + // } + // _center.setLocation(v1); // draw tube _scale.setTo(radius, radius, height); drawCachedGeometry(Type.CYLINDER, /* solid, */border); @@ -469,7 +469,7 @@ private void drawCone3D(final Geometry p, /* final boolean solid, */final double _vertices.getCenter(_center); _vertices.getNormal(true, 1, _normal); _tangent.setLocation(_center).subtract(_vertices.at(0)); - _rot.rotateToHorizontal(_normal, _tangent, false).revertInPlace(); + // _rot.rotateToHorizontal(_normal, _tangent, false).revertInPlace(); _scale.setTo(radius, radius, height); drawCachedGeometry(Type.CONE, /* solid, */ border); } @@ -517,10 +517,14 @@ public void drawROIHelper(final Envelope3D envelope) { final Polygon polygon = envelope.yNegated().toGeometry(); gl.setCurrentColor(0, 0.5, 0, 0.15); gl.setZIncrement(0); - boolean old = gl.isWireframe(); - gl.setObjectWireframe(false); - drawPolyhedron(polygon, /* true, */ envelope.getMaxZ(), DEFAULT_BORDER); - gl.setObjectWireframe(old); + boolean old = gl.setObjectWireframe(false); + boolean previous = gl.setObjectLighting(false); + try { + drawPolyhedron(polygon, /* true, */ envelope.getMaxZ(), DEFAULT_BORDER); + } finally { + gl.setObjectWireframe(old); + gl.setObjectLighting(previous); + } } /** @@ -536,10 +540,14 @@ public void drawRotationHelper(final GamaPoint target, final double distance, fi gl.setCurrentColor(Color.gray, 0.3); final GamaPoint position = target.yNegated().add(0, 0, -height); final Geometry point = GamaGeometryType.buildCircle(height, position).getInnerGeometry(); - boolean old = gl.isWireframe(); - gl.setObjectWireframe(false); - drawSphere(point, /* true, */ height, DEFAULT_BORDER); - gl.setObjectWireframe(old); + boolean old = gl.setObjectWireframe(false); + boolean previous = gl.setObjectLighting(false); + try { + drawSphere(point, /* true, */ height, DEFAULT_BORDER); + } finally { + gl.setObjectWireframe(old); + gl.setObjectLighting(previous); + } } @Override diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/AxesLayerObject.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/AxesLayerObject.java index 19d5761bc9..6dda18fbf1 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/AxesLayerObject.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/AxesLayerObject.java @@ -102,6 +102,7 @@ public void setScale(final GamaPoint s) { @Override public void draw(final OpenGL gl) { + boolean previous = gl.setObjectWireframe(false); if (renderer.getOpenGLHelper().isInRotationMode()) { final GamaPoint pivotPoint = renderer.getCameraTarget(); setOffset(pivotPoint.yNegated()); @@ -113,6 +114,7 @@ public void draw(final OpenGL gl) { setScale(null); } super.draw(gl); + gl.setObjectWireframe(previous); } @Override @@ -120,7 +122,7 @@ public void fillWithObjects(final List> list) { for (int i = 0; i < 3; i++) { final GamaPoint p = dirs[i]; // build axis - addSyntheticObject(list, axes[i], COLORS[i], IShape.Type.LINECYLINDER, false); + addSyntheticObject(list, axes[i], COLORS[i], IShape.Type.LINECYLINDER); // build labels final TextDrawingAttributes text = new TextDrawingAttributes(of(1), null, p.times(1.3).yNegated(), COLORS[i]); @@ -130,7 +132,7 @@ public void fillWithObjects(final List> list) { list.add(new StringObject(LABELS[i], text)); // build arrows final GamaShape s = new GamaShape(arrow, null, ROTATIONS[i], p.times(0.98)); - addSyntheticObject(list, s, COLORS[i], IShape.Type.CONE, false); + addSyntheticObject(list, s, COLORS[i], IShape.Type.CONE); } } @@ -149,10 +151,10 @@ public void fillWithObjects(final List> list) { * the empty */ protected void addSyntheticObject(final List> list, final IShape shape, final GamaColor color, - final IShape.Type type, final boolean empty) { + final IShape.Type type) { final DrawingAttributes att = new ShapeDrawingAttributes(shape, (IAgent) null, color, color, type, GamaPreferences.Displays.CORE_LINE_WIDTH.getValue(), null); - att.setEmpty(empty); + att.setEmpty(false); att.setHeight(shape.getDepth()); att.setLighting(false); list.add(new GeometryObject(shape.getInnerGeometry(), att)); diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/FrameLayerObject.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/FrameLayerObject.java index d556e5767b..81f25feb54 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/FrameLayerObject.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/FrameLayerObject.java @@ -47,7 +47,7 @@ public void fillWithObjects(final List> list) { final double h = renderer.getData().getEnvHeight(); final IShape g = GamaGeometryType.buildRectangle(w, h, new GamaPoint(w / 2, h / 2)); final DrawingAttributes drawingAttr = new ShapeDrawingAttributes(g, (IAgent) null, null, FRAME); - drawingAttr.setLighting(false); + // drawingAttr.setLighting(false); final GeometryObject geomObj = new GeometryObject(g.getInnerGeometry(), drawingAttr); list.add(geomObj); } diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/OverlayLayerObject.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/OverlayLayerObject.java index 50a0fd7753..2068a5472f 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/OverlayLayerObject.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/OverlayLayerObject.java @@ -77,13 +77,17 @@ protected void addFrame(final OpenGL gl) { if (size.y <= 1) { size.y *= renderer.getEnvHeight(); } } gl.pushMatrix(); - gl.setObjectWireframe(false); - gl.translateBy(0, -size.y, 0); - gl.scaleBy(size.x, size.y, 1); - gl.setCurrentColor(((OverlayLayer) layer).getData().getBackgroundColor(scope), - 1 - layer.getData().getTransparency(scope)); - gl.drawCachedGeometry(IShape.Type.ROUNDED, null); - gl.popMatrix(); + boolean previous = gl.setObjectWireframe(false); + try { + gl.translateBy(0, -size.y, 0); + gl.scaleBy(size.x, size.y, 1); + gl.setCurrentColor(((OverlayLayer) layer).getData().getBackgroundColor(scope), + 1 - layer.getData().getTransparency(scope)); + gl.drawCachedGeometry(IShape.Type.ROUNDED, null); + } finally { + gl.setObjectWireframe(previous); + gl.popMatrix(); + } } @Override diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/StaticLayerObject.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/StaticLayerObject.java index e4149e50cc..fab8b600cd 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/StaticLayerObject.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/layers/StaticLayerObject.java @@ -57,9 +57,9 @@ public void draw(final OpenGL gl) { if (currentList.isEmpty()) { fillWithObjects(currentList); } gl.suspendZTranslation(); - final boolean previous = gl.setLighting(false); + final boolean previous = gl.setDisplayLighting(false); super.draw(gl); - gl.setLighting(previous); + gl.setDisplayLighting(previous); gl.resumeZTranslation(); } diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/LegacyMeshDrawer.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/LegacyMeshDrawer.java index d913cb042e..df5d9c68a5 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/LegacyMeshDrawer.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/LegacyMeshDrawer.java @@ -297,14 +297,14 @@ public void drawField() { ogl.glVertex3d(vertexBuffer.get(one), vertexBuffer.get(two), vertexBuffer.get(three)); } if (outputsLines) { - gl.setObjectWireframe(true); + boolean previous = gl.setObjectWireframe(true); for (var index = 0; index < indexBuffer.limit(); index++) { var i = indexBuffer.get(index); gl.setCurrentColor(lineColorBuffer.get(i * 3), lineColorBuffer.get(i * 3 + 1), lineColorBuffer.get(i + 1), 1); gl.outputVertex(vertexBuffer.get(i * 3), vertexBuffer.get(i * 3 + 1), vertexBuffer.get(i * 3 + 2)); } - gl.setObjectWireframe(false); + gl.setObjectWireframe(previous); } } finally { gl.endDrawing(); @@ -337,12 +337,12 @@ public void drawLabels(final OpenGL gl) { } } gl.beginRasterTextMode(); - final var previous = gl.setLighting(false); + final var previous = gl.setObjectLighting(false); for (var i = 0; i < strings.length; i++) { gl.getGL().glRasterPos3d(coords[i * 3], coords[i * 3 + 1], coords[i * 3 + 2] + gl.getCurrentZTranslation()); gl.getGlut().glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_10, strings[i]); } - gl.setLighting(previous); + gl.setObjectLighting(previous); gl.exitRasterTextMode(); } diff --git a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/MeshDrawer.java b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/MeshDrawer.java index d7925dba6a..a6ee3605d8 100644 --- a/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/MeshDrawer.java +++ b/ummisco.gama.opengl/src/ummisco/gama/opengl/scene/mesh/MeshDrawer.java @@ -320,14 +320,14 @@ public void drawFieldFallback() { ogl.glVertex3d(vertexBuffer.get(one), vertexBuffer.get(two), vertexBuffer.get(three)); } if (outputsLines) { - gl.setObjectWireframe(true); + boolean previous = gl.setObjectWireframe(true); for (var index = 0; index < indexBuffer.limit(); index++) { var i = indexBuffer.get(index); gl.setCurrentColor(lineColorBuffer.get(i * 3), lineColorBuffer.get(i * 3 + 1), lineColorBuffer.get(i + 1), 1); gl.outputVertex(vertexBuffer.get(i * 3), vertexBuffer.get(i * 3 + 1), vertexBuffer.get(i * 3 + 2)); } - gl.setObjectWireframe(false); + gl.setObjectWireframe(previous); } gl.endDrawing(); ogl.glBlendColor(0.0f, 0.0f, 0.0f, 0.0f); @@ -371,9 +371,9 @@ public void drawField() { if (outputsLines) { if (!outputsColors) { gl.enable(GLPointerFunc.GL_COLOR_ARRAY); } ogl.glColorPointer(3, GL2GL3.GL_DOUBLE, 0, lineColorBuffer); - gl.setObjectWireframe(true); + boolean previous = gl.setObjectWireframe(true); ogl.glDrawElements(GL.GL_TRIANGLES, indexBuffer.limit(), GL.GL_UNSIGNED_INT, indexBuffer); - gl.setObjectWireframe(false); + gl.setObjectWireframe(previous); } } finally { @@ -413,12 +413,12 @@ public void drawLabels(final OpenGL gl) { } } gl.beginRasterTextMode(); - final var previous = gl.setLighting(false); + final var previous = gl.setObjectLighting(false); for (var i = 0; i < strings.length; i++) { gl.getGL().glRasterPos3d(coords[i * 3], coords[i * 3 + 1], coords[i * 3 + 2] + gl.getCurrentZTranslation()); gl.getGlut().glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_10, strings[i]); } - gl.setLighting(previous); + gl.setObjectLighting(previous); gl.exitRasterTextMode(); }