Improvements my frien
This commit is contained in:
@@ -133,7 +133,7 @@ world_to_screen :: (camera: Camera, world_position: Vector3) -> Vector3 {
|
||||
return screen_position;
|
||||
}
|
||||
|
||||
screen_to_world :: (camera: Camera, screen_position: Vector2) -> Vector3 {
|
||||
screen_to_world :: (camera: Camera, screen_position: Vector2, distance: float) -> Vector3 {
|
||||
pos : Vector4;
|
||||
pos.x = (screen_position.x / cast(float)engine.renderer.render_target_width) * 2.0 - 1.0;
|
||||
pos.y = (screen_position.y / cast(float)engine.renderer.render_target_height) * 2.0 - 1.0;
|
||||
@@ -145,10 +145,18 @@ screen_to_world :: (camera: Camera, screen_position: Vector2) -> Vector3 {
|
||||
result.y /= result.w;
|
||||
result.z /= result.w;
|
||||
|
||||
// Calculate world direction by subtracting camera position and normalizing
|
||||
direction : Vector3;
|
||||
direction.x = result.x - camera.position.x;
|
||||
direction.y = result.y - camera.position.y;
|
||||
direction.z = result.z - camera.position.z;
|
||||
direction = normalize(direction);
|
||||
|
||||
// Scale the direction to the specified distance
|
||||
world_position : Vector3;
|
||||
world_position.x = result.x;
|
||||
world_position.y = result.y;
|
||||
world_position.z = result.z;
|
||||
world_position.x = camera.position.x + direction.x * distance;
|
||||
world_position.y = camera.position.y + direction.y * distance;
|
||||
world_position.z = camera.position.z + direction.z * distance;
|
||||
|
||||
return world_position;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user