FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál

It Sure Looks Like Keanu Reeves Is Starring In An Armored Core Short Film For Amazon

20. Srpen 2024 v 22:50

Earlier this month, Amazon announced that it had ordered an animated series full of shorts based on video games like Spelunky and Mega Man, called Secret Level. Now we’ve gotten our first look at the teaser trailer for the series, and it certainly looks like there’s a short based on Armored Core, the FromSoftware mech…

Read more...

  • ✇Recent Questions - Game Development Stack Exchange
  • Matrices for OpenGL shadersValtsuh
    So I'm trying to figure out the model, view and projection matrices. I can, with some effort, find my drawings (3x3x3 structure of cubes) in 3D space and it looks like: The problem is, the cubes seem to be offset from the center (where the lines meet at 0, 0, 0), which is where around they're initially positioned, and don't really seem to be sticking to it when moving camera. All around while moving camera the cube movement is off, seems off and inverted. The green area is the far end of the vi
     

Matrices for OpenGL shaders

So I'm trying to figure out the model, view and projection matrices. I can, with some effort, find my drawings (3x3x3 structure of cubes) in 3D space and it looks like:

result

The problem is, the cubes seem to be offset from the center (where the lines meet at 0, 0, 0), which is where around they're initially positioned, and don't really seem to be sticking to it when moving camera. All around while moving camera the cube movement is off, seems off and inverted.

The green area is the far end of the view frustum, and the near end is where the black lines meet.

So far, from what I've gathered, I'm passing to the shaders:

// The model matrix
model.position = { x * scale, y * scale, z * scale }; // 3 x 3 x 3, scale = 50.0
drx::util::MAT4F mModel;
drx::util::MAT4F mSize;
mModel.LoadIdentity();
mModel.Translate(model.position.x, model.position.y, model.position.z);
mSize.Scale(scale, scale, scale);
mModel = mModel.Add(mSize);

// from the MAT4F structure
void Translate(float x, float y, float z) {
    this->matrix[3][0] = x;
    this->matrix[3][1] = y;
    this->matrix[3][2] = z;
}

void Scale(float x, float y, float z) {
    this->matrix[0][0] = x;
    this->matrix[1][1] = y;
    this->matrix[2][2] = z;
}

// The view matrix
m.LoadIdentity();
m.matrix[0][0] = this->right.x;
m.matrix[1][0] = this->right.y;
m.matrix[2][0] = this->right.z;
m.matrix[0][1] = this->up.x;
m.matrix[1][1] = this->up.y;
m.matrix[2][1] = this->up.z;
m.matrix[0][2] = this->front.x; //
m.matrix[1][2] = this->front.y; // Direction vector
m.matrix[2][2] = this->front.z; //
m.matrix[3][0] = this->position.x; //
m.matrix[3][1] = this->position.y; // Eye or camera position vector
m.matrix[3][2] = this->position.z; //
// The projection matrix
float sf = tanf(fov / 2.0f);
this->matrix[0][0] = 1.0f / (ar * sf);
this->matrix[1][1] = 1.0f / sf;
this->matrix[2][2] = -((f + n) / (f - n));
this->matrix[2][3] = -1.0f;
this->matrix[3][2] = -((2.0f * f * n) / (f - n));
this->matrix[3][3] = 1.0f;

And on vertex shader, I have:

#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 inColor;
layout (location = 2) in vec2 texCoord;

out vec4 ourColor;
out vec2 texCoords;

uniform vec4 myColor;
uniform float scale;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 model;

uniform vec3 myOtherColor;

void main()
{
    vec4 myPos = vec4(aPos, 1.0);
    gl_Position = projection * view * model * myPos;
    ourColor = vec4(inColor, 1.0);
    texCoords = texCoord;
} 

Custom matrix structure with OpenGL shaders

I have a MAT4 structure.

struct MAT4 {
    MAT4() {
        int c = 0;
        for (int x = 0; x < 4; x++) {
            for (int y = 0; y < 4; y++) {
                this->matrix[x][y] = 0.0;
                this->pointer[c] = this->matrix[x][y];
                c++;
            }
        }
    }

    double matrix[4][4];
    double pointer[16]; // for opengl

    void LoadIdentity() {
        this->matrix[0][0] = 1.0;
        this->matrix[1][1] = 1.0;
        this->matrix[2][2] = 1.0;
        this->matrix[3][3] = 1.0;
    }

    void RotateX(double x, bool rads = false) {
        if (rads) x *= drx::rad;
        this->matrix[1][1] = cos(x);
        this->matrix[2][1] = -sin(x);
        this->matrix[2][2] = cos(x);
        this->matrix[1][2] = sin(x);
    }
    void RotateY(double y, bool rads = false) {
        if (rads) y *= drx::rad;
        this->matrix[0][0] = cos(y);
        this->matrix[2][0] = sin(y);
        this->matrix[2][2] = cos(y);
        this->matrix[0][2] = -sin(y);
    }
    void RotateZ(double z, bool rads = false) {
        if (rads) z *= drx::rad;
        this->matrix[0][0] = cos(z);
        this->matrix[1][0] = -sin(z);
        this->matrix[1][1] = cos(z);
        this->matrix[0][1] = sin(z);
    }

    void Translate(double x, double y, double z) {
        this->matrix[3][0] = x;
        this->matrix[3][1] = y;
        this->matrix[3][2] = z;
    }

    void Scale(double x, double y, double z) {
        this->matrix[0][0] = x;
        this->matrix[1][1] = y;
        this->matrix[2][2] = z;
    }

    double* Pointer() {
        int c = 0;
        for (int x = 0; x < 4; x++) {
            for (int y = 0; y < 4; y++) {
                this->pointer[c] = this->matrix[x][y];
                c++;
            }
        }

        return this->pointer;
    }

    void Dump() {
        for (int x = 0; x < 4; x++) {
            for (int y = 0; y < 4; y++) {
                std::cout << "\n [" << x << ", " << y << "]: " << this->matrix[x][y];
            }
        }
    }
};

Which I'm then trying to pass onto OpenGL:

drx::util::MAT4 trans;
trans.LoadIdentity();
trans.RotateY(45.0, true);
trans.Dump(); // outputs values as should
glUseProgram(this->P);
glUniformMatrix4dv(glGetUniformLocation(this->P, "transform"), 1, GL_FALSE, trans.Pointer());
glUseProgram(0);

My shader looks like:

#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 inColor;

out vec3 ourColor;

uniform mat4 transform;

void main()
{
    gl_Position = transform * vec4(aPos, 1.0);
    ourColor = inColor;
} 

If I take out the transforms from shaders, my triangle draws fine. But if I use the transforms my triangle disappears, is it offscreen or what could be happening?

Trying to follow this tutorial on Youtube.

Update: glGetError() gives 1282

std::cout << "\n " << glGetError(); // 0
int loc = glGetUniformLocation(this->P, "transform");
std::cout << "\n " << glGetError(); // 0
glUniformMatrix4dv(loc, 1, GL_FALSE, trans.Pointer());
std::cout << "\n " << glGetError(); // 1282

Update 2: Tried with glm, same result, no drawing.

Update 3: location for uniform variable returns -1

int loc = glGetUniformLocation(this->P, "transform"); // -1

/* defs */
extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation");  
❌
❌