Преглед на файлове

Change algorithm to compute sprite's vertex positions

Daniele Bartolini преди 12 години
родител
ревизия
605a1ea23a
променени са 2 файла, в които са добавени 10 реда и са изтрити 10 реда
  1. 10 3
      engine/resource/SpriteResource.cpp
  2. 0 7
      engine/resource/SpriteResource.h

+ 10 - 3
engine/resource/SpriteResource.cpp

@@ -82,10 +82,16 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	JSONParser json(buf);
 	JSONElement root = json.root();
 
+	float width;
+	float height;
 	List<StringId32>		m_names(default_allocator());
 	List<FrameData> 		m_regions(default_allocator());
 	List<float>				m_vertices(default_allocator());
 
+	// Read width/height
+	width = root.key("width").float_value();
+	height = root.key("height").float_value();
+
 	// Read frames
 	JSONElement frames = root.key("frames");
 	uint32_t num_frames = frames.size();
@@ -104,9 +110,11 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 		float u1 = fd.x0 + fd.x1;
 		float v1 = fd.y0 + fd.y1;
 
+		float aspect = (fd.x1 * width) / (fd.y1 * height);
+
 		// Compute positions
-		float w = fd.x1;
-		float h = fd.y1;
+		float w = aspect;
+		float h = 1;
 
 		float x0 = fd.scale_x * (-w * 0.5) + fd.offset_x;
 		float y0 = fd.scale_y * (-h * 0.5) + fd.offset_y;
@@ -130,7 +138,6 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	default_allocator().deallocate(buf);
 
 	SpriteHeader h;
-	h.texture.id = hash::murmur2_64("textures/circle.texture", string::strlen("textures/circle.texture"), 0);
 	h.num_frames = m_names.size();
 
 	uint32_t offt = sizeof(SpriteHeader);

+ 0 - 7
engine/resource/SpriteResource.h

@@ -55,7 +55,6 @@ struct SpriteHeader
 {
 	VertexBufferId 	vb;
 	IndexBufferId 	ib;
-	ResourceId 		texture;
 	uint32_t 		num_frames;
 	uint32_t		frame_names_offset;
 	uint32_t		frame_vertices_offset;
@@ -109,12 +108,6 @@ struct SpriteResource
 		device()->renderer()->destroy_index_buffer(h->ib);
 	}
 
-	//-----------------------------------------------------------------------------
-	ResourceId texture() const
-	{
-		return ((SpriteHeader*) this)->texture;
-	}
-
 	//-----------------------------------------------------------------------------
 	uint32_t num_frames() const
 	{