Skip to content

Commit

Permalink
Fix for #995. Addition of the #isometric camera
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Mar 3, 2022
1 parent 46500e8 commit c023c8c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
10 changes: 5 additions & 5 deletions msi.gama.core/src/msi/gama/outputs/layers/CameraDefinition.java
Expand Up @@ -96,7 +96,8 @@ public void refresh(final IScope scope) {
GamaPoint location;
boolean noLocation = temp == null;
if (noLocation) { temp = GamaPreferences.Displays.OPENGL_DEFAULT_CAM.getValue(); }

// We negate the Y ordinate coming from GAML
target = target.yNegated();
if (temp instanceof String pos) {
// If it is a symbolic position
double w = scope.getSimulation().getWidth();
Expand All @@ -105,11 +106,10 @@ public void refresh(final IScope scope) {
location = computeLocation(pos, target, w, -h, max);
} else {
location = Cast.asPoint(scope, temp);
// The location should be a point now and we negate it as well
location = location.yNegated();
}
// We negate the Y ordinate coming from GAML
target = target.yNegated();
// The location should be a point now and we negate it as well
location = location.yNegated();

// We determine the distance and apply it to the location if it is explicitly defined or if no location has been
// defined
Double d = distanceAttribute.get();
Expand Down
24 changes: 16 additions & 8 deletions msi.gama.core/src/msi/gama/outputs/layers/ICameraDefinition.java
Expand Up @@ -73,10 +73,17 @@ public interface ICameraDefinition extends INamed {
doc = @doc ("Represent the position of the camera, in front and slightly above the scene")) String from_up_front =
"From up front";

/** The from left. */
@constant (
value = "isometric",
category = IOperatorCategory.THREED,
doc = @doc ("Represent the position of the camera, on the left of the scene")) String isometric =
"Isometric";

/** The presets. */
String[] PRESETS =
List.of(from_above, from_left, from_right, from_front, from_up_left, from_up_right, from_up_front)
.toArray(new String[7]);
String[] PRESETS = List
.of(from_above, from_left, from_right, from_front, from_up_left, from_up_right, from_up_front, isometric)
.toArray(new String[7]);

/**
* Gets the location.
Expand Down Expand Up @@ -173,15 +180,15 @@ default void refresh(final IScope scope) {}
* Computes the location of a camera based on a symbolic position, a target and boundarises .
*
* @param pos
* the pos
* the symbolic position
* @param target
* the target
* the target - y-negated already
* @param maxX
* the w
* the dimension on the x axis > 0
* @param maxY
* the h
* the dimension on the y axis > 0
* @param maxZ
* the max
* the dimension on the z axis > 0
* @return the gama point
*/
default GamaPoint computeLocation(final String pos, final GamaPoint target, final double maxX, final double maxY,
Expand All @@ -194,6 +201,7 @@ default GamaPoint computeLocation(final String pos, final GamaPoint target, fina
case from_up_right -> new GamaPoint(target.x + maxX, target.y - maxY / 1000, maxZ);
case from_front -> new GamaPoint(target.x, target.y - maxY, 0);
case from_up_front -> new GamaPoint(target.x, target.y - maxY, maxZ);
case isometric -> new GamaPoint(target.x + maxZ, -maxZ + target.y, maxZ / 1.2);
default -> new GamaPoint(target.x, target.y, maxZ); // FROM_ABOVE
};
}
Expand Down
Expand Up @@ -150,7 +150,7 @@ experiment road_traffic type: gui
}
output
{
display city_display type: opengl
display city_display type: opengl camera: #isometric
{
species building aspect: base refresh: false;
species road aspect: base refresh: false;
Expand Down
Expand Up @@ -62,6 +62,9 @@ experiment Display type: gui autorun: true {
display "From right" parent: shared {
camera "default" location: #from_right distance: 40 / factor target: {w, p.y, 0} dynamic: true;
}
display "Isometric" parent: shared {
camera default location: #isometric target: {p.x, p.y, 0} dynamic: true;
}


}
Expand Down

0 comments on commit c023c8c

Please sign in to comment.