Hi all,
I am writing a voxel engine and I require a function to perform a calculation to work out the centre of a cube. To that end I have this function in my UUBlock Class written in C++.
void UUBlock::Blockdata(AChunk* chunk, INT32 X, INT32 Y, INT32 Z, TArray<FMeshDataTriangle>& Triangles)
{
this->BlockCenter.X = (float)((float)X*chunk->BlockSize) + chunk->BlockSizeHalf;
this->BlockCenter.Y = (float)((float)Y*chunk->BlockSize) + chunk->BlockSizeHalf;
this->BlockCenter.Z = (float)((float)Z*chunk->BlockSize) + chunk->BlockSizeHalf;
.......
}
when I call this method with a know BlockSize and BlockSizeHalf and know my X, Y, Z parameters.
my BlockCenter.X / BlockCenter.Y & BlockCenter.Z or always 0
which is rubbish when I have X = 5, BlockSize = 100 & BlockSizeHalf = 50
in this case BlockCenter.X should be 550.
Can someone please Advise as I am having these issues in serveral places in my code I don’t understand why simple Maths isn’t working.
Thanks for any advise or pointers.