[Request] rot/scale texture drawer frontend (tri drawer)

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

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!)
Post Reply
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

[Request] rot/scale texture drawer frontend (tri drawer)

Post by Nash »

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.
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [Request] rot/scale texture drawer frontend (tri drawer)

Post by Nash »

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.
Attachments
shape_m.zip
(865 Bytes) Downloaded 50 times
User avatar
Marisa the Magician
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
Contact:

Re: [Request] rot/scale texture drawer frontend (tri drawer)

Post by Marisa the Magician »

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]);
	}
}
Talon1024
 
 
Posts: 374
Joined: Mon Jun 27, 2016 7:26 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia with Vulkan support
Contact:

Re: [Request] rot/scale texture drawer frontend (tri drawer)

Post by Talon1024 »

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.
What's the license for that code?

We're using it in Blade of Agony, and I'm trying to sort out some code licensing issues right now.
Post Reply

Return to “Scripting”