Working on umbrella rendering
This commit is contained in:
parent
614822d464
commit
4e511ed395
35
game/dist/assets/env/env_umbrella/env_umbrellaBlue.json
vendored
Normal file
35
game/dist/assets/env/env_umbrella/env_umbrellaBlue.json
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "env_umbrellaBlue",
|
||||||
|
"bottom_texture": {
|
||||||
|
"file_path": "assets/env/env_umbrella/env_umbrellaPole.png"
|
||||||
|
},
|
||||||
|
"top_texture": {
|
||||||
|
"file_path": "assets/env/env_umbrella/env_umbrellaBlue.png"
|
||||||
|
},
|
||||||
|
"footprint":[
|
||||||
|
{
|
||||||
|
"position": [
|
||||||
|
-108,
|
||||||
|
-108
|
||||||
|
],
|
||||||
|
"size": [
|
||||||
|
216,
|
||||||
|
216
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"visualization_radius": 256.0,
|
||||||
|
"physics_colliders": [
|
||||||
|
{
|
||||||
|
"position": [
|
||||||
|
-3,
|
||||||
|
-3
|
||||||
|
],
|
||||||
|
"size": [
|
||||||
|
6,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"temperature": 3.0
|
||||||
|
}
|
35
game/dist/assets/env/env_umbrella/env_umbrellaBlueTowels.json
vendored
Normal file
35
game/dist/assets/env/env_umbrella/env_umbrellaBlueTowels.json
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "env_umbrellaBlueTowels",
|
||||||
|
"bottom_texture": {
|
||||||
|
"file_path": "assets/env/env_umbrella/env_umbrellaTowels.png"
|
||||||
|
},
|
||||||
|
"top_texture": {
|
||||||
|
"file_path": "assets/env/env_umbrella/env_umbrellaBlue.png"
|
||||||
|
},
|
||||||
|
"footprint":[
|
||||||
|
{
|
||||||
|
"position": [
|
||||||
|
-108,
|
||||||
|
-108
|
||||||
|
],
|
||||||
|
"size": [
|
||||||
|
216,
|
||||||
|
216
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"visualization_radius": 256.0,
|
||||||
|
"physics_colliders": [
|
||||||
|
{
|
||||||
|
"position": [
|
||||||
|
-3,
|
||||||
|
-3
|
||||||
|
],
|
||||||
|
"size": [
|
||||||
|
6,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"temperature": 3.0
|
||||||
|
}
|
9
game/dist/map_gameMap.objects.json
vendored
9
game/dist/map_gameMap.objects.json
vendored
@ -1,11 +1,12 @@
|
|||||||
[
|
[
|
||||||
|
|
||||||
{
|
{
|
||||||
"type": "env",
|
"type": "env",
|
||||||
"name": "env_testObject",
|
"name": "env_umbrella",
|
||||||
|
"variant": "Blue",
|
||||||
"position": [
|
"position": [
|
||||||
0,
|
1,0
|
||||||
0
|
|
||||||
],
|
],
|
||||||
"rotation_radians": 0.5
|
"rotation_degrees": 90
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -58,10 +58,24 @@ pub struct WorldObjectRef {
|
|||||||
pub kind: String,
|
pub kind: String,
|
||||||
/// Object name
|
/// Object name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
/// Variant name
|
||||||
|
pub variant: Option<String>,
|
||||||
/// Object position (tile-space *not* pixel-space). 1,1 being up and to the right
|
/// Object position (tile-space *not* pixel-space). 1,1 being up and to the right
|
||||||
pub position: na::Vector2<f32>,
|
position: na::Vector2<f32>,
|
||||||
/// Object rotation, positive is clockwise
|
/// Object rotation, positive is clockwise
|
||||||
pub rotation_radians: f32,
|
pub rotation_degrees: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WorldObjectRef {
|
||||||
|
pub fn into_key(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"{}:{}:{}",
|
||||||
|
self.kind,
|
||||||
|
self.name,
|
||||||
|
self.variant.as_ref().unwrap_or(&"default".to_string())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
pub fn get_world_space_position(&self)-> na::Vector2<f32> {
|
||||||
|
self.position * 2.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -54,12 +54,15 @@ impl WorldObjectPackage {
|
|||||||
let mut world_space_colliders: Vec<WorldSpaceObjectCollider> = Vec::new();
|
let mut world_space_colliders: Vec<WorldSpaceObjectCollider> = Vec::new();
|
||||||
for reference in &object_references {
|
for reference in &object_references {
|
||||||
// If this is a new object, load it.
|
// If this is a new object, load it.
|
||||||
let object_key = format!("{}:{}", reference.kind, reference.name);
|
let object_key = reference.into_key();
|
||||||
if !object_definitions.contains_key(object_key.as_str()) {
|
if !object_definitions.contains_key(object_key.as_str()) {
|
||||||
// Construct the file path from the data we know about the reference
|
// Construct the file path from the data we know about the reference
|
||||||
let path = format!(
|
let path = format!(
|
||||||
"assets/{}/{}/{}.json",
|
"assets/{}/{}/{}{}.json",
|
||||||
reference.kind, reference.name, reference.name
|
reference.kind,
|
||||||
|
reference.name,
|
||||||
|
reference.name,
|
||||||
|
reference.variant.as_ref().unwrap_or(&String::new())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Attempt to load the object definition
|
// Attempt to load the object definition
|
||||||
@ -100,7 +103,7 @@ impl WorldObjectPackage {
|
|||||||
// Keep track of all the colliders in the world
|
// Keep track of all the colliders in the world
|
||||||
for collider in &object_definition.physics_colliders {
|
for collider in &object_definition.physics_colliders {
|
||||||
// Get the object's position
|
// Get the object's position
|
||||||
let object_position = reference.position;
|
let object_position = reference.get_world_space_position();
|
||||||
|
|
||||||
// Convert the collider's position to world space
|
// Convert the collider's position to world space
|
||||||
let world_space_collider = WorldSpaceObjectCollider {
|
let world_space_collider = WorldSpaceObjectCollider {
|
||||||
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
asset_manager::{load_texture_from_internal_data, InternalData},
|
asset_manager::{load_texture_from_internal_data, InternalData},
|
||||||
model::{world_object_package::WorldObjectPackage, world_object::WorldSpaceObjectCollider},
|
model::{world_object::WorldSpaceObjectCollider, world_object_package::WorldObjectPackage},
|
||||||
};
|
};
|
||||||
use nalgebra as na;
|
use nalgebra as na;
|
||||||
use raylib::{
|
use raylib::{
|
||||||
@ -148,11 +148,11 @@ impl MapRenderer {
|
|||||||
|
|
||||||
// If there is an object here, let it override the output
|
// If there is an object here, let it override the output
|
||||||
for obj_ref in &self.world_objects.object_references {
|
for obj_ref in &self.world_objects.object_references {
|
||||||
if obj_ref.position.x == tile_position.x as f32
|
if obj_ref.get_world_space_position().x == tile_position.x as f32
|
||||||
&& obj_ref.position.y == tile_position.y as f32
|
&& obj_ref.get_world_space_position().y == tile_position.y as f32
|
||||||
{
|
{
|
||||||
// Get access to the actual object definition
|
// Get access to the actual object definition
|
||||||
let object_key = format!("{}:{}", obj_ref.kind, obj_ref.name);
|
let object_key = obj_ref.into_key();
|
||||||
let obj_def = self
|
let obj_def = self
|
||||||
.world_objects
|
.world_objects
|
||||||
.object_definitions
|
.object_definitions
|
||||||
@ -203,11 +203,11 @@ impl MapRenderer {
|
|||||||
|
|
||||||
// If there is an object here, let it override the output
|
// If there is an object here, let it override the output
|
||||||
for obj_ref in &self.world_objects.object_references {
|
for obj_ref in &self.world_objects.object_references {
|
||||||
if obj_ref.position.x == tile_position.x as f32
|
if obj_ref.get_world_space_position().x == tile_position.x as f32
|
||||||
&& obj_ref.position.y == tile_position.y as f32
|
&& obj_ref.get_world_space_position().y == tile_position.y as f32
|
||||||
{
|
{
|
||||||
// Get access to the actual object definition
|
// Get access to the actual object definition
|
||||||
let object_key = format!("{}:{}", obj_ref.kind, obj_ref.name);
|
let object_key = obj_ref.into_key();
|
||||||
let obj_def = self
|
let obj_def = self
|
||||||
.world_objects
|
.world_objects
|
||||||
.object_definitions
|
.object_definitions
|
||||||
@ -319,12 +319,12 @@ impl MapRenderer {
|
|||||||
|
|
||||||
// Check if there is an object at this tile
|
// Check if there is an object at this tile
|
||||||
for obj_ref in &self.world_objects.object_references {
|
for obj_ref in &self.world_objects.object_references {
|
||||||
if obj_ref.position.x == sampler_x as f32
|
if obj_ref.get_world_space_position().x == sampler_x as f32
|
||||||
&& obj_ref.position.y == sampler_y as f32
|
&& obj_ref.get_world_space_position().y == sampler_y as f32
|
||||||
{
|
{
|
||||||
// Get access to the actual object definition
|
// Get access to the actual object definition
|
||||||
let object_key =
|
let object_key = obj_ref.into_key();
|
||||||
format!("{}:{}", obj_ref.kind, obj_ref.name);
|
debug!("Found object: {}", object_key);
|
||||||
let obj_def = self
|
let obj_def = self
|
||||||
.world_objects
|
.world_objects
|
||||||
.object_definitions
|
.object_definitions
|
||||||
@ -340,10 +340,10 @@ impl MapRenderer {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
tex.render_automatic(
|
tex.render_automatic(
|
||||||
draw_handle,
|
draw_handle,
|
||||||
obj_ref.position - (tex.size() / 2.0),
|
obj_ref.get_world_space_position() - (tex.size() / 2.0),
|
||||||
None,
|
None,
|
||||||
Some(tex.size() / 2.0),
|
Some(tex.size() / 2.0),
|
||||||
Some(obj_ref.rotation_radians.to_degrees()),
|
Some(obj_ref.rotation_degrees),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -352,7 +352,7 @@ impl MapRenderer {
|
|||||||
.bottom_static_textures
|
.bottom_static_textures
|
||||||
.get_mut(&object_key)
|
.get_mut(&object_key)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let p: Vector2 = obj_ref.position.into();
|
let p: Vector2 = obj_ref.get_world_space_position().into();
|
||||||
let r1 = Rectangle {
|
let r1 = Rectangle {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
@ -374,7 +374,7 @@ impl MapRenderer {
|
|||||||
tex.width as f32 / 2.0,
|
tex.width as f32 / 2.0,
|
||||||
tex.height as f32 / 2.0,
|
tex.height as f32 / 2.0,
|
||||||
),
|
),
|
||||||
obj_ref.rotation_radians.to_degrees(),
|
obj_ref.rotation_degrees,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ impl MapRenderer {
|
|||||||
obj_def.visualization_radius
|
obj_def.visualization_radius
|
||||||
{
|
{
|
||||||
let player_dist_to_object =
|
let player_dist_to_object =
|
||||||
(obj_ref.position - player_position).norm();
|
(obj_ref.get_world_space_position() - player_position).norm();
|
||||||
// debug!(
|
// debug!(
|
||||||
// "Player dist to object: {}",
|
// "Player dist to object: {}",
|
||||||
// player_dist_to_object
|
// player_dist_to_object
|
||||||
@ -405,10 +405,10 @@ impl MapRenderer {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
tex.render_automatic(
|
tex.render_automatic(
|
||||||
draw_handle,
|
draw_handle,
|
||||||
obj_ref.position - (tex.size() / 2.0),
|
obj_ref.get_world_space_position() - (tex.size() / 2.0),
|
||||||
None,
|
None,
|
||||||
Some(tex.size() / 2.0),
|
Some(tex.size() / 2.0),
|
||||||
Some(obj_ref.rotation_radians.to_degrees()),
|
Some(obj_ref.rotation_degrees),
|
||||||
Some(tint),
|
Some(tint),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -417,7 +417,7 @@ impl MapRenderer {
|
|||||||
.top_static_textures
|
.top_static_textures
|
||||||
.get_mut(&object_key)
|
.get_mut(&object_key)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let p: Vector2 = obj_ref.position.into();
|
let p: Vector2 = obj_ref.get_world_space_position().into();
|
||||||
let r1 = Rectangle {
|
let r1 = Rectangle {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
@ -439,7 +439,7 @@ impl MapRenderer {
|
|||||||
tex.width as f32 / 2.0,
|
tex.width as f32 / 2.0,
|
||||||
tex.height as f32 / 2.0,
|
tex.height as f32 / 2.0,
|
||||||
),
|
),
|
||||||
obj_ref.rotation_radians.to_degrees(),
|
obj_ref.rotation_degrees,
|
||||||
tint,
|
tint,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -500,7 +500,7 @@ impl MapRenderer {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// // Get the object definition
|
// // Get the object definition
|
||||||
// let object_key = format!("{}:{}", obj_ref.kind, obj_ref.name);
|
// let object_key = obj_ref.into_key();
|
||||||
// let obj_def = self
|
// let obj_def = self
|
||||||
// .world_objects
|
// .world_objects
|
||||||
// .object_definitions
|
// .object_definitions
|
||||||
@ -543,6 +543,4 @@ impl MapRenderer {
|
|||||||
// // If we got here, the player is not in a collision zone
|
// // If we got here, the player is not in a collision zone
|
||||||
// player_velocity
|
// player_velocity
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user