🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++, Local to World Geometry Transformation

Started by
1 comment, last by arnero 4 years, 5 months ago

Good Afternoon,

I have a quick question about an efficient way of storing world transformation vertices.

So far, I do something like this

class GeometryObject{
public:

	const std::vector<Vec2f> & GetTransformed()const{
		return m_transformed; 
	}
	
	void Transform(const Mat3& l_matrix){
		for(all verts in model){
			m_transformed[i] = l_matrix * m_local[i];
 		}
	}

private:

	std::vector<Vec2> m_local; //local verts not affected by translation, rotation etc.
	std::vector<Vec2> m_transformed; //transformed verts affected by translate, rotation etc. 

};

This has always felt like a huge waste of memory because I am doubleing the amount of vert data stored in an object.

The reference keeps me from making a copy however so it should be faster than simply returning a new copy of std::vector<Vec2> every time I need world data.

So my question is: Is there a more efficient way to transform data? I would also like to make this extensible to 3d where a mesh might have thounsands of triangles.

Thanks so much for the help.

Mike

Advertisement

If you want to optimize prematurely, you could also just use OpenGl. I am just learning WebGL. It seems to cater to some limitations in hardware of the last century. Still it seems that it wants you define a matrix, which is global for the mesh, and then let the GPU transform the vertices on the fly every frame. Next mesh, next matrix.

Per mesh = “uniform”
inside the forEach loop = “attribute”

What a strange language..

This topic is closed to new replies.

Advertisement