Skip to content
This repository has been archived by the owner on Oct 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #35 from adamjryan/fixbuilddraw
Browse files Browse the repository at this point in the history
Prevent a buildings construction image from jittering.
  • Loading branch information
michaelzangl committed Apr 25, 2015
2 parents 289727d + b496230 commit a7ed8db
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go.graphics/src/go/graphics/GlCachingDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected GLBuffer() {

private int currentTriangles = 0;

protected void addTirangles(float[] triangles) {
protected void addTriangles(float[] triangles) {
for (int i = 0; i < triangles.length; i += 5 * 3) {
addTexturedTriangle(triangles, i);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ protected GLBuffer getBuffer(int texture) {
@Override
public void drawTrianglesWithTexture(int textureid, float[] geometry) {
GLBuffer buffer = getBuffer(textureid);
buffer.addTirangles(geometry);
buffer.addTriangles(geometry);
}

@Override
Expand Down
34 changes: 30 additions & 4 deletions jsettlers.graphics/src/jsettlers/graphics/image/SingleImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,35 @@ public void drawTriangle(GLDrawContext gl, DrawBuffer buffer, float viewX,
float left = getOffsetX() + viewX;
float top = -getOffsetY() + viewY;

buffer2.addTirangle(left + u1 * width, top - v1 * height, left + u2
* width, top - v2 * height, left + u3 * width, top - v3
* height, convertU(u1), convertV(v1), convertU(u2),
convertV(v2), convertU(u3), convertV(v3), activeColor);
buffer2.addTriangle(
alignCoord( left + u1 * width ),
alignCoord( top - v1 * height ),
alignCoord( left + u2 * width ),
alignCoord( top - v2 * height ),
alignCoord( left + u3 * width ),
alignCoord( top - v3 * height ),
convertU(u1),
convertV(v1),
convertU(u2),
convertV(v2),
convertU(u3),
convertV(v3),
activeColor
);
}

/**
* In the draw process sub-integer coordinates can be rounded in unexpected ways that is particularly noticeable when redrawing the
* growing image of a building in the construction phase. By aligning to the nearest integer images can be placed in a more
* predictable and controlled manner.
* @param value the coordinate to be aligned.
* @return an aligned coordinate value.
*/
private float alignCoord( float value )
{
//At larger scales the issue is still present to some degree which zoomFactor helps to minimize.
//TODO need to find the factor based on the zoom level.
float zoomFactor = 1.06f;
return (float)((Math.floor( value * zoomFactor )) / zoomFactor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ protected void addImage(float x1, float y1, float x2, float y2, float u1, float
currentTriangles += 2;
}

public void addTirangle(float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3,
float v3, int activeColor) {
public void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3,
float u1, float v1, float u2, float v2, float u3, float v3, int activeColor) {
if (currentTriangles >= BUFFER_TRIANGLES - 1) {
draw();
}
Expand Down
4 changes: 4 additions & 0 deletions jsettlers.logic/src/jsettlers/logic/buildings/Building.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ private boolean positionAt(IBuildingsGrid grid, ShortPoint2D pos) {
return couldBePlaced;
}

/**
* Used to set or clear the small red flag atop a building to indicate it is occupied.
* @param place specifies whether the flag should appear or not.
*/
protected void placeFlag(boolean place) {
ShortPoint2D flagPosition = type.getFlag().calculatePoint(pos);

Expand Down

0 comments on commit a7ed8db

Please sign in to comment.