V
VectorStudio
Guest
Hello, I decided to try if it's possible to work with the kinect in GameMaker: Studio. Everything's going fine, only a one problem showed up. I'm receiving data from my kinect sensor and handling it in GameMaker. I have position of each joint so I'm able to draw a basic skeleton by using primitives. Now I'm trying to cover the skeleton with 3D blocks. These blocks are drawn as 'bones' so one between two joints. But I don't know how to correctly rotate this blocks. I tryed it by tan fuction. It works but only sometimes. I mean that in one position the bones are rotated correctly but if I move they are rotated wrong.
Here is my code I'm using to draw a bone:
In this position it works:
But here it doesn't:
Here is my code I'm using to draw a bone:
Code:
/// DrawBone(from, to)
var from = argument[0];
var to = argument[1];
var fromX = pointX + GetJointX(from);
var fromY = pointY + GetJointY(from);
var fromZ = pointZ + GetJointZ(from);
var toX = pointX + GetJointX(to);
var toY = pointY + GetJointY(to);
var toZ = pointZ + GetJointZ(to);
var centerX = (fromX + toX) / 2;
var centerY = (fromY + toY) / 2;
var centerZ = (fromZ + toZ) / 2;
var length = point_distance_3d(fromX, fromY, fromZ, toX, toY, toZ);
var lengthX = abs(fromX - toX);
var lengthY = abs(fromY - toY);
var lengthZ = abs(fromZ - toZ);
var angleX = radtodeg(arctan(lengthX / lengthZ));
var angleZ = radtodeg(arctan(lengthX / lengthY));
draw_set_colour(c_black);
d3d_draw_block(fromX - .1, fromY - .1, fromZ - .1, fromX + .1, fromY + .1, fromZ + .1, -1, 1, 1);
d3d_draw_block(toX - .1, toY - .1, toZ - .1, toX + .1, toY + .1, toZ + .1, -1, 1, 1);
draw_set_colour(c_white);
d3d_transform_set_identity();
d3d_transform_add_rotation_x(angleX);
d3d_transform_add_rotation_z(angleZ);
d3d_transform_add_translation(centerX, centerY, centerZ);
d3d_draw_block(-.3, -.3, -length / 2, .3, .3, length / 2, background_get_texture(textureBlock), 1, 1);
d3d_transform_set_identity();
But here it doesn't: