About Monkey 2 › Forums › Monkey 2 Programming Help › [Mojo3d] World to Screen / TransformVector
This topic contains 5 replies, has 2 voices, and was last updated by
Ethernaut
1 year, 3 months ago.
-
AuthorPosts
-
January 8, 2018 at 8:55 pm #12760
Hey there,
another question: In mojo3d how can I get the screen coordinates of a 3d object which is within the camera’s FOV?
And: How do I transform a vector/point from local to world space and vice versa? Just having BlitzBasic3d in mind and those commands were very handy! Thanks!
January 9, 2018 at 7:57 am #12768Sorry for bumping. No idea so far? I’d need the screen coordinates of enemy vessels for my HUD. What I basically want to achieve is something like this (screen is from my BB3D project):
And that TransformVector stuff is very handy for all those torpedo targeting projection stuff…
I’d love to use mx2 with mojo3d for this.
THANKS!
Attachments:
January 9, 2018 at 8:05 am #12770I started work on a wireframe renderer a while ago, but never finished it.
It used “Camera.ProjectToViewPort( Vec3f )” to work. Haven’t tried it in a while, maybe still works…Monkey123456789101112131415Class Canvas ExtensionMethod Draw3DLine( camera:Camera, v0:Vec3f, v1:Vec3f, offsetX:Float=0, offsetY:Float=0 )Local s0 := camera.ProjectToViewport( v0 )Local s1 := camera.ProjectToViewport( v1 )If( ( Abs(s0.X) / camera.Viewport.Width ) < 2.0 )And ( ( Abs(s0.Y) / camera.Viewport.Height ) < 2.0 )If( ( Abs(s1.X) / camera.Viewport.Width ) < 2.0 )And ( ( Abs(s1.Y) / camera.Viewport.Height ) < 2.0 )If camera.Viewport.Contains( s0 , s1 )DrawLine( s0.X-offsetX, -s0.Y+offsetY, s1.X-offsetX, -s1.Y+offsetY )EndEndEndEndEndJanuary 9, 2018 at 9:41 am #12773Awesome, thanks! Should look into all those classes. I think I’m going to write all this down and create kind of a “how to start with mojo3d” document at some point.
January 10, 2018 at 5:10 am #12791Actually, you can remove the “If( ( Abs(s0.X) / camera.Viewport.Width ) < 2.0 )And ( ( Abs(s0.Y) / camera.Viewport.Height ) < 2.0 )” lines…
The only reason I have those is because I use coordinates (0,0) at the center of the screen, not at the corner… you can just remove those checks.
Here’s how it looks like when you feed that method all the points in a mesh.
(The render time is usually around a millisecond… I think the screen capture messed it up).
I never got backface culling working, though. Now that I think about it… how would you do that? Hmmm…
Cheers!January 10, 2018 at 5:16 am #12792Oh, and the best way to “inspect” mojo classes, in my opinion, is from within Ted2Go!
You can go to the “docs” tab, move it to the side dock (yes you can dock it!) and start typing the class you want, with the namespace in it, like “mojo3d.mesh” (capitalization doesn’t seem to matter) and hit enter. Every time you hit enter, a similar result will be shown.
Hitting F1 twice with the cursor in a keyword also works. Not always, though. Typing the namespace seems more consistent.
Cheers.
-
AuthorPosts
You must be logged in to reply to this topic.
