(was unsure of where to post a c# question, so i came here)
ive never learned c#, but im trying to learn a little by converting some gdscript code i made into c#, and im running into a weird issue that i just do not understand. the output of the gdscript code (first image) is correct, but the c# output (second image) continuously shows the wrong values
the size of the blocks array is the same (64) in both scripts
(apologies for the probably very messy c#. like i said before, this is my first time trying to use it)
gscript code:
func _ready() -> void:
blocks.resize(Global.chunk_size ** 3)
print(get_block_pos(2))
func get_block_pos(index : int) -> Vector3:
var chunksize_minus1 : int = round(pow(blocks.size(), 1.0/3.0) - 1.0)
var chunksize_bitwize_y : int = roundi(log(chunksize_minus1) / log(2.0))
var chunksize_bitwise_z : int = roundi(chunksize_bitwize_y * 2.0)
var blockpos : Vector3 = Vector3(index & chunksize_minus1, (index >> chunksize_bitwize_y) & chunksize_minus1, (index >> chunksize_bitwise_z) & chunksize_minus1)
return blockpos
c# code:
public override void _Ready()
{
blocks.Resize((int)Math.Pow(chunk_size, 3));
GD.Print(get_block_pos(2));
}
public Vector3 get_block_pos(int index)
{
Vector3 blockpos = new Vector3(0, 0, 0);
int chunksize_minus1 = (int)Mathf.Pow(blocks.Count, 1.0f / 3.0f);
int chunksize_bitwise_y = (int)(Math.Log(chunksize_minus1) / Math.Log(2));
int chunksize_bitwise_z = chunksize_bitwise_y * 2;
blockpos.X = index & chunksize_minus1;
blockpos.Y = (index >> chunksize_bitwise_y) & chunksize_minus1;
blockpos.Z = (index >> chunksize_bitwise_z) & chunksize_minus1;
return blockpos;
}