[Request] rot/scale texture drawer frontend (tri drawer)
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
-
- Posts: 17481
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
[Request] rot/scale texture drawer frontend (tri drawer)
Hi, can someone please make a wrapper function that simply allows the user to draw a 2D texture on to the screen that can be scaled and rotated easily? Thanks.
-
-
- Posts: 17481
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: [Request] rot/scale texture drawer frontend (tri drawer)
Here is a rotating texture example wrote by Marisa that was buried in obscurity, so I'm re-uploading it here so that others can benefit and learn from it.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: [Request] rot/scale texture drawer frontend (tri drawer)
Here's generalised functions for creating/preparing a square shape and then applying a scale, rotation and translation. I've only just written it without testing it, so do tell me if anything's wrong.
Code: Select all
// create a square shape (not usable until calling MoveSquare)
static clearscope Shape2D MakeSquare()
{
// the shape that will be drawn
Shape2D square = new("Shape2D");
// texture coordinates of each corner
square.PushCoord((0,0));
square.PushCoord((1,0));
square.PushCoord((0,1));
square.PushCoord((1,1));
// two triangles make up the square
// the points have to be in counter-clockwise order
square.PushTriangle(0,3,1);
square.PushTriangle(0,2,3);
return square;
}
// set the positions of an existing square shape's vertices
static clearscope void MoveSquare( Shape2D shape, Vector2 size, Vector2 pos, double angle )
{
// clear any vertices already set
shape.Clear(Shape2D.C_Verts);
// corners of a square centered on 0,0
Vector2 points[4];
points[0] = (-0.5*size.x,-0.5*size.y);
points[1] = ( 0.5*size.x,-0.5*size.y);
points[2] = (-0.5*size.x, 0.5*size.y);
points[3] = ( 0.5*size.x, 0.5*size.y);
// apply a 2D rotation matrix:
//
// ┌ ┐ ┌ ┐
// │ cos θ -sin θ │ │ X │
// │ │ * │ │
// │ sin θ cos θ │ │ Y │
// └ ┘ └ ┘
//
// then move the points by the set offset
for ( int i=0; i<4; i++ )
{
Vector2 oldpos = points[i];
points[i].x = oldpos.x*cos(angle)-oldpos.y*sin(angle) + pos.x;
points[i].y = oldpos.x*sin(angle)+oldpos.y*cos(angle) + pos.y;
square.PushVertex(points[i]);
}
}
-
-
- Posts: 376
- Joined: Mon Jun 27, 2016 7:26 pm
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia with Vulkan support
Re: [Request] rot/scale texture drawer frontend (tri drawer)
What's the license for that code?Marisa Kirisame wrote:Here's generalised functions for creating/preparing a square shape and then applying a scale, rotation and translation. I've only just written it without testing it, so do tell me if anything's wrong.
We're using it in Blade of Agony, and I'm trying to sort out some code licensing issues right now.