It is currently March 28th, 2024, 11:59 pm

Question(s) about transformation matrix

General topics related to Rainmeter.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Question(s) about transformation matrix

Post by FreeRaider »

Hello everyone.
I'm working with transformation matrix, but I do not understand how to make a skew of a polygon (the green square in the following images).

I use a couple of images to explain:
I have this image:
start.png
and my goal is this
end.png
where the blue point is the origin i.e. the top-left corner of the entire skin.

Now, the first question: how I calculate the new origin point for the square (you can see that the blue point, after the transformation, is at a new value of X) ?
the second question: if I wanted to change the origin point of the transformation, what should I insert in the matrix ?

An example code:

Code: Select all

[Rainmeter]
Update=-1
AccurateText=1
DynamicWindowSize=1

[Variables]
Angle=-60
X_prime=150
Y_prime=150

[MeasureScaleX]
Measure=Calc
Formula=1

[MeasureSkewY]
Measure=Calc
Formula=0
DynamicVariables=1

[MeasureSkewX]
Measure=Calc
Formula=TAN(Rad(#Angle#))
DynamicVariables=1

[MeasureScaleY]
Measure=Calc
Formula=1

[MeasureMoveX]
Measure=Calc
Formula=(#X_prime# - [MeterSquare:X] * [MeasureScaleX:] - [MeterSquare:Y] * [MeasureSkewX:])
DynamicVariables=1

[MeasureMoveY]
Measure=Calc
Formula=(#Y_prime# - [MeterSquare:X] * [MeasureSkewY:] - [MeterSquare:Y] * [MeasureScaleY:])
DynamicVariables=1

[MeterBackground]
Meter=Image
X=0
Y=0
W=400
H=400
SolidColor=200,200,200,125

[MeterSquare]
Meter=Image
X=150
Y=150
W=100
H=100
SolidColor=255,0,0,255
SolidColor2=0,255,0,255
GradientAngle=270
AntiAlias=1
TransformationMatrix=([MeasureScaleX:]);([MeasureSkewY:]);([MeasureSkewX:]);([MeasureScaleY:]);([MeasureMoveX:]);([MeasureMoveY:])
DynamicVariables=1
Thanks in advance for your answers.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question(s) about transformation matrix

Post by jsmorley »

Easy...

User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Question(s) about transformation matrix

Post by FreeRaider »

:rolmfao: :rofl:
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Question(s) about transformation matrix

Post by balala »

FreeRaider wrote:Now, the first question: how I calculate the new origin point for the square (you can see that the blue point, after the transformation, is at a new value of X) ?
the second question: if I wanted to change the origin point of the transformation, what should I insert in the matrix ?
The last two parameters of the TransformationMatrix option are used to move the "transformed" meter horizontally, respectively vertically (obviously the fifth moves it horizontally, while the sixth vertically). So you should have to alter the fifth parameter. In your initial code it is ([MeasureMoveX:]). I'd modify the Formula option of the [MeasureMoveX] measure, to Formula=([color=#FF0000]2 * [/color]#X_prime# - [MeterSquare:X] * [MeasureScaleX:] - [MeterSquare:Y] * [MeasureSkewX:]) (I marked red what I've changed). Not sure this will entirely match your needs, but if it doesn't, you can add a constant value: Formula=(2 * #X_prime# - [MeterSquare:X] * [MeasureScaleX:] - [MeterSquare:Y] * [MeasureSkewX:] [color=#FF0000]+ 23[/color]). I think you have to make a few tries to find the best value to add, 23 is just a first approach.
I hope this answers both questions. If it doesn't please let me know.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Question(s) about transformation matrix

Post by FreeRaider »

balala wrote:used to move the "transformed" meter
this sentence has opened my mind.

Precisely, the measure must be

Code: Select all

[MeasureMoveX]
Measure=Calc
Formula=(#X_prime# - [MeterSquare:X] * [MeasureScaleX:] - [MeterSquare:Y] * [MeasureSkewX:] - [MeterSquare:H] * [MeasureSkewX:])
DynamicVariables=1
The updated code

Code: Select all

[Rainmeter]
Update=-1
AccurateText=1
DynamicWindowSize=1

[Variables]
Angle=(0-30)
X_prime=150
Y_prime=150

[MeasureScaleX]
Measure=Calc
Formula=1

[MeasureSkewY]
Measure=Calc
Formula=0
DynamicVariables=1

[MeasureSkewX]
Measure=Calc
Formula=TAN(Rad(#Angle#))
DynamicVariables=1

[MeasureScaleY]
Measure=Calc
Formula=1

[MeasureMoveX]
Measure=Calc
Formula=(#X_prime# - [MeterSquare:X] * [MeasureScaleX:] - [MeterSquare:Y] * [MeasureSkewX:] - [MeterSquare:H] * [MeasureSkewX:])
DynamicVariables=1

[MeasureMoveY]
Measure=Calc
Formula=(#Y_prime# - [MeterSquare:X] * [MeasureSkewY:] - [MeterSquare:Y] * [MeasureScaleY:])
DynamicVariables=1

[MeterBackground]
Meter=Image
X=0
Y=0
W=400
H=400
SolidColor=200,200,200,125

[MeterSquare]
Meter=Image
X=150
Y=150
W=100
H=100
SolidColor=255,0,0,255
SolidColor2=0,255,0,255
GradientAngle=270
AntiAlias=1
TransformationMatrix=([MeasureScaleX:]);([MeasureSkewY:]);([MeasureSkewX:]);([MeasureScaleY:]);([MeasureMoveX:]);([MeasureMoveY:])
DynamicVariables=1

[MeterVertical]
Meter=Image
X=150
Y=0
W=1
H=400
SolidColor=0,0,0,255

[MeterHorizontal]
Meter=Image
X=0
Y=150
W=400
H=1
SolidColor=0,0,0,255
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Question(s) about transformation matrix

Post by balala »

:17good