Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
96f78f8
Changed lerp() to lerpUnclamped()
ArtifactForms Dec 24, 2024
613e500
Added clamped lerp
ArtifactForms Dec 24, 2024
64942f0
Changed negateLocal to a more readable an potentially faster
ArtifactForms Dec 25, 2024
e0e87eb
Changed negate back to old version. New version didn't pass tests.
ArtifactForms Dec 25, 2024
ba586f0
feat(math): Add Vector4f.multiply(Matrix4) method with unit tests
ArtifactForms Dec 25, 2024
8c6012d
feat(math): Add Vector4f.toVector3f() method with unit tests
ArtifactForms Dec 25, 2024
5e155c4
Add divideByW and divideByWLocal methods to Vector4f with unit tests
ArtifactForms Dec 25, 2024
a14a555
Refactor:
ArtifactForms Dec 26, 2024
56011d1
Feat: Added boolean equals(float a, float b, float epsilon)
ArtifactForms Dec 26, 2024
53c9625
Format changes.
ArtifactForms Dec 27, 2024
f8cb6c0
Format changes.
ArtifactForms Dec 27, 2024
bda6c0a
Initial implementation of the ProArchCreator class for generating 3D
ArtifactForms Dec 27, 2024
fa292d1
Fix incorrect angle calculation in ArcCreator
ArtifactForms Dec 28, 2024
096553c
Added center property to ArcCreator to allow specifying
ArtifactForms Dec 28, 2024
95080d0
Added java doc.
ArtifactForms Dec 28, 2024
7f3acc8
Feat: Implemented RoundCornerPlaneCreator
ArtifactForms Dec 28, 2024
3721fc2
Add getter and setter for camera movement speed in FlyByCameraControl
ArtifactForms Dec 29, 2024
71d8a03
Added getMouseSensitivity() and setMouseSensitivity() methods with
ArtifactForms Dec 30, 2024
0eee805
Refactor: Optimized FlyByCameraControl update by calling updateTarget
ArtifactForms Dec 30, 2024
aae734f
Feat: Added Uv and texture support.
ArtifactForms Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/main/java/engine/components/FlyByCameraControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ public void update(float tpf) {
float mouseY = input.getMouseDeltaY() * mouseSensitivity * tpf;

handleRotation(mouseX, mouseY);
updateTarget();

Vector3f velocity = calculateVelocity();
if (velocity.length() > 0) {
applyMovement(velocity, tpf);
}

updateTarget();
input.center();
}

Expand Down Expand Up @@ -147,7 +146,6 @@ private void applyMovement(Vector3f velocity, float tpf) {
Vector3f position = camera.getTransform().getPosition();
position.addLocal(velocity.mult(moveSpeed * tpf));
camera.getTransform().setPosition(position);
updateTarget();
}

/**
Expand Down Expand Up @@ -180,4 +178,46 @@ public void onAttach() {
public void onDetach() {
// Not used yet
}

/**
* Returns the current movement speed of the camera.
*
* @return The movement speed in units per second.
*/
public float getMoveSpeed() {
return moveSpeed;
}

/**
* Sets the movement speed of the camera.
*
* @param moveSpeed The new movement speed in units per second.
*/
public void setMoveSpeed(float moveSpeed) {
this.moveSpeed = moveSpeed;
}

/**
* Returns the current mouse sensitivity used for camera rotation.
*
* <p>The mouse sensitivity determines how much the camera rotates based on mouse movement. Higher
* sensitivity values result in larger rotations for smaller mouse movements.
*
* @return The current mouse sensitivity.
*/
public float getMouseSensitivity() {
return mouseSensitivity;
}

/**
* Sets the mouse sensitivity used for camera rotation.
*
* <p>The mouse sensitivity determines how much the camera rotates based on mouse movement. Higher
* sensitivity values result in larger rotations for smaller mouse movements.
*
* @param mouseSensitivity The new mouse sensitivity value.
*/
public void setMouseSensitivity(float mouseSensitivity) {
this.mouseSensitivity = mouseSensitivity;
}
}
2 changes: 2 additions & 0 deletions src/main/java/engine/processing/ProcessingApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import engine.input.KeyInput;
import engine.input.MouseInput;
import engine.resources.ResourceManager;
import engine.resources.TextureManager;
import processing.core.PApplet;
import workspace.GraphicsPImpl;
import workspace.ui.Graphics;
Expand All @@ -31,6 +32,7 @@ public void settings() {
public void setup() {
Graphics g = new GraphicsPImpl(this);
ResourceManager.getInstance().setImageLoader(new ProcessingImageLoader(this));
TextureManager.getInstance().setTextureLoader(new ProcessingTextureLoader(this));
container.setGraphics(g);
getSurface().setTitle(settings.getTitle());
setupInput();
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/engine/processing/ProcessingTexture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package engine.processing;

import engine.resources.Texture;
import processing.core.PImage;

public class ProcessingTexture implements Texture {

private final PImage image;

public ProcessingTexture(PImage image) {
this.image = image;
}

@Override
public int getWidth() {
return image.width;
}

@Override
public int getHeight() {
return image.height;
}

@Override
public void bind(int unit) {
// Processing doesn't use texture units in the same way, just bind globally
image.loadPixels();
}

@Override
public void unbind() {
// No specific unbind operation for Processing
}

@Override
public void delete() {
// Processing handles memory management automatically
}

public PImage getImage() {
return image;
}
}
27 changes: 27 additions & 0 deletions src/main/java/engine/processing/ProcessingTextureLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package engine.processing;

import engine.resources.Texture;
import engine.resources.TextureLoader;
import processing.core.PApplet;
import processing.core.PImage;

public class ProcessingTextureLoader implements TextureLoader {

private final PApplet parent;

public ProcessingTextureLoader(PApplet parent) {
this.parent = parent;
}

@Override
public Texture loadTexture(String filePath) {
PImage image =
parent.loadImage(
ProcessingTextureLoader.class
.getClassLoader()
.getResource("images/" + filePath)
.getPath());
ProcessingTexture texture = new ProcessingTexture(image);
return texture;
}
}
52 changes: 50 additions & 2 deletions src/main/java/engine/render/Material.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package engine.render;

import engine.resources.Texture;
import math.Color;
import workspace.ui.Graphics;

Expand Down Expand Up @@ -67,6 +68,10 @@ public class Material {
/** Shininess factor for specular highlights. */
private final float shininess;

private Texture normalTexture;

private Texture diffuseTexture;

/**
* Constructor to set the base color of the material.
*
Expand All @@ -83,11 +88,13 @@ private Material(Builder builder) {
this.diffuse = builder.diffuse;
this.specular = builder.specular;
this.shininess = builder.shininess;
this.normalTexture = builder.normalTexture;
this.diffuseTexture = builder.diffuseTexture;
}

/**
* Builder class to facilitate the creation of custom materials with specific lighting and shader
* properties.
* Builder class to facilitate the creation of custom materials with specific lighting, shader and
* texture properties.
*/
public static class Builder {

Expand All @@ -103,6 +110,10 @@ public static class Builder {

private float shininess = 10.0f;

private Texture diffuseTexture = null;

private Texture normalTexture = null;

/**
* Sets the base color of the material.
*
Expand Down Expand Up @@ -163,6 +174,28 @@ public Builder setUseLighting(boolean useLighting) {
return this;
}

/**
* Sets the normal texture of the material.
*
* @param normalTexture The normal texture, can be null
* @return The builder instance for chaining
*/
public Builder setNormalTexture(Texture normalTexture) {
this.normalTexture = normalTexture;
return this;
}

/**
* Sets the diffuse texture of the material.
*
* @param diffuseTexture The diffuse texture, can be null.
* @return The builder instance for chaining
*/
public Builder setDiffuseTexture(Texture diffuseTexture) {
this.diffuseTexture = diffuseTexture;
return this;
}

/**
* Builds and returns the Material instance with the set properties.
*
Expand All @@ -180,6 +213,13 @@ public Material build() {
*/
public void apply(Graphics g) {
g.setMaterial(this);

if (diffuseTexture != null) {
g.bindTexture(diffuseTexture, 0); // Bind to texture unit 0
}
if (normalTexture != null) {
g.bindTexture(normalTexture, 1); // Bind to texture unit 1
}
}

/**
Expand Down Expand Up @@ -240,4 +280,12 @@ public float[] getSpecular() {
public float getShininess() {
return shininess;
}

public Texture getDiffuseTexture() {
return diffuseTexture;
}

public Texture getNormalTexture() {
return normalTexture;
}
}
14 changes: 14 additions & 0 deletions src/main/java/engine/resources/Texture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package engine.resources;

public interface Texture {

int getWidth();

int getHeight();

void bind(int unit); // Bind to a specific texture unit

void unbind();

void delete();
}
6 changes: 6 additions & 0 deletions src/main/java/engine/resources/TextureLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package engine.resources;

public interface TextureLoader {

Texture loadTexture(String filePath);
}
45 changes: 45 additions & 0 deletions src/main/java/engine/resources/TextureManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package engine.resources;

import java.util.HashMap;
import java.util.Map;

public class TextureManager {

private static TextureManager instance;

private TextureLoader imageLoader;

private final Map<String, Texture> resourceCache = new HashMap<>();

private TextureManager() {}

public static TextureManager getInstance() {
if (instance == null) {
instance = new TextureManager();
}
return instance;
}

public void setTextureLoader(TextureLoader loader) {
this.imageLoader = loader;
}

public Texture loadTexture(String path) {
if (resourceCache.containsKey(path)) {
return resourceCache.get(path); // Return cached resource
}

if (imageLoader == null) {
throw new IllegalStateException("ImageLoader is not set!");
}

Texture texture = imageLoader.loadTexture(path);
resourceCache.put(path, texture);

return texture;
}

public void unloadImage(String path) {
resourceCache.remove(path); // Optionally handle cleanup for backend-specific resources
}
}
25 changes: 22 additions & 3 deletions src/main/java/math/Mathf.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ public class Mathf {
* `numberOfColumns` is less than or equal to zero.
*/
public static int toOneDimensionalIndex(int rowIndex, int colIndex, int numberOfColumns) {
if (rowIndex < 0 || colIndex < 0) throw new IllegalArgumentException();

if (numberOfColumns <= 0) throw new IllegalArgumentException();
if (numberOfColumns <= 0) {
throw new IllegalArgumentException("NumberOfColumns must be greater than zero.");
}
if (rowIndex < 0) {
throw new IllegalArgumentException("rowIndex must be non-negative");
}
if (colIndex < 0 || colIndex >= numberOfColumns) {
throw new IllegalArgumentException("colIndex is out of bounds");
}

return rowIndex * numberOfColumns + colIndex;
}
Expand Down Expand Up @@ -890,4 +896,17 @@ public static float normalizeAngle(float angle) {

return angle;
}

/**
* Compares two floating-point numbers for equality within a given tolerance (epsilon).
*
* @param a The first number.
* @param b The second number.
* @param epsilon The tolerance within which the two numbers are considered equal.
* @return True if the absolute difference between the two numbers is less than or equal to
* epsilon, otherwise false.
*/
public static boolean equals(float a, float b, float epsilon) {
return Math.abs(a - b) <= epsilon;
}
}
Loading
Loading