Help Understanding CFrame Matrix for Camera Manipulation?

Hello, I want to create a camera effect with CFrame Matrix, I’ve looked into it and it relies on a lot of math that I do not currently understand. I found a “Camera Skewer”, but I still left with confusion.

I tried editing R00 and leaving else at 0, but that killed the player and left my screen black, same with all. Can someone explain some math behind Matrix and how I could utilize it with camera manipulation?

A CFrame consists of an offset (the Position, or P vector) and 3 basis vectors XVector, YVector, ZVector. These 3 vectors define the rotation by establishing a right, up and back (-Z is forward in roblox) direction. When these 3 vectors are all perpendicular, the camera behaves normally. Bending these vectors away from perpendicular is what causes the skew. Keep in mind that there is a second matrix used by the camera, the Projection matrix, that you can’t directly edit. It is controlled by the FoV and near / far distances.

When you start out in Camera Skewer, note that each vector has one component which is 1, corresponding to its axis. I.e. R11 starts as 1. Changing the vectors that were originally one scales the view inversely in that direction. If you set R11 to 0.5, then 1 unit of vertical space only takes up half the vertical distance on screen, so your view squishes vertically. Changing a value that was originally zero causes cross-coupling between horizontal and vertical, skewing the view.

Keep in mind that this example is actually letting you multiply the camera basis vectors, not set them. The basis vectors change continuously as the camera is rotated.
(This part is wrong but I have to brb so I can’t fix it now):
A yVector multiplier of 0.5, 1, 0 would actually mean cameraMatrix += cameraMatrix * Vector3.new(0.5, 0, 0)

What kind of camera manipulation are you trying to do? In all cases I can think of you won’t need to directly manipulate the matrix, and I wouldn’t recommend doing that because it’s not very readable. Instead I’d recommend just using transformations.

This is a popular effect I’ve seen many want to recreate and the same with me, this video from UglyBurger0 briefly went over it on his slender series where he “skewed” the camera in ways that look glitchy.

0:14 timestamp

So I get what you’re saying but how can I set the matrix itself?

You have to use CFrame.FromMatrix()

I’m sorry but is it possible for you can give an example of utilizing FromMatrix()? I’m not really understanding how to use it.

I found this CFrame.fromMatrix, what is it and how can I use it? - #7 by Eternalove_fan32 but still pretty confused

CFrame.fromMatrix(
	Vector3.new(0,0,0), --X, Y, Z
	Vector3.new(0,0,0), --Vector3.new(r00,r10,r20)
	Vector3.new(.5,0,0), --Vector3.new(r01,r11,r21)
	Vector3.new(0,0,0) --Vector3.new(r02,r12,r22)
)

A camera in the default orientation and at position zero would be:

CFrame.fromMatrix(
	Vector3.new(0,0,0), --X, Y, Z
	Vector3.new(1,0,0), --Vector3.new(r00,r10,r20)
	Vector3.new(0,1,0), --Vector3.new(r01,r11,r21)
	Vector3.new(0,0,1) --Vector3.new(r02,r12,r22)
)

So if you want skew you would change it to something like:

CFrame.fromMatrix(
	Vector3.new(0,0,0), --X, Y, Z
	Vector3.new(1,0,0), --Vector3.new(r00,r10,r20)
	Vector3.new(0.5,1,0), --Vector3.new(r01,r11,r21)
	Vector3.new(0,0,1) --Vector3.new(r02,r12,r22)
)

I’m sorry for asking a lot of questions but why would you change a lot of the R Parameters?

What do you mean? I’ve only changed one of them in that example.

Instead of just changing 1 of the parameters, you changed a lot of the numbers from 0 to 1. Is there a reason why?

CFrame.fromMatrix(
	Vector3.new(0,0,0), --X, Y, Z
	Vector3.new(1,0,0), --Vector3.new(r00,r10,r20)
	Vector3.new(0,1,0), --Vector3.new(r01,r11,r21)
	Vector3.new(0,0,1) --Vector3.new(r02,r12,r22)
)

Is the identity matrix, it is the matrix equivalent of “one”. Any vector or matrix multiplied by the identity matrix is unchanged, just like multiplying any number by one. Any changes are measured relative to this, not to a matrix of all zeroes, (which isn’t a valid matrix for the camera to have anyway)

So by my understanding, some matrix are just default to 1, and others 0?

The matrix I showed is what you get from CFrame.new()
(with no arguments)
Multiplying anything by this has no effect.

This matrix:

CFrame.fromMatrix(
	Vector3.new(0,0,0), --X, Y, Z
	Vector3.new(1,0,0), --Vector3.new(r00,r10,r20)
	Vector3.new(0.5,1,0), --Vector3.new(r01,r11,r21)
	Vector3.new(0,0,1) --Vector3.new(r02,r12,r22)
)

Has the effect of changing the Y axis of anything multiplied by it. For example, the vector (1, 2, 3) times the identity matrix is still (1, 2, 3). If you multiplied it by this matrix you would get:

X = 1 * 1   + 2 * 0  +  3 * 0 = 1   (the same)
Y = 1 * 0.5 + 2 * 1  +  3 * 0 = 2.5 (different)
Z = 1 * 0   + 2 * 0  +  3 * 1 = 3   (same)

Only the Y axis of the result is affected, and it is only affected by the X part of the input. This is all a matrix is, a list of how much each input axis effects each output axis. So an identity matrix just says “the X output is the same as the X input” and so on. Skew is possible by having the Y component of the game space effect the X component of whats drawn on screen, which is why this effect is possible this way.

3 Likes

I think I get it but I’ll also test this a lot, thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.