View Full Version : how to scale am matrix non-uniformly/with negative values?

Vexator

07-22-2006, 10:50 AM

for reflections in my water shader i need to flip my scene upside down. i'm using glscalef( 1.0f, -1.0f, 1.0f) for this atm, but i'd prefer to use my matrix class for this, of course. but i can't figure out how to scale a matrix non-uniformly and with negative values. no matter what i do, my scene is always deformed.. any hints? thank you :)

Zengar

07-22-2006, 12:38 PM

If i am not mistaken, a scale matrix is

(sx, 0, 0, 0)

(0, sy, 0, 0)

(0, 0, sz, 0)

(0, 0, 0, 1)

Hence you need to use something like

(1, 0, 0, 0)

(0, -1, 0, 0)

(0, 0, 1, 0)

(0, 0, 0, 1)

Or?

Vexator

07-24-2006, 10:12 AM

thank you, that did it!

ok, next question - how to apply scaling to the inverted matrix?

Overmind

07-24-2006, 04:12 PM

Scale it by the inverse values...

(1/sx, 0, 0, 0)

(0, 1/sy, 0, 0)

(0, 0, 1/sz, 0)

(0, 0, 0, 1)

And of course you have to premultiply instead of postmultiply, as with every operation on the inverse matrix.

Vexator

07-25-2006, 01:29 AM

ah that's probably the problem - i tried to multiply by the inverse values after i applied translation and rotation, but this screwed it all up. so i have to scale first, and then translate and rotate? i'll give it a try thanks.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.