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();
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
-
4.1 KB Views: 0