hismailbulut / Neoray

Simple and lightweight GUI client for Neovim
MIT License
144 stars 5 forks source link

Camera Perspective in 2D Grid Rendering #47

Open fefa4ka opened 9 months ago

fefa4ka commented 9 months ago

I'm interested in exploring the possibility of adjusting the camera perspective to simulate different angles in a 2D space. My goal is to achieve a more dynamic visual experience within the existing 2D rendering framework.

After some research and experimentation, I made modifications to the SetProjection in grid_renderer.go, Render method in buffer.go to update the projection matrix using the SetProjection method in the VertexBuffer. I adjusted the fovy (field of view angle) to try to simulate different camera angles.

In grid_renderer.go:

func perspectiveProjection(fovy, aspect, near, far float32) [16]float32 {
    f := 1.0 / float32(math.Tan(float64(fovy/2.0)))
    return [16]float32{
        f / aspect, 0, 0, 0,
        0, f, 0, 0,
        0, 0, (far + near) / (near - far), -1,
        0, 0, (2 * far * near) / (near - far), 0,
    }
}

func (buffer *VertexBuffer) SetProjection(fovy, aspect, near, far float32) {
    projection := perspectiveProjection(fovy, aspect, near, far)
    loc := buffer.shader.UniformLocation("projection")
    gl.UniformMatrix4fv(loc, 1, true, &projection[0])
}

in buffer.go

func (renderer *GridRenderer) Render() {
    // ... (previous code)

    // Calculate perspective parameters based on your requirements
    fovy := float32(math.Pi / 4) // Field of view angle
    aspect := float32(Editor.window.Size().X) / float32(Editor.window.Size().Y) // Aspect ratio
    near := 0.1 // Near clipping plane
    far := 100.0 // Far clipping plane

    renderer.buffer.SetProjection(fovy, aspect, near, far)

    // ... (remaining code)
}

Unfortunately, these changes seem to have no effect, I'm not entirely sure if this is the correct approach or if it's even feasible to adjust the camera perspective in a 2D rendering scenario. I wanted to reach out to the authors to seek your guidance and expertise on this matter.

Questions:

hismailbulut commented 9 months ago

The rendering process is mostly hardcoded and I thing we need a proper 3d rendering in order to see result or understand why it doesn't work. It isn't hard but you may need to rewrite the rendering process in order to achieve what you want. I am really looking forward to see results if you work on this. Some of the things you need to know:

These are the ones I remember right now. Feel free to ask questions