Renamed members to differentiate between encoded and decoded values.
This commit is contained in:
		| @@ -47,19 +47,16 @@ namespace PolyVox | ||||
|  | ||||
| 		// Each component of the position is stored as a single unsigned byte. | ||||
| 		// The true position is found by offseting each component by 0.5f. | ||||
| 		Vector3DUint8 position; | ||||
|  | ||||
| 		// Currently unused and just serves as passing | ||||
| 		uint8_t unused; | ||||
| 		Vector3DUint8 encodedPosition; | ||||
|  | ||||
| 		// User data | ||||
| 		DataType data; | ||||
| 	}; | ||||
|  | ||||
| 	/// Decodes a position from a CubicVertex | ||||
| 	inline Vector3DFloat decode(const Vector3DUint8& position) | ||||
| 	inline Vector3DFloat decode(const Vector3DUint8& encodedPosition) | ||||
| 	{ | ||||
| 		Vector3DFloat result(position.getX(), position.getY(), position.getZ()); | ||||
| 		Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ()); | ||||
| 		result -= 0.5f; // Apply the required offset | ||||
| 		return result; | ||||
| 	} | ||||
| @@ -69,7 +66,7 @@ namespace PolyVox | ||||
| 	Vertex<DataType> decode(const CubicVertex<DataType>& cubicVertex) | ||||
| 	{ | ||||
| 		Vertex<DataType> result; | ||||
| 		result.position = decode(cubicVertex.position); | ||||
| 		result.position = decode(cubicVertex.encodedPosition); | ||||
| 		result.normal.setElements(0.0f, 0.0f, 0.0f); // Currently not calculated | ||||
| 		result.data = cubicVertex.data; // Data is not encoded | ||||
| 		return result; | ||||
|   | ||||
| @@ -221,7 +221,7 @@ namespace PolyVox | ||||
| 			{ | ||||
| 				//No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them. | ||||
| 				CubicVertex<typename VolumeType::VoxelType> cubicVertex; | ||||
| 				cubicVertex.position.setElements(static_cast<uint8_t>(uX), static_cast<uint8_t>(uY), static_cast<uint8_t>(uZ)); | ||||
| 				cubicVertex.encodedPosition.setElements(static_cast<uint8_t>(uX), static_cast<uint8_t>(uY), static_cast<uint8_t>(uZ)); | ||||
| 				cubicVertex.data = uMaterialIn; | ||||
| 				rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex); | ||||
| 				rEntry.uMaterial = uMaterialIn; | ||||
|   | ||||
| @@ -45,32 +45,32 @@ namespace PolyVox | ||||
| 		typedef _DataType DataType; | ||||
|  | ||||
| 		// Each component of the position is stored using 8.8 fixed-point encoding. | ||||
| 		Vector3DUint16 position; | ||||
| 		Vector3DUint16 encodedPosition; | ||||
|  | ||||
| 		// Each component of the normal is encoded using 5 bits of this variable. | ||||
| 		// The 16 bits are -xxxxxyyyyyzzzzz (note the left-most bit is currently  | ||||
| 		// unused). Some extra shifting and scaling is required to make it signed. | ||||
| 		uint16_t normal; | ||||
| 		uint16_t encodedNormal; | ||||
|  | ||||
| 		// User data | ||||
| 		DataType data; | ||||
| 	}; | ||||
|  | ||||
| 	/// Decodes a position from a MarchingCubesVertex | ||||
| 	inline Vector3DFloat decode(const Vector3DUint16& position) | ||||
| 	inline Vector3DFloat decode(const Vector3DUint16& encodedPosition) | ||||
| 	{ | ||||
| 		Vector3DFloat result(position.getX(), position.getY(), position.getZ()); | ||||
| 		Vector3DFloat result(encodedPosition.getX(), encodedPosition.getY(), encodedPosition.getZ()); | ||||
| 		result *= (1.0f / 256.0f); // Division is compile-time constant | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
| 	/// Decodes a normal from a MarchingCubesVertex | ||||
| 	inline Vector3DFloat decode(const uint16_t normal) | ||||
| 	inline Vector3DFloat decode(const uint16_t encodedNormal) | ||||
| 	{ | ||||
| 		// Get normal components in the range 0 to 31 | ||||
| 		uint16_t x = (normal >> 10) & 0x1F; | ||||
| 		uint16_t y = (normal >> 5) & 0x1F; | ||||
| 		uint16_t z = (normal) & 0x1F; | ||||
| 		uint16_t x = (encodedNormal >> 10) & 0x1F; | ||||
| 		uint16_t y = (encodedNormal >> 5) & 0x1F; | ||||
| 		uint16_t z = (encodedNormal) & 0x1F; | ||||
|  | ||||
| 		// Build the resulting vector | ||||
| 		Vector3DFloat result(x, y, z); | ||||
| @@ -89,8 +89,8 @@ namespace PolyVox | ||||
| 	Vertex<DataType> decode(const MarchingCubesVertex<DataType>& marchingCubesVertex) | ||||
| 	{ | ||||
| 		Vertex<DataType> result; | ||||
| 		result.position = decode(marchingCubesVertex.position); | ||||
| 		result.normal = decode(marchingCubesVertex.normal); | ||||
| 		result.position = decode(marchingCubesVertex.encodedPosition); | ||||
| 		result.normal = decode(marchingCubesVertex.encodedNormal); | ||||
| 		result.data = marchingCubesVertex.data; // Data is not encoded | ||||
| 		return result; | ||||
| 	} | ||||
|   | ||||
| @@ -470,8 +470,8 @@ namespace PolyVox | ||||
| 					const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp); | ||||
|  | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dScaledPosition; | ||||
| 					surfaceVertex.normal = encodedNormal; | ||||
| 					surfaceVertex.encodedPosition = v3dScaledPosition; | ||||
| 					surfaceVertex.encodedNormal = encodedNormal; | ||||
| 					surfaceVertex.data = uMaterial; | ||||
|  | ||||
| 					const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| @@ -513,8 +513,8 @@ namespace PolyVox | ||||
| 					const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v010, fInterp); | ||||
|  | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dScaledPosition; | ||||
| 					surfaceVertex.normal = encodedNormal; | ||||
| 					surfaceVertex.encodedPosition = v3dScaledPosition; | ||||
| 					surfaceVertex.encodedNormal = encodedNormal; | ||||
| 					surfaceVertex.data = uMaterial; | ||||
|  | ||||
| 					uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| @@ -555,8 +555,8 @@ namespace PolyVox | ||||
| 					const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v001, fInterp); | ||||
|  | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dScaledPosition; | ||||
| 					surfaceVertex.normal = encodedNormal; | ||||
| 					surfaceVertex.encodedPosition = v3dScaledPosition; | ||||
| 					surfaceVertex.encodedNormal = encodedNormal; | ||||
| 					surfaceVertex.data = uMaterial; | ||||
|  | ||||
| 					const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user