• 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!

Each rotation starts with the same image

C

Constant

Guest
Rotating cube

When <Left>, <Right>, <Up> or <Down> is used the cube should have a -90 or 90 degree rotation.
The cube does rotate but each rotation starts with the same image (= the image that is visible at startup).
In the obj_Cube Draw-event I tested using d3d_transform_stack_push() and d3d_transform_stack_pop()
or d3d_transform_stack_top() but could not make it work correctly.

1 Room, 1 Camera, 1 0bj_cube

Can somebody take a look and help me please?
I use GM Professional Edition v1.4.1675

Thanks in advance. (see code below)

// ---- obj_cam ----
// Create
d3d_start();
d3d_set_perspective(true);
d3d_set_hidden(true);
d3d_set_lighting(false);
d3d_set_culling(false);
d3d_set_shading(false);
draw_set_color(c_white);

// Draw
d3d_set_projection(obj_cube.x,obj_cube.y,30,obj_cube.x,obj_cube.y,60,0,0,1);


// ---- obj_cube ---
// Create
rot = 0; //rotation variable

b_Left_Pressed=false; //to check if Left is pressed
b_Right_Pressed=false; //to check if Right is pressed
b_Up_pressed=false; //to check if Up is pressed
b_Down_pressed=false; //to check if Down is pressed

// Step
//if b_Left_Pressed=true
//{ rot-=5; } //Cube keeps on rotating

if b_Left_Pressed=true
{ if rot > -90 then { rot-=5; } } // -90 degree rotation

if b_Right_Pressed=true
{ if rot < 90 then { rot+=5; } } // 90 degree rotation

if b_Down_pressed=true
{ if rot > -90 then { rot-=5; } } // -90 degree rotation

if b_Up_pressed=true
{ if rot < 90 then { rot+=5; } } // 90 degree rotation

//<Left>
rot=0;
b_Left_Pressed=true;
b_Right_Pressed=false;
b_Up_pressed=false;
b_Down_pressed=false;

//<Up>
rot=0;
b_Left_Pressed=false;
b_Up_pressed=true;
b_Right_Pressed=false;
b_Down_pressed=false;

//<Right>
rot=0;
b_Left_Pressed=false;
b_Up_pressed=false;
b_Right_Pressed=true;
b_Down_pressed=false;

//<Down>
rot=0;
b_Left_Pressed=false;
b_Up_pressed=false;
b_Right_Pressed=false;
b_Down_pressed=true;

//Draw
if b_Left_Pressed=true
{ d3d_transform_add_rotation_y(rot) }

if b_Right_Pressed=true
{ d3d_transform_add_rotation_y(rot) }

if b_Up_pressed=true
{ d3d_transform_add_rotation_x(rot) }

if b_Down_pressed=true
{ d3d_transform_add_rotation_x(rot) }

d3d_transform_add_translation(room_width/2,room_height/2,0);

d3d_draw_block(-32,-32,32, 32,32,-32,background_get_texture(tex_cube),1,1);

d3d_transform_set_identity();
 

Attachments

RangerX

Member
In the create event you tell the rotation to start at zero here:

Code:
// ---- obj_cube ---
// Create
rot = 0; //rotation variable
So each cube that is created will start with the same rotation/angle.
 
C

Constant

Guest
I don't relly know what you mean.
I only use one cube: obj_cube and it is created only one time.
Once it is created it has to rotate -90 or 90 degrees lwhen <Left>,<Right>,<Up> or <Down> is used.
 

RangerX

Member
Ok, then if you want your cube to start on different sides, you need to rotate it at creation using a random.
Now you know if its by the "rot" variable or some d3d function...
 
C

Constant

Guest
Thanks for the response but my issue is not about eacht time the program starts
the cube must have a different image to the front.

What I want to achieve is that once the cube is created it has to rotate 90 degrees when
<Left>, <Right>, <Up> or <Down> is used .

Regardless of the number of previous rotations, and regardless of the direction
( Left, Right, Up or Down ) , the cube should rotate 90 degrees each time an arrow button
is pressed.

So each ROTATION begins with a new image to the front.

That's what I want to achieve.
 

RangerX

Member
Then you need to just add or substract 90 degrees when you press those keys. If you cube is already into some rotation or already rotated to a certain angle, it will add or remove 90 of that angle.
 
C

Constant

Guest
When I use: rot+=90 or rot-=90 then the image is changed immediately.
This way you don't see the cube actually rotating.

That's why I use rot+=5 or rot-=5 in the Step-event. That makes the cube really rotating.
So the problem still is: how can I start each rotation with the last image to the front.
 
C

Constant

Guest
I found a solution by checking the amount of rotation in the Step-event
and stop rotation at the correct value.
Thanks for helping me.
 
Top