• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Problem with 3D rotations

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:

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();
In this position it works:
11.png
But here it doesn't:
22.png
 
V

VectorStudio

Guest
This would probably be a better topic for the advanced board. Really cool work, though!
Thanks, I didn't know there is the advanced board because I'm new here. Anyway I found a possible way how to solve my problem. I just basically need to implement Unity3D's function 'LookAt' into GameMaker. If I succeed I will consider writing a C++ library that will allow you to work with the kinect so also others will be able to test it out.
 
M

Multimagyar

Guest
not soo much "unity" function I'm almost sure it's the same as the openGL or DirectX equivalent. In GMS2 it also been implemented alternatively which is a pretty inconvenient solution for GMS1 and probably slow, you could take advantage of the camera setup code and just harvest the necessary matrix from there. d3d_set_projection or something like that I recall then matrix get the view matrix.

Also one thing I noticed in your code, you only rotate on roll (x rotation transformation) and yaw (z rotation transformation) and for your desired effect you most probably want to rotate on pitch as well.
 
V

VectorStudio

Guest
not soo much "unity" function I'm almost sure it's the same as the openGL or DirectX equivalent. In GMS2 it also been implemented alternatively which is a pretty inconvenient solution for GMS1 and probably slow, you could take advantage of the camera setup code and just harvest the necessary matrix from there. d3d_set_projection or something like that I recall then matrix get the view matrix.

Also one thing I noticed in your code, you only rotate on roll (x rotation transformation) and yaw (z rotation transformation) and for your desired effect you most probably want to rotate on pitch as well.
Thanks for the nice answer. I have never worked with 3D in GMS2 but according to what you wrote is seems like it's better than 3D in GMS1 so I will try it. One more question. Is 3D in GMS2 "real" or it's "fake" like in GMS1?
 
M

Multimagyar

Guest
depends what you mean by fake. More advanced products (AAA titles if you will or unity,) uses vertex buffers, shaders, and other buffer based algorithms with camera world-view-projection algorithms just like Game maker does in all version, the difference is in GMS2 you don't have to activate the 3D view instead you completely have to setup your camera and gives you more functions like matrix with vector multiplication, lookat matrix build and takes away certain aspects that's completely outdated with d3d and introduces the DX11 version of it. Which includes some GPU functions.
 
Top