Skip to content

Commit 564404a

Browse files
Merge pull request #61 from ArtifactForms/working2
Working2
2 parents e891d18 + 0207819 commit 564404a

File tree

10 files changed

+464
-49
lines changed

10 files changed

+464
-49
lines changed

src/main/java/engine/components/ControlWASD.java

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
/**
99
* ControlWASD is a movement component that allows moving a node in the scene graph using keyboard
10-
* input (W/A/S/D). It integrates with the scene's transformation system to control position
11-
* changes, allowing basic 3D navigation in a scene graph.
10+
* input (W/A/S/D) or custom key mappings. It integrates with the scene's transformation system to
11+
* control position changes, allowing basic 3D navigation in a scene graph.
1212
*
1313
* <p>Movement is normalized to ensure consistent speed, even when moving diagonally. This class
1414
* supports velocity adjustments via the speed multiplier and works by translating the owning node
1515
* within the 3D world space.
1616
*
17-
* <p>Example usage: Attach this component to a {@link SceneNode} to allow movement using WASD
18-
* keyboard inputs. The position updates depend on the elapsed time per frame to ensure smooth and
19-
* consistent movement over varying frame rates.
17+
* <p>Example usage: Attach this component to a {@link SceneNode} to allow movement using keyboard
18+
* inputs. The position updates depend on the elapsed time per frame to ensure smooth and consistent
19+
* movement over varying frame rates.
2020
*/
2121
public class ControlWASD extends AbstractComponent {
2222

@@ -26,6 +26,18 @@ public class ControlWASD extends AbstractComponent {
2626
/** The Input instance to monitor keyboard events (injected dependency). */
2727
private Input input;
2828

29+
/** Key used for moving left. Default is 'A'. */
30+
private Key leftKey = Key.A;
31+
32+
/** Key used for moving right. Default is 'D'. */
33+
private Key rightKey = Key.D;
34+
35+
/** Key used for moving forward. Default is 'W'. */
36+
private Key forwardKey = Key.W;
37+
38+
/** Key used for moving backward. Default is 'S'. */
39+
private Key backwardKey = Key.S;
40+
2941
/**
3042
* Constructs a new ControlWASD component, injecting the Input logic needed for detecting key
3143
* presses.
@@ -63,7 +75,7 @@ public ControlWASD(Input input, float speed) {
6375
/**
6476
* Updates the movement of the owning node based on keyboard input.
6577
*
66-
* <p>This method calculates the velocity vector by processing the WASD input and applies it to
78+
* <p>This method calculates the velocity vector by processing the input keys and applies it to
6779
* move the node smoothly in the 3D space by adjusting its position over time with respect to
6880
* `tpf` (time per frame).
6981
*
@@ -81,19 +93,20 @@ public void update(float tpf) {
8193
}
8294

8395
/**
84-
* Processes keyboard input to determine velocity. Handles the W/A/S/D keys to allow movement in
85-
* the 3D plane. Normalizes the vector to ensure diagonal movement doesn't lead to faster speeds.
96+
* Processes keyboard input to determine velocity. Handles the configured keys to allow movement
97+
* in the 3D plane. Normalizes the vector to ensure diagonal movement doesn't lead to faster
98+
* speeds.
8699
*
87100
* @return A velocity vector representing the computed movement direction and speed.
88101
*/
89102
private Vector3f handleInput() {
90103
Vector3f velocity = new Vector3f();
91104

92105
// Check for movement inputs
93-
if (input.isKeyPressed(Key.W)) velocity.addLocal(0, 0, -1);
94-
if (input.isKeyPressed(Key.A)) velocity.addLocal(-1, 0, 0);
95-
if (input.isKeyPressed(Key.S)) velocity.addLocal(0, 0, 1);
96-
if (input.isKeyPressed(Key.D)) velocity.addLocal(1, 0, 0);
106+
if (input.isKeyPressed(forwardKey)) velocity.addLocal(0, 0, -1);
107+
if (input.isKeyPressed(leftKey)) velocity.addLocal(-1, 0, 0);
108+
if (input.isKeyPressed(backwardKey)) velocity.addLocal(0, 0, 1);
109+
if (input.isKeyPressed(rightKey)) velocity.addLocal(1, 0, 0);
97110

98111
// Normalize diagonal movement to prevent unintended speed boosts
99112
if (velocity.length() > 0) {
@@ -128,9 +141,49 @@ public void setSpeed(float speed) {
128141
this.speed = speed;
129142
}
130143

144+
/**
145+
* Sets the key used to move left.
146+
*
147+
* @param leftKey The new key to use for left movement.
148+
*/
149+
public void setLeftKey(Key leftKey) {
150+
this.leftKey = leftKey;
151+
}
152+
153+
/**
154+
* Sets the key used to move right.
155+
*
156+
* @param rightKey The new key to use for right movement.
157+
*/
158+
public void setRightKey(Key rightKey) {
159+
this.rightKey = rightKey;
160+
}
161+
162+
/**
163+
* Sets the key used to move forward.
164+
*
165+
* @param forwardKey The new key to use for forward movement.
166+
*/
167+
public void setForwardKey(Key forwardKey) {
168+
this.forwardKey = forwardKey;
169+
}
170+
171+
/**
172+
* Sets the key used to move backward.
173+
*
174+
* @param backwardKey The new key to use for backward movement.
175+
*/
176+
public void setBackwardKey(Key backwardKey) {
177+
this.backwardKey = backwardKey;
178+
}
179+
180+
/** Called when the component is attached to a {@link SceneNode}. Override for custom behavior. */
131181
@Override
132182
public void onAttach() {}
133183

184+
/**
185+
* Called when the component is detached from a {@link SceneNode}. Override for custom behavior.
186+
*/
134187
@Override
135188
public void onDetach() {}
136189
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package engine.components;
2+
3+
import math.Color;
4+
import workspace.ui.Graphics;
5+
6+
/**
7+
* A component that renders a round reticle in the center of the screen. The reticle consists of an
8+
* outer circle and a smaller, filled inner circle, both customizable in terms of radius and color.
9+
*/
10+
public class RoundReticle extends AbstractComponent implements RenderableComponent {
11+
12+
private float outerRadius;
13+
14+
private float innerRadius;
15+
16+
private Color color;
17+
18+
/**
19+
* Creates a default RoundReticle with preset values. Default configuration: - Outer radius: 30 -
20+
* Inner radius: 6 - Color: White
21+
*/
22+
public RoundReticle() {
23+
this(30, 6, Color.WHITE);
24+
}
25+
26+
/**
27+
* Creates a RoundReticle with specified outer radius, inner radius, and color.
28+
*
29+
* @param outerRadius the radius of the outer circle.
30+
* @param innerRadius the radius of the inner filled circle.
31+
* @param color the color of the reticle.
32+
* @throws IllegalArgumentException if any radius is non-positive or color is null.
33+
*/
34+
public RoundReticle(float outerRadius, float innerRadius, Color color) {
35+
setOuterRadius(outerRadius);
36+
setInnerRadius(innerRadius);
37+
setColor(color);
38+
}
39+
40+
/**
41+
* Renders the reticle on the screen, centered in the viewport. The reticle includes an outer
42+
* circle and a filled inner circle.
43+
*
44+
* @param g the {@link Graphics} context used for rendering.
45+
*/
46+
@Override
47+
public void render(Graphics g) {
48+
int centerX = g.getWidth() / 2;
49+
int centerY = g.getHeight() / 2;
50+
51+
// Render reticle circles
52+
g.setColor(color);
53+
renderCenteredOval(g, centerX, centerY, outerRadius, false);
54+
renderCenteredOval(g, centerX, centerY, innerRadius, true);
55+
}
56+
57+
/**
58+
* Draws a centered oval at the specified position.
59+
*
60+
* @param g the {@link Graphics} context used for rendering.
61+
* @param centerX the x-coordinate of the oval's center.
62+
* @param centerY the y-coordinate of the oval's center.
63+
* @param radius the radius of the oval.
64+
* @param filled whether the oval should be filled.
65+
*/
66+
private void renderCenteredOval(
67+
Graphics g, int centerX, int centerY, float radius, boolean filled) {
68+
int diameter = (int) radius;
69+
int topLeftX = centerX - diameter / 2;
70+
int topLeftY = centerY - diameter / 2;
71+
72+
if (filled) {
73+
g.fillOval(topLeftX, topLeftY, diameter, diameter);
74+
} else {
75+
g.drawOval(topLeftX, topLeftY, diameter, diameter);
76+
}
77+
}
78+
79+
/**
80+
* Updates the component. Currently, this method does nothing.
81+
*
82+
* @param tpf time per frame, used for animations or updates.
83+
*/
84+
@Override
85+
public void update(float tpf) {}
86+
87+
/** Called when the component is attached to a {@link engine.SceneNode}. */
88+
@Override
89+
public void onAttach() {}
90+
91+
/** Called when the component is detached from a {@link engine.SceneNode}. */
92+
@Override
93+
public void onDetach() {}
94+
95+
/**
96+
* Gets the outer radius of the reticle.
97+
*
98+
* @return the outer radius.
99+
*/
100+
public float getOuterRadius() {
101+
return outerRadius;
102+
}
103+
104+
/**
105+
* Sets the outer radius of the reticle.
106+
*
107+
* @param outerRadius the new outer radius.
108+
* @throws IllegalArgumentException if the radius is non-positive.
109+
*/
110+
public void setOuterRadius(float outerRadius) {
111+
if (outerRadius <= 0) {
112+
throw new IllegalArgumentException("Outer radius must be greater than 0.");
113+
}
114+
this.outerRadius = outerRadius;
115+
}
116+
117+
/**
118+
* Gets the inner radius of the reticle.
119+
*
120+
* @return the inner radius.
121+
*/
122+
public float getInnerRadius() {
123+
return innerRadius;
124+
}
125+
126+
/**
127+
* Sets the inner radius of the reticle.
128+
*
129+
* @param innerRadius the new inner radius.
130+
* @throws IllegalArgumentException if the radius is non-positive.
131+
*/
132+
public void setInnerRadius(float innerRadius) {
133+
if (innerRadius <= 0) {
134+
throw new IllegalArgumentException("Inner radius must be greater than 0.");
135+
}
136+
this.innerRadius = innerRadius;
137+
}
138+
139+
/**
140+
* Gets the color of the reticle.
141+
*
142+
* @return the color.
143+
*/
144+
public Color getColor() {
145+
return color;
146+
}
147+
148+
/**
149+
* Sets the color of the reticle.
150+
*
151+
* @param color the new color.
152+
* @throws IllegalArgumentException if the color is null.
153+
*/
154+
public void setColor(Color color) {
155+
if (color == null) {
156+
throw new IllegalArgumentException("Color cannot be null.");
157+
}
158+
this.color = color;
159+
}
160+
}

src/main/java/engine/debug/DebugInfoUpdater.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ private void updateCameraInfo(Camera camera) {
104104
setInfo(CATEGORY_CAMERA, "FOV", Mathf.toDegrees(camera.getFieldOfView()));
105105
setInfo(CATEGORY_CAMERA, "Near", camera.getNearPlane());
106106
setInfo(CATEGORY_CAMERA, "Far", camera.getFarPlane());
107+
setInfo(CATEGORY_CAMERA, "PositionX", camera.getTransform().getPosition().getX());
108+
setInfo(CATEGORY_CAMERA, "PositionY", camera.getTransform().getPosition().getY());
109+
setInfo(CATEGORY_CAMERA, "PositionZ", camera.getTransform().getPosition().getZ());
107110
}
108111

109112
private void updateOsMetrics() {

src/main/java/engine/processing/LightRendererImpl.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,24 @@ public void render(SpotLight light) {
6666

6767
public void render(PointLight light) {
6868
renderCommon(light.getColor(), light.getIntensity());
69+
70+
float intensity = light.getIntensity();
71+
72+
// Retrieve light color
73+
float red = light.getColor().getRed(); // Gives a value from 0 to 1
74+
float green = light.getColor().getGreen(); // Same for green
75+
float blue = light.getColor().getBlue(); // Same for blue
76+
77+
// Apply intensity to each color component
78+
red *= intensity;
79+
green *= intensity;
80+
blue *= intensity;
81+
82+
// Call pointLight() with adjusted color
6983
p.pointLight(
70-
light.getColor().getRedInt(),
71-
light.getColor().getGreenInt(),
72-
light.getColor().getBlueInt(),
84+
red * 255, // Scale back to 0-255 range for Processing's pointLight
85+
green * 255, // Same for green
86+
blue * 255, // Same for blue
7387
light.getPosition().getX(),
7488
light.getPosition().getY(),
7589
light.getPosition().getZ());

src/main/java/engine/processing/ProcessingTexture.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import engine.resources.FilterMode;
44
import engine.resources.Texture;
5+
import engine.resources.TextureWrapMode;
56
import processing.core.PImage;
67

78
public class ProcessingTexture implements Texture {
@@ -10,9 +11,12 @@ public class ProcessingTexture implements Texture {
1011

1112
private FilterMode filterMode;
1213

14+
private TextureWrapMode textureWrapMode;
15+
1316
public ProcessingTexture(PImage image) {
1417
this.image = image;
1518
this.filterMode = FilterMode.BILINEAR;
19+
this.textureWrapMode = TextureWrapMode.CLAMP;
1620
}
1721

1822
@Override
@@ -61,6 +65,16 @@ public void setFilterMode(FilterMode filterMode) {
6165
this.filterMode = filterMode;
6266
}
6367

68+
@Override
69+
public TextureWrapMode getTextureWrapMode() {
70+
return textureWrapMode;
71+
}
72+
73+
@Override
74+
public void setTextureWrapMode(TextureWrapMode textureWrapMode) {
75+
this.textureWrapMode = textureWrapMode;
76+
}
77+
6478
@Override
6579
public Texture getBackendTexture() {
6680
return this;

src/main/java/engine/resources/Texture.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ public interface Texture {
5555
*/
5656
void setFilterMode(FilterMode filterMode);
5757

58+
/**
59+
* Gets the current texture wrapping mode.
60+
*
61+
* <p>The texture wrap mode determines how the texture is applied when texture coordinates exceed
62+
* the [0, 1] range. For example, in {@link TextureWrapMode#REPEAT}, the texture will repeat,
63+
* whereas in {@link TextureWrapMode#CLAMP}, the texture will extend the edge pixels.
64+
*
65+
* @return the {@link TextureWrapMode} currently applied to the texture.
66+
*/
67+
TextureWrapMode getTextureWrapMode();
68+
69+
/**
70+
* Sets the texture wrapping mode.
71+
*
72+
* <p>This method controls how the texture is mapped outside the standard [0, 1] texture
73+
* coordinate range. Use {@link TextureWrapMode#REPEAT} to tile the texture across a surface, or
74+
* {@link TextureWrapMode#CLAMP} to stretch the texture's edge pixels when coordinates exceed the
75+
* valid range.
76+
*
77+
* @param textureWrapMode the new {@link TextureWrapMode} to apply to the texture.
78+
*/
79+
void setTextureWrapMode(TextureWrapMode textureWrapMode);
80+
5881
/**
5982
* Gets the underlying backend texture implementation. This is useful for accessing
6083
* engine-specific or platform-specific features.

0 commit comments

Comments
 (0)