我有Python代码和C代码的结构。我填这些字段
("bones_pos_vect",((c_float*4)*30)),
("bones_rot_quat",((c_float*4)*30))
在python代码中使用正确的值,但是当我用C代码请求它们时,我从所有数组单元格中只能得到0.0。为什么我会失去价值观?我所有其他领域的结构工作良好。
class SceneObject(Structure):
_fields_ = [("x_coord", c_float),
("y_coord", c_float),
("z_coord", c_float),
("x_angle", c_float),
("y_angle", c_float),
("z_angle", c_float),
("indexes_count", c_int),
("vertices_buffer", c_uint),
("indexes_buffer", c_uint),
("texture_buffer", c_uint),
("bones_pos_vect",((c_float*4)*30)),
("bones_rot_quat",((c_float*4)*30))]
typedef struct
{
float x_coord;
float y_coord;
float z_coord;
float x_angle;
float y_angle;
float z_angle;
int indexes_count;
unsigned int vertices_buffer;
unsigned int indexes_buffer;
unsigned int texture_buffer;
float bones_pos_vect[30][4];
float bones_rot_quat[30][4];
} SceneObject;
下面是一个如何将多维数组与Python和ctypes结合使用的示例。
我编写了下面的C代码,并使用MinGW中的
gcc
将其编译为slib.dll
:请注意,该结构包含一个“二维”数组。
然后,我编写了以下Python脚本:
当我运行Python脚本时,它调用了C函数,该函数输出多维数组的内容:
我使用了Python2,而您问题上的标记表明您正在使用Python3。不过,我不认为这会有什么不同。
相关问题 更多 >
编程相关推荐