Need some help with CFrame matrix

  1. What do you want to achieve?
    I’ve been struggling to wrap my head around CFrame matrix, I’ve been trying for about 2 days to use CFrame matrix to stretch the camera to the X and Y axis. If somebody could explain to me how to get CFrame matrix to work specifically for this situation (Being able to stretch the camera for example) that would be much appreciated.

  2. What is the issue?
    There are no clear explanations I could find online, I’ve only seen 1 person asking for help similar to what I’m asking help for, but nobody responded.

  3. What solutions have you tried so far?
    I’ve tried looking online for answers, and I even found a open-source game by clone trooper, I’ve read the code and I still just don’t understand, I’ve also tried just messing around with the camera’s CFrame in the command bar just to see if I make any progress but still nothing.

1 Like

Have you tried understanding normal matrices first? Jumping into the deep end of Camera CFrame before learning matrices might not be the best idea

2 Likes

Sorry for the late reply but no I haven’t, but the whole point of this game I’m working on is to learn more, this game is more of a place to just test what I am capable of and having a better idea of CFrame matrices will help.

This article: CFrame Math Operations is my go-to if I need to see how matrices relate to CFrames.

I’m not sure what you mean by stretch the camera either so could you please clarify?

In Roblox, a CFrame is a hidden 4x4 matrix but you can’t modify the bottom row, it defaults to 0,0,0,1 (well you actually can, sorta). The players camera cframe, that is the one that comes from setting the cameratype to scriptable → workspace.CurrentCamera.CFrame is equal to the perspectiveMatrix * cameraMatrix* modelMatrix * matrixWhichDescribesTheCurrentVeertexBeingRenderedInModelSpaceMatrix.

you need to create a pseudo perspective matrix with your fov and the clients width and height (see my computer graphics library) then you get the inverse of that and do this (pseudo-code, may need to implement multiplication for 4x4 matricies).

local viewMatrix = perspectiveMatrix:inverse() * camera.CFrame
camera.CFrame = viewMatrix * scaleMatrix

That scale matrix is an affine, aka, the bottom row is 0,0,0,1, a normal cframe, with scaling on all of the vectors which define that matrix transformation. Theres cool stuff you can do than just stretch everything in-game though, you can exploit that and bypass the fov limit. Roblox’s camera cframe matrices are in coloumn order btw.

Does this thread have any useful info for you?

Yes that is basically what I am looking for, thanks.