On 16/03/2014 at 07:12, xxxxxxxx wrote:
Well, that is a little bit tricky, it took me a while to figure it out how to set the normal vectors at the normaltag.
Here are my utility functions for setting them (you have to implement similar functions for getting them.
def float2bytes(f) :
int_value = int(math.fabs(f * 32000.0))
high_byte = int(int_value / 256)
low_byte = int_value - 256 * high_byte
if f < 0:
high_byte = 255-high_byte
low_byte = 255-low_byte
return (low_byte,high_byte)
def set_normals(normal_tag,polygon,normal_a,normal_b,normal_c,normal_d) :
normal_list = [normal_a,normal_b,normal_c,normal_d]
normal_buffer = normal_tag.GetLowlevelDataAddressW()
vector_size = 6
component_size = 2
for v in range(0,4) :
normal = normal_list[v]
for c in range(0,3) :
low_byte, high_byte = float2bytes(normal[c])
normal_buffer[normal_tag.GetDataSize()*polygon+v*vector_size+c*component_size+0] = chr(low_byte)
normal_buffer[normal_tag.GetDataSize()*polygon+v*vector_size+c*component_size+1] = chr(high_byte)