Jump to content


Photo

Using D3D to rotate multisprites at multi-angles


  • Please log in to reply
4 replies to this topic

#1 esco

esco

    GMC Member

  • GMC Member
  • 209 posts

Posted 21 May 2012 - 05:13 AM

Hey everyone, I have run into a bit of an issue using d3d rotation that I need a little help with please. I am aware that when rotating sprites IF I want them to stay centered in a manner so that when rotated they appear to spin in place (as if the origin is set to the EXACT center of the sprite, which is usually not the case) I have to use the following:

d3d_transform_set_rotation_z(image_angle)
d3d_transform_add_translation(x,y,0) 
draw_sprite_ext(backleg_sprite, 0, 0, 0, image_xscale, image_yscale, 0, image_blend, image_alpha);
draw_sprite_ext(frontleg_sprite, 0, 0, 0, image_xscale, image_yscale, 0, image_blend, image_alpha);

But how can I do this same thing IF I have multiple sprites that ARE ROTATED AT DIFFERENT ANGLES (unlike the above two which both rotate with image angle). Here is my code thus far:

//DRAW EVENT
d3d_transform_set_rotation_z(0)
d3d_transform_add_translation(x,y,0)  
      
draw_sprite_ext(aluwolf_sword, 0, 0, 0, alucard.image_xscale, alucard.image_yscale, wolf_body1_angle, image_blend, image_alpha);  
                                                        
draw_sprite_ext(aluwolf_body2, 0, 0, 0, alucard.image_xscale, alucard.image_yscale, wolf_body2_angle, image_blend, image_alpha);
                
draw_sprite_ext(aluwolf_body1, 0, 0, 0, alucard.image_xscale, alucard.image_yscale, wolf_body1_angle, image_blend, image_alpha);
                                  
//Next two don't rotate
draw_sprite_ext(aluwolf_head, head_index, 0, 0, alucard.image_xscale, alucard.image_yscale, 0, image_blend, image_alpha);     
                       
draw_sprite_ext(backleg_sprite, floor(image_index), 0, 0, alucard.image_xscale, alucard.image_yscale, 0, image_blend, image_alpha);
                        
d3d_transform_set_identity();  

I have it coded so that when I walk downhill the body pieces and sword angle downward. And when I walk uphill they all angle upward. Now this code actually does work when I walk downhill, but when walking uphill for some reason the pieces appear to move back instead of rotating in place? Why is this? And how can I adapt my code to take the fact that these sprites use 2 angles instead of one into account?

I will gladly rep anyone who solves this. I have messed with my code for about 2-3 hours trying to figure out how to fix this issue and could not. This is also my first time creating an object that uses multiple rotating sprites for it, so any good advice on working with them is welcome.

Edited by esco, 22 May 2012 - 12:50 AM.

  • 0

#2 brac37

brac37

    GMC Member

  • GMC Member
  • 765 posts
  • Version:GM7

Posted 21 May 2012 - 06:34 PM

I do not see image_angle in your first code: it is zero. Furthermore, the subimage argument is missing.

In the second code, the angle argument can be seen as an initial z-rotation. So
d3d_transform_set_rotation_z(0);
d3d_transform_add_translation(x,y,0)  
draw_sprite_ext(aluwolf_sword, 0, 0, 0, alucard.image_xscale, alucard.image_yscale, wolf_body1_angle, image_blend, image_alpha); 
d3d_transform_set_identity();
is the same as
d3d_transform_set_rotation_z(wolf_body1_angle);
d3d_transform_add_translation(x,y,0)  
draw_sprite_ext(aluwolf_sword, 0, 0, 0, alucard.image_xscale, alucard.image_yscale, 0, image_blend, image_alpha); 
d3d_transform_set_identity();
I do not understand exactly what you get and what you wish to get.
  • 0

#3 esco

esco

    GMC Member

  • GMC Member
  • 209 posts

Posted 21 May 2012 - 07:23 PM

I do not see image_angle in your first code: it is zero. Furthermore, the subimage argument is missing.


Corrected.... thanks for that. I made that post right before going to bed so I missed some small things. :)


I do not understand exactly what you get and what you wish to get.


It is listed above in great detail. And here is a video of it:



As you can see walking DOWNHILL the pieces don't move when they rotate. But walking uphill they do for some reason and appear to "jerk" backwards.. :/

Edited by esco, 21 May 2012 - 08:07 PM.

  • 0

#4 esco

esco

    GMC Member

  • GMC Member
  • 209 posts

Posted 22 May 2012 - 06:48 PM

I yet again, stand corrected; I moved the body pieces up some, and now that I have a clearer view, I can clearly see that when angling downward the body pieces DO move forward, just like when angling upward they move backward. How can I rotate these pieces in a way that they act as if their origin is in the EXACT center of the sprite?
  • 0

#5 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1589 posts
  • Version:GM8.1

Posted 23 May 2012 - 02:22 AM

I yet again, stand corrected; I moved the body pieces up some, and now that I have a clearer view, I can clearly see that when angling downward the body pieces DO move forward, just like when angling upward they move backward. How can I rotate these pieces in a way that they act as if their origin is in the EXACT center of the sprite?

Well, you can move the sprite by a rotated offset, or you can simply set the sprite's origin in the sprite editor.

(If you can't set the origin, which is unlikely), you can use lengthdir_x/lengthdir_y to find what you should add.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users