mirror of
https://github.com/guezoloic/t3dsr.git
synced 2026-01-25 12:34:24 +00:00
fix: change value to persp matrix
This commit is contained in:
21
src/cam.c
21
src/cam.c
@@ -5,14 +5,14 @@
|
||||
|
||||
Mat4f_t perspCam(float fov, float asp, float near, float far)
|
||||
{
|
||||
const float t = 1.f / tanf(fov*0.5f);
|
||||
const float fn = near - far;
|
||||
const float t = 1.f / tanf(fov * 0.5f * (M_PI/180.f));
|
||||
const float fn = far - near;
|
||||
const float persp[16] =
|
||||
{
|
||||
t/asp, 0.f, 0.f, 0.f,
|
||||
0.f, t, 0.f, 0.f,
|
||||
0.f, 0.f, (far + near) / fn, -1.f,
|
||||
0.f, 0.f, (2.f * far * near) / fn, 0.f
|
||||
0.f, 0.f, -(far + near) / fn, -1.f,
|
||||
0.f, 0.f, -(2.f * far * near) / fn, 0.f
|
||||
};
|
||||
|
||||
return mat4f_from_array(persp);
|
||||
@@ -48,14 +48,11 @@ Mat4f_t lookAt(Vec4f_t* eye, Vec4f_t* center, Vec4f_t* up)
|
||||
Vec4f_t u = vec4f_cross(s, f);
|
||||
u.data[3] = 0.f;
|
||||
|
||||
const float m[16] = {
|
||||
s.x, u.x, -f.x, 0.f,
|
||||
s.y, u.y, -f.y, 0.f,
|
||||
s.z, u.z, -f.z, 0.f,
|
||||
-vec4f_dot(s, *eye),
|
||||
-vec4f_dot(u, *eye),
|
||||
vec4f_dot(f, *eye),
|
||||
1.f
|
||||
float m[16] = {
|
||||
s.x, s.y, s.z, -vec4f_dot(s, *eye),
|
||||
u.x, u.y, u.z, -vec4f_dot(u, *eye),
|
||||
-f.x, -f.y, -f.z, -vec4f_dot(f, *eye),
|
||||
0.f, 0.f, 0.f, 1.f
|
||||
};
|
||||
|
||||
return mat4f_from_array(m);
|
||||
|
||||
28
src/main.c
28
src/main.c
@@ -1,28 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include "cam.h"
|
||||
#include "math/vec4.h"
|
||||
|
||||
Vec4f_t mat4f_mul_vec4f(const Mat4f_t mat, Vec4f_t v)
|
||||
{
|
||||
Vec4f_t out;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
out.data[i] = 0.f;
|
||||
for (int j = 0; j < 4; j++)
|
||||
out.data[i] += mat.m[i*4 + j] * v.data[j];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#include "draw.h"
|
||||
#include "math/mv4.h"
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
const float fov = 60;
|
||||
const float width = 1000, height = 800;
|
||||
const float width = 80, height = 30;
|
||||
const float near = 0.1, far = 1000;
|
||||
|
||||
const float aspect = width / height;
|
||||
|
||||
// xyz = [-1, 1]
|
||||
// xyz = [-1; 1]
|
||||
Vec4f_t vec = vec4f(0.f, 0.f, -1.f, 1.f);
|
||||
Mat4f_t proj = perspCam(fov, aspect, near, far);
|
||||
|
||||
@@ -30,9 +19,10 @@ int main(int argc, const char** argv)
|
||||
|
||||
normCoord_r(&v_clip);
|
||||
viewport_r(&v_clip, width, height);
|
||||
|
||||
printf("Screen coordinates: x = %f, y = %f, z = %f\n",
|
||||
v_clip.x, v_clip.y, v_clip.z);
|
||||
|
||||
|
||||
initCanvas(width, height);
|
||||
drawCanvas(v_clip, width, height);
|
||||
renderCanvas(width, height);
|
||||
printf("%f", v_clip.z);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user