# Textured Primitive Deformation

7 replies to this topic

### #1 banov

banov

GMC Member

• GMC Member
• 1172 posts
• Version:Unknown

Posted 19 February 2012 - 10:12 PM

Hi everyone.

I want to draw an image, labelled here A, and transform it into shape B in which it sort of fans out. Textured primitives struck me as the way to go, but when I set my vertices and draw it, the result is C--the shape is comprised of two triangles, and their edges do not line up so there's a very visible deformation on the final shape. Rearranging the point orders didn't seem to make any particular difference other than the angle of the deformation.

Is there a way for my textured primitive to look nondeformed? Is there another method to achieve this scaling effect? Any help at all would be appreciated.

Thanks.
• 0

### #2 Medusar

Medusar

GMC Member

• GMC Member
• 1228 posts
• Version:GM:Studio

Posted 19 February 2012 - 10:24 PM

You could try perspective projection in 3D mode. Or you could draw sufficently large an amount of triangles so that the result is not clearly visible anymore.
• 0

Q: Why do programmers always get Christmas and Halloween mixed up?
A: Because DEC 25 = OCT 31

### #3 banov

banov

GMC Member

• GMC Member
• 1172 posts
• Version:Unknown

Posted 19 February 2012 - 10:53 PM

Drawing many triangles sounds slow and unattractive... but I'm very very unfamiliar with d3d transformations. I don't know where to begin when it comes to attempting that on a sprite. Could you guide me to what functions I should be looking at?
• 0

### #4 hit172

hit172

GMC Member

• New Member
• 189 posts
• Version:GM8

Posted 19 February 2012 - 11:59 PM

you can try mapping the texture to the primitive in the shape of the resulting triangles instead of a square.
so for the texture coordinates do this.

Edited by hit172, 20 February 2012 - 12:01 AM.

• 0
Duct tape is like the force. It has a light side and a dark side and holds the universe together.
When life gives you lemons, make orange juice... and leave everyone wondering how the **** you did it.

### #5 banov

banov

GMC Member

• GMC Member
• 1172 posts
• Version:Unknown

Posted 20 February 2012 - 12:07 AM

you can try mapping the texture to the primitive in the shape of the resulting triangles instead of a square.
so for the texture coordinates do this.

That would not work for me, since the stretching is an important part of the effect I'm attempting to create. I'm also moving the texture origin and looping it so that the stars fan out and grow. It's a nice looking animation, discounting the distortion across the center axis.
• 0

### #6 hit172

hit172

GMC Member

• New Member
• 189 posts
• Version:GM8

Posted 20 February 2012 - 02:27 AM

you can try mapping the texture to the primitive in the shape of the resulting triangles instead of a square.
so for the texture coordinates do this.

That would not work for me, since the stretching is an important part of the effect I'm attempting to create. I'm also moving the texture origin and looping it so that the stars fan out and grow. It's a nice looking animation, discounting the distortion across the center axis.

in what order are you drawing the vertices (you need to get that right so that the deformation happens in the direction you want)
• 0
Duct tape is like the force. It has a light side and a dark side and holds the universe together.
When life gives you lemons, make orange juice... and leave everyone wondering how the **** you did it.

### #7 banov

banov

GMC Member

• GMC Member
• 1172 posts
• Version:Unknown

Posted 20 February 2012 - 04:09 AM

BCAD and BACD are the combinations I tried. They were about identical in appearance.

Edited by banov, 20 February 2012 - 04:10 AM.

• 0

### #8 Medusar

Medusar

GMC Member

• GMC Member
• 1228 posts
• Version:GM:Studio

Posted 20 February 2012 - 10:51 AM

Drawing many triangles sounds slow and unattractive...

Needn't be. You can simply create a d3d model and draw that... the vertices are then stored in graphics memory (if you use GM8.1) which is about as fast as drawing a single quad. Remember that you won't need hundreds of triangles.

I don't know where to begin when it comes to attempting that on a sprite. Could you guide me to what functions I should be looking at?

I think you won't need to switch to 3D mode for this. You could start with something like this:
```// setup perspective projection
d3d_set_projection_perspective(0, 0, room_width, room_height, 0); // change this to view_xview[] and family if necessary

// transform the sprite.
d3d_transform_set_rotation_x(/*...*/); // rotating about the x axis will make the top / bottom area become smaller
d3d_transform_add_rotation_y(/*...*/); // rotating about the y axis will do the same but with the sides
d3d_transform_add_translation(x, y, 0); // where you want the sprite to be drawn
draw_sprite(/*...*/, /*...*/, 0, 0); // always draw at (0, 0)
d3d_transform_set_identity(); // reset the transformation

d3d_set_projection_ortho(0, 0, room_width, room_height, 0); // reset normal projection. Again use view_* if necessary.```

Remember that with perspective projection, the deformation will change depending on the position of the image relative to the camera. So if you draw the image in the middle of the screen, you will get another result than if you draw it, for instance, in a corner.
• 0

Q: Why do programmers always get Christmas and Halloween mixed up?
A: Because DEC 25 = OCT 31