MCPcopy Create free account
hub / github.com/SFML/SFML / matrixLookAt

Function matrixLookAt

examples/vulkan/Vulkan.cpp:98–125  ·  view source on GitHub ↗

Construct a lookat view matrix

Source from the content-addressed store, hash-verified

96
97// Construct a lookat view matrix
98void matrixLookAt(Matrix& result, const sf::Vector3f& eye, const sf::Vector3f& center, const sf::Vector3f& up)
99{
100 // Forward-looking vector
101 const sf::Vector3f forward = (center - eye).normalized();
102
103 // Side vector (Forward cross product Up)
104 const sf::Vector3f side = forward.cross(up).normalized();
105
106 result[0][0] = side.x;
107 result[0][1] = side.y * forward.z - side.z * forward.y;
108 result[0][2] = -forward.x;
109 result[0][3] = 0.f;
110
111 result[1][0] = side.y;
112 result[1][1] = side.z * forward.x - side.x * forward.z;
113 result[1][2] = -forward.y;
114 result[1][3] = 0.f;
115
116 result[2][0] = side.z;
117 result[2][1] = side.x * forward.y - side.y * forward.x;
118 result[2][2] = -forward.z;
119 result[2][3] = 0.f;
120
121 result[3][0] = (-eye.x) * result[0][0] + (-eye.y) * result[1][0] + (-eye.z) * result[2][0];
122 result[3][1] = (-eye.x) * result[0][1] + (-eye.y) * result[1][1] + (-eye.z) * result[2][1];
123 result[3][2] = (-eye.x) * result[0][2] + (-eye.y) * result[1][2] + (-eye.z) * result[2][2];
124 result[3][3] = (-eye.x) * result[0][3] + (-eye.y) * result[1][3] + (-eye.z) * result[2][3] + 1.0f;
125}
126
127// Construct a perspective projection matrix
128void matrixPerspective(Matrix& result, sf::Angle fov, float aspect, float nearPlane, float farPlane)

Callers 1

updateUniformBufferMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected