Skip to content

graphene_matrix_init_look_at() inverted and upside down #288

Description

@sta-c0000

graphene v1.10.8

Hello and thank you for graphene.
I was trying it out this weekend. It appears graphene_matrix_init_look_at() actually produces an inverted view matrix, ok, but with a negated eye translation vector, which doesn't make sense to me. For an inverted view matrix I would expect the eye translation vector to not be negated.

here: /include/graphene-simd4x4f.h

m->w = graphene_simd4f_init (-eye_v[0], -eye_v[1], -eye_v[2], 1.f);

Unless I'm missing something? I wonder if it's a quirk related to GTK's 2D coords Y+ pointing down? But here in 3D all axes flip upside down; the look_at source states coords: X+ right, Y+ up, Z+ towards us (same as OpenGL). And normally we project to NDC first then flip Y if needed while converting to screen space.

To illustrate, see NOTEs in this barebones graphene 3D to 2D projection example: graphene-3d-svg.c

Seems it's been like that for a long time, I guess it won't change. I'm just noting it here for others that may bang their head. Don't know how used it is. Appears gthree has a single call to graphene_matrix_init_look_at, converting the resulting matrix to a quaternion, effectively throwing away the translation.

Thank you for your time.

p.s.: I started by prototyping in Python, but it segmentation faults whenever graphene returns an array with more than 4 elements. I understand not a graphene issue, but an introspection one (#11) . Confirmed with valgrind --tool=memcheck

import gi
gi.require_version("Graphene", "1.0")
from gi.repository import Graphene

rect = Graphene.Rect.alloc().init(-0.5,-0.5,1,1)
verts = rect.get_vertices() # malloc issue!

p_max = Graphene.Point3D.alloc().init(0.5,0.5,0.5)
p_min = p_max.scale(-1)
box = Graphene.Box.alloc().init(p_max, p_min)
verts = box.get_vertices() # malloc issue!

m = Graphene.Matrix.alloc().init_identity()
mat = m.to_float() # malloc issue!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions