Jump to content


Photo

Add rotation to a sprite then scaling?


  • This topic is locked This topic is locked
8 replies to this topic

#1 demon

demon

    GMC Member

  • GMC Member
  • 98 posts

Posted 25 April 2012 - 07:23 PM

How would you go about rotating a sprite and THEN changing the scale with gml drawing functions?

Heres an example(This is done by scaling the room which is not what I want to do):
Posted Image

Edited by demon, 25 April 2012 - 08:43 PM.

  • 0

#2 loverock125

loverock125

    GMC Member

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

Posted 25 April 2012 - 07:55 PM

Doesn't draw_sprite_ext do that?

draw_sprite_ext(sSpr,-1,x,y,1.5,1.5,60,c_white,1);

  • 0

#3 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 20921 posts
  • Version:GM:Studio

Posted 25 April 2012 - 08:05 PM

That won't work as what he wants is the sprite to maintain the angle of scaling while the texture has the rotation. You will probably need to use textured primitives for this...
  • 0

#4 loverock125

loverock125

    GMC Member

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

Posted 25 April 2012 - 08:09 PM

That won't work as what he wants is the sprite to maintain the angle of scaling while the texture has the rotation. You will probably need to use textured primitives for this...


What about saving the rotated sprite in a surface, use sprite_assign to replace the old one and then use draw_sprite_ext to scale it?
  • 0

#5 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2940 posts
  • Version:GM:Studio

Posted 25 April 2012 - 08:21 PM

Or you can use transformations:
d3d_transform_set_rotation_z(image_angle)
d3d_transform_add_scaling(image_xscale, image_yscale, 0)
d3d_transform_add_translation(x, y, 0)
draw_sprite_ext(sprite_index, 0, 0, 0, 1, 1, 0, image_blend, image_alpha)
d3d_transform_set_identity()
Not tested, but I believe it should work. You do not have to start 3D mode to use transformation functions. The first one rotates the image, the second one scales it, and the third one moves it to the correct coordinates. The last one is needed to prevent stuff drawn afterwards from being affected by the transformation
  • 1

#6 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9322 posts
  • Version:Unknown

Posted 25 April 2012 - 08:24 PM

I'd go with TheSnidr's method, as it's much simpler than working out the math for the verticies of a textured primitive with rotation and scaling. The only change I'd suggest is using push and pop to maintain the transformation state instead of resetting to the identity. For the most part, it won't make a difference, but in the case that you do add other transformations later, it will save you some headaches.

d3d_transform_stack_push();
d3d_transform_set_rotation_z(image_angle);
d3d_transform_add_scaling(image_xscale, image_yscale, 0);
d3d_transform_add_translation(x, y, 0);
draw_sprite_ext(sprite_index, 0, 0, 0, 1, 1, 0, image_blend, image_alpha);
d3d_transform_stack_pop();

-IMP
  • 0

#7 demon

demon

    GMC Member

  • GMC Member
  • 98 posts

Posted 25 April 2012 - 08:25 PM

Or you can use transformations:

d3d_transform_set_rotation_z(image_angle)
d3d_transform_add_scaling(image_xscale, image_yscale, 0)
d3d_transform_add_translation(x, y, 0)
draw_sprite_ext(sprite_index, 0, 0, 0, 1, 1, 0, image_blend, image_alpha)
d3d_transform_set_identity()
Not tested, but I believe it should work. You do not have to start 3D mode to use transformation functions. The first one rotates the image, the second one scales it, and the third one moves it to the correct coordinates.


Worked perfectly, thanks a bunch! Thats a neat little trick using D3D functions for 2D.
  • 0

#8 loverock125

loverock125

    GMC Member

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

Posted 25 April 2012 - 08:35 PM


Or you can use transformations:

d3d_transform_set_rotation_z(image_angle)
d3d_transform_add_scaling(image_xscale, image_yscale, 0)
d3d_transform_add_translation(x, y, 0)
draw_sprite_ext(sprite_index, 0, 0, 0, 1, 1, 0, image_blend, image_alpha)
d3d_transform_set_identity()
Not tested, but I believe it should work. You do not have to start 3D mode to use transformation functions. The first one rotates the image, the second one scales it, and the third one moves it to the correct coordinates.


Worked perfectly, thanks a bunch! Thats a neat little trick using D3D functions for 2D.


I tried this before posting and it has the same result as draw_sprite_ext. Maybe I couldn't notice any difference on the texture because it was a 64x64 image.

Edited by loverock125, 25 April 2012 - 08:35 PM.

  • 0

#9 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2940 posts
  • Version:GM:Studio

Posted 25 April 2012 - 08:42 PM



Or you can use transformations:

d3d_transform_set_rotation_z(image_angle)
d3d_transform_add_scaling(image_xscale, image_yscale, 0)
d3d_transform_add_translation(x, y, 0)
draw_sprite_ext(sprite_index, 0, 0, 0, 1, 1, 0, image_blend, image_alpha)
d3d_transform_set_identity()
Not tested, but I believe it should work. You do not have to start 3D mode to use transformation functions. The first one rotates the image, the second one scales it, and the third one moves it to the correct coordinates.


Worked perfectly, thanks a bunch! Thats a neat little trick using D3D functions for 2D.


I tried this before posting and it has the same result as draw_sprite_ext. Maybe I couldn't notice any difference on the texture because it was a 64x64 image.

You probably scaled it first, then rotated it. That would produce the same result as just using draw_sprite_ext
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users