Projecting vectors

Home Forums Monkey 2 Programming Help Projecting vectors

This topic contains 6 replies, has 3 voices, and was last updated by  Mark Sibly 1 week ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10404

    Ethernaut
    Participant

    How do I take a Vec3 coordinate and “project” it onto the 2D camera plane?

    I’m trying to draw HUD elements on top of a 3D scene that stay locked to their 3D counterparts. Going through the modules I see that the camera has a Matrix and I can multiply the point by that, but I don’t know how to proceed from there and get the actual projected point as Vec2.

    Thanks!

    #10405

    Mark Sibly
    Keymaster

    Dividing a 3d point by it’s ‘z’ component will give you a 2d point at z=1.

    #10412

    Ethernaut
    Participant

    Ok, almost working…

    The line translates across the screen as the camera rotates, but at a different rate. I imagine this is because I’m using the camera’s Matrix but not the ProjectionMatrix, so the FOV is ignored. But a ProjectionMatrix is Mat4, and I don’t see any method there that could help me in this case. Or is there?

    #10414

    Mark Sibly
    Keymaster

    Ok, I think these camera methods are basically what you’re after? Adding to repos soon…

    You can added these as extensoin methods if you want, or butcher them for your own evil purposes.

    #10419

    nerobot
    Participant

    Is there a plan to add switcher for camera orthographic / perspective mode?

    #10420

    Ethernaut
    Participant

    Sweet! Thanks!

    Is there a plan to add switcher for camera orthographic / perspective mode?

    That would be great. I tried doing it by butchering the existing classes and failed miserably!

    Here’s the working version of the 3D lines example, if anyone is interested…

    #10427

    Mark Sibly
    Keymaster

    Yes, camera’ll eventually support orthographic, and hopefully stero one day!

    This is the nice thing about the 4×4 projection matrix – it supports both perspective and orthographic projections so the project/unproject code wont have to change.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.