Scaled vertices to always be integers.
This commit is contained in:
		
							
								
								
									
										25
									
								
								include/Constants.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								include/Constants.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | #ifndef __Constants_H__ | ||||||
|  | #define __Constants_H__ | ||||||
|  |  | ||||||
|  | namespace Ogre | ||||||
|  | { | ||||||
|  | 	//FIXME - i think we can define mod using a bitmask which flattens the upper bits. Should define that here. | ||||||
|  | 	const unsigned int OGRE_BLOCK_SIDE_LENGTH_POWER = 5; | ||||||
|  | 	const unsigned int OGRE_BLOCK_SIDE_LENGTH = (0x0001 << OGRE_BLOCK_SIDE_LENGTH_POWER); | ||||||
|  | 	const unsigned int OGRE_NO_OF_VOXELS_IN_BLOCK = (OGRE_BLOCK_SIDE_LENGTH * OGRE_BLOCK_SIDE_LENGTH * OGRE_BLOCK_SIDE_LENGTH); | ||||||
|  |  | ||||||
|  | 	const unsigned int OGRE_VOLUME_SIDE_LENGTH_POWER = 8; | ||||||
|  | 	const unsigned int OGRE_VOLUME_SIDE_LENGTH = (0x0001 << OGRE_VOLUME_SIDE_LENGTH_POWER); | ||||||
|  | 	const unsigned int OGRE_VOLUME_SIDE_LENGTH_IN_BLOCKS = (OGRE_VOLUME_SIDE_LENGTH >> OGRE_BLOCK_SIDE_LENGTH_POWER); | ||||||
|  | 	const unsigned int OGRE_NO_OF_BLOCKS_IN_VOLUME = (OGRE_VOLUME_SIDE_LENGTH_IN_BLOCKS * OGRE_VOLUME_SIDE_LENGTH_IN_BLOCKS * OGRE_VOLUME_SIDE_LENGTH_IN_BLOCKS); | ||||||
|  | 	const unsigned int OGRE_NO_OF_VOXELS_IN_VOLUME = (OGRE_VOLUME_SIDE_LENGTH * OGRE_VOLUME_SIDE_LENGTH * OGRE_VOLUME_SIDE_LENGTH); | ||||||
|  |  | ||||||
|  | 	const unsigned int OGRE_REGION_SIDE_LENGTH_POWER = 4; | ||||||
|  | 	const unsigned int OGRE_REGION_SIDE_LENGTH = (0x0001 << OGRE_REGION_SIDE_LENGTH_POWER); | ||||||
|  | 	const unsigned int OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS = (OGRE_VOLUME_SIDE_LENGTH >> OGRE_REGION_SIDE_LENGTH_POWER); | ||||||
|  | 	const unsigned int OGRE_NO_OF_REGIONS_IN_VOLUME = (OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS * OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS * OGRE_VOLUME_SIDE_LENGTH_IN_REGIONS); | ||||||
|  |  | ||||||
|  | 	const unsigned long OGRE_MAX_VOXELS_TO_BURN_PER_FRAME = 1000; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #endif | ||||||
| @@ -44,6 +44,10 @@ namespace Ogre | |||||||
|  |  | ||||||
| 	void SurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2) | 	void SurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2) | ||||||
| 	{ | 	{ | ||||||
|  | 		m_uTrianglesAdded++; | ||||||
|  |  | ||||||
|  | 		m_uVerticesAdded += 3; | ||||||
|  |  | ||||||
| 		/*m_vecVertexData.push_back(v0); | 		/*m_vecVertexData.push_back(v0); | ||||||
| 		m_vecIndexData.push_back(m_vecVertexData.size()-1); | 		m_vecIndexData.push_back(m_vecVertexData.size()-1); | ||||||
| 		m_vecVertexData.push_back(v1); | 		m_vecVertexData.push_back(v1); | ||||||
| @@ -51,13 +55,7 @@ namespace Ogre | |||||||
| 		m_vecVertexData.push_back(v2); | 		m_vecVertexData.push_back(v2); | ||||||
| 		m_vecIndexData.push_back(m_vecVertexData.size()-1);*/ | 		m_vecIndexData.push_back(m_vecVertexData.size()-1);*/ | ||||||
|  |  | ||||||
| 		m_uTrianglesAdded++; | 		/*long int index; | ||||||
|  |  | ||||||
| 		m_uVerticesAdded += 3; |  | ||||||
|  |  | ||||||
| 		SurfaceTriangle triangle; |  | ||||||
|  |  | ||||||
| 		long int index; |  | ||||||
| 		//If a vertex has not yet been added, it's index is -1 | 		//If a vertex has not yet been added, it's index is -1 | ||||||
| 		index = vertexIndices[(v0.position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (v0.position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (v0.position.z)]; | 		index = vertexIndices[(v0.position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (v0.position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (v0.position.z)]; | ||||||
| 		if((index == -1)) | 		if((index == -1)) | ||||||
| @@ -101,20 +99,19 @@ namespace Ogre | |||||||
| 		{ | 		{ | ||||||
| 			//Just reuse the existing vertex | 			//Just reuse the existing vertex | ||||||
| 			m_vecIndexData.push_back(index); | 			m_vecIndexData.push_back(index); | ||||||
| 		} | 		}*/ | ||||||
|  |  | ||||||
|  | 		SurfaceTriangle triangle; | ||||||
|  |  | ||||||
|  | 		triangle.v0 = m_setVertices.insert(v0).first;		 | ||||||
|  | 		triangle.v1 = m_setVertices.insert(v1).first; | ||||||
|  | 		triangle.v2 = m_setVertices.insert(v2).first; | ||||||
|  |  | ||||||
|  | 		/*triangle.v0 = std::find(m_setVertices.begin(), m_setVertices.end(), v0); | ||||||
| 		/*m_setVertices.insert(v0);		 |  | ||||||
| 		m_setVertices.insert(v1); |  | ||||||
| 		m_setVertices.insert(v2); |  | ||||||
|  |  | ||||||
| 		triangle.v0 = std::find(m_setVertices.begin(), m_setVertices.end(), v0); |  | ||||||
| 		triangle.v1 = std::find(m_setVertices.begin(), m_setVertices.end(), v1); | 		triangle.v1 = std::find(m_setVertices.begin(), m_setVertices.end(), v1); | ||||||
| 		triangle.v2 = std::find(m_setVertices.begin(), m_setVertices.end(), v2);*/			 | 		triangle.v2 = std::find(m_setVertices.begin(), m_setVertices.end(), v2);	*/		 | ||||||
|  |  | ||||||
| 		//m_listTriangles.push_back(triangle); | 		m_listTriangles.push_back(triangle); | ||||||
|  |  | ||||||
| 		/*triangle.v0->listTrianglesUsingThisVertex.push_back(m_listTriangles.end()); | 		/*triangle.v0->listTrianglesUsingThisVertex.push_back(m_listTriangles.end()); | ||||||
| 		triangle.v1->listTrianglesUsingThisVertex.push_back(m_listTriangles.end()); | 		triangle.v1->listTrianglesUsingThisVertex.push_back(m_listTriangles.end()); | ||||||
| @@ -123,21 +120,22 @@ namespace Ogre | |||||||
|  |  | ||||||
| 	void SurfacePatch::getVertexAndIndexData(std::vector<SurfaceVertex>& vertexData, std::vector<uint>& indexData) | 	void SurfacePatch::getVertexAndIndexData(std::vector<SurfaceVertex>& vertexData, std::vector<uint>& indexData) | ||||||
| 	{ | 	{ | ||||||
| 		/*vertexData.clear(); | 		vertexData.clear(); | ||||||
| 		indexData.clear();*/ | 		indexData.clear(); | ||||||
|  |  | ||||||
| 		vertexData = m_vecVertexData; | 		/*vertexData = m_vecVertexData; | ||||||
| 		indexData = m_vecIndexData; | 		indexData = m_vecIndexData;*/ | ||||||
|  |  | ||||||
| 		return; | 		//return; | ||||||
| #ifdef BLAH |  | ||||||
|  |  | ||||||
| 		vertexData.resize(m_setVertices.size()); | 		vertexData.resize(m_setVertices.size()); | ||||||
| 		std::copy(m_setVertices.begin(), m_setVertices.end(), vertexData.begin()); | 		std::copy(m_setVertices.begin(), m_setVertices.end(), vertexData.begin()); | ||||||
|  |  | ||||||
| 		sort(vertexData.begin(),vertexData.end()); | 		//sort(vertexData.begin(),vertexData.end()); | ||||||
| 		//reverse(vertexData.begin(),vertexData.end()); | 		//reverse(vertexData.begin(),vertexData.end()); | ||||||
|  |  | ||||||
|  | 		//LogManager::getSingleton().logMessage("No of triangles = " + StringConverter::toString(m_listTriangles.size())); | ||||||
|  |  | ||||||
| 		for(std::list<SurfaceTriangle>::iterator iterTriangles = m_listTriangles.begin(); iterTriangles != m_listTriangles.end(); ++iterTriangles) | 		for(std::list<SurfaceTriangle>::iterator iterTriangles = m_listTriangles.begin(); iterTriangles != m_listTriangles.end(); ++iterTriangles) | ||||||
| 		{ | 		{ | ||||||
| 			/*vertexData.push_back(*(iterTriangles->v0)); | 			/*vertexData.push_back(*(iterTriangles->v0)); | ||||||
| @@ -145,7 +143,7 @@ namespace Ogre | |||||||
| 			vertexData.push_back(*(iterTriangles->v1)); | 			vertexData.push_back(*(iterTriangles->v1)); | ||||||
| 			indexData.push_back(vertexData.size()-1); | 			indexData.push_back(vertexData.size()-1); | ||||||
| 			vertexData.push_back(*(iterTriangles->v2)); | 			vertexData.push_back(*(iterTriangles->v2)); | ||||||
| 			indexData.push_back(vertexData.size()-1);*/		 | 			indexData.push_back(vertexData.size()-1);	*/	 | ||||||
|  |  | ||||||
| 			/*std::set<SurfaceVertex>::iterator iterVertex = m_setVertices.find((*(iterTriangles->v0))); | 			/*std::set<SurfaceVertex>::iterator iterVertex = m_setVertices.find((*(iterTriangles->v0))); | ||||||
| 			indexData.push_back(iterVertex - m_setVertices.begin()); | 			indexData.push_back(iterVertex - m_setVertices.begin()); | ||||||
| @@ -163,21 +161,21 @@ namespace Ogre | |||||||
| 				}				 | 				}				 | ||||||
| 			}*/ | 			}*/ | ||||||
|  |  | ||||||
| 			std::vector<SurfaceVertex>::iterator iterVertex = find(vertexData.begin(), vertexData.end(),(*(iterTriangles->v0))); | 			std::vector<SurfaceVertex>::iterator iterVertex = lower_bound(vertexData.begin(), vertexData.end(),(*(iterTriangles->v0))); | ||||||
| 			if(iterVertex == vertexData.end()) | 			if(iterVertex == vertexData.end()) | ||||||
| 			{ | 			{ | ||||||
| 				LogManager::getSingleton().logMessage("Vertex 0 Not Found"); | 				LogManager::getSingleton().logMessage("Vertex 0 Not Found"); | ||||||
| 			} | 			} | ||||||
| 			indexData.push_back(iterVertex - vertexData.begin()); | 			indexData.push_back(iterVertex - vertexData.begin()); | ||||||
|  |  | ||||||
| 			iterVertex = find(vertexData.begin(), vertexData.end(),(*(iterTriangles->v1))); | 			iterVertex = lower_bound(vertexData.begin(), vertexData.end(),(*(iterTriangles->v1))); | ||||||
| 			if(iterVertex == vertexData.end()) | 			if(iterVertex == vertexData.end()) | ||||||
| 			{ | 			{ | ||||||
| 				LogManager::getSingleton().logMessage("Vertex 1 Not Found"); | 				LogManager::getSingleton().logMessage("Vertex 1 Not Found"); | ||||||
| 			} | 			} | ||||||
| 			indexData.push_back(iterVertex - vertexData.begin()); | 			indexData.push_back(iterVertex - vertexData.begin()); | ||||||
|  |  | ||||||
| 			iterVertex = find(vertexData.begin(), vertexData.end(),(*(iterTriangles->v2))); | 			iterVertex = lower_bound(vertexData.begin(), vertexData.end(),(*(iterTriangles->v2))); | ||||||
| 			if(iterVertex == vertexData.end()) | 			if(iterVertex == vertexData.end()) | ||||||
| 			{ | 			{ | ||||||
| 				LogManager::getSingleton().logMessage("Vertex 2 Not Found"); | 				LogManager::getSingleton().logMessage("Vertex 2 Not Found"); | ||||||
| @@ -202,10 +200,10 @@ namespace Ogre | |||||||
| 				} | 				} | ||||||
| 			}*/ | 			}*/ | ||||||
| 		} | 		} | ||||||
|  | 		//LogManager::getSingleton().logMessage("Out of Loop"); | ||||||
|  |  | ||||||
| 		/*vertexData = m_vecVertexData; | 		/*vertexData = m_vecVertexData; | ||||||
| 		indexData = m_vecIndexData;*/ | 		indexData = m_vecIndexData;*/ | ||||||
|  |  | ||||||
| #endif |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
|  | #include "Constants.h" | ||||||
| #include "SurfaceVertex.h" | #include "SurfaceVertex.h" | ||||||
|  |  | ||||||
| namespace Ogre | namespace Ogre | ||||||
| @@ -22,32 +23,45 @@ namespace Ogre | |||||||
| 		//We dont't check the normal here as it may not have been set. But if two vertices have the same position they should have the same normal too. | 		//We dont't check the normal here as it may not have been set. But if two vertices have the same position they should have the same normal too. | ||||||
| 		/*return | 		/*return | ||||||
| 		( | 		( | ||||||
| 			(abs(position.x - rhs.position.x) <= 0.01) &&  | 			(position.x == rhs.position.x) &&  | ||||||
| 			(abs(position.y - rhs.position.y) <= 0.01) && | 			(position.y == rhs.position.y) &&  | ||||||
| 			(abs(position.z - rhs.position.z) <= 0.01) && | 			(position.z == rhs.position.z) //&&  | ||||||
| 			(abs(alpha - rhs.alpha) <= 0.01) | 			//(abs(alpha - rhs.alpha) <= 0.01) | ||||||
| 		);*/ | 		);*/ | ||||||
|  |  | ||||||
| 		return | 		/*ulong value = 0; | ||||||
| 		( | 		value |= position.x; | ||||||
| 			(position.x == rhs.position.x) &&  | 		value << 10; | ||||||
| 			(position.x == rhs.position.y) &&  | 		value |= position.y; | ||||||
| 			(position.x == rhs.position.z) &&  | 		value << 10; | ||||||
| 			(abs(alpha - rhs.alpha) <= 0.01) | 		value |= position.z; | ||||||
| 		); |  | ||||||
|  | 		ulong rhsValue = 0; | ||||||
|  | 		rhsValue |= rhs.position.x; | ||||||
|  | 		rhsValue << 10; | ||||||
|  | 		rhsValue |= rhs.position.y; | ||||||
|  | 		rhsValue << 10; | ||||||
|  | 		rhsValue |= rhs.position.z; | ||||||
|  |  | ||||||
|  | 		return value == rhsValue;*/ | ||||||
|  |  | ||||||
|  | 		unsigned long offset = (position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.z); | ||||||
|  | 		unsigned long rhsOffset = (rhs.position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.position.z); | ||||||
|  |  | ||||||
|  | 		return offset == rhsOffset; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	bool SurfaceVertex::operator < (const SurfaceVertex& rhs) const | 	bool SurfaceVertex::operator < (const SurfaceVertex& rhs) const | ||||||
| 	{ | 	{ | ||||||
| 		if((*this) == rhs) | 		/*if((*this) == rhs) | ||||||
| 		{ | 		{ | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 		if(alpha < rhs.alpha) | 		if(alpha < rhs.alpha) | ||||||
| 		{ | 		{ | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		}*/ | ||||||
| 		if(position.z < rhs.position.z) | 		/*if(position.z < rhs.position.z) | ||||||
| 		{ | 		{ | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| @@ -60,6 +74,27 @@ namespace Ogre | |||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		return false; | 		return false;*/ | ||||||
|  |  | ||||||
|  | 		/*ulong value = 0; | ||||||
|  | 		value |= position.x; | ||||||
|  | 		value << 10; | ||||||
|  | 		value |= position.y; | ||||||
|  | 		value << 10; | ||||||
|  | 		value |= position.z; | ||||||
|  |  | ||||||
|  | 		ulong rhsValue = 0; | ||||||
|  | 		rhsValue |= rhs.position.x; | ||||||
|  | 		rhsValue << 10; | ||||||
|  | 		rhsValue |= rhs.position.y; | ||||||
|  | 		rhsValue << 10; | ||||||
|  | 		rhsValue |= rhs.position.z; | ||||||
|  |  | ||||||
|  | 		return value < rhsValue;*/ | ||||||
|  |  | ||||||
|  | 		unsigned long offset = (position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (position.z); | ||||||
|  | 		unsigned long rhsOffset = (rhs.position.x*(OGRE_REGION_SIDE_LENGTH*2+1)*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.position.y*(OGRE_REGION_SIDE_LENGTH*2+1)) + (rhs.position.z); | ||||||
|  |  | ||||||
|  | 		return offset < rhsOffset; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user