![]() |
Wanted: Very Simple 3D system - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Wanted: Very Simple 3D system (/showthread.php?tid=2451) |
Wanted: Very Simple 3D system - bplus - 02-15-2024 By very simple I mean convert and x,y,z coordinate in 3D array to an x,y screen coordinate such that we sim a 3D eg, SUB Sim3D(xyzPointInFromArray, xyPointOutToScreenGraph) Mainly we need this to use for _MapTriangle to wall cubes with triangles (2 per face) I think there is some simple formula that does sin and/or cos with x combined with z and another for y combined with z. RE: Wanted: Very Simple 3D system - dbox - 02-15-2024 Hey @bplus, I don't know if this is exactly what you are looking for or not, but I was reminded of this 3D library that someone in the QB64 community created: https://github.com/creamcast/3D-Library-for-QB64 I haven't used it myself but it looks like it provides a relatively easy to use API that can load 3d objects and manipulate the camera more easily that using straight _MapTriangle or _gl* calls. RE: Wanted: Very Simple 3D system - bplus - 02-15-2024 +1 Great link, thanks @dbox Wow look at those screen shots! Yikes .bm alone 600+ LOC Dang, I was hoping for something simpler but I do see possibles there. RE: Wanted: Very Simple 3D system - vince - 02-15-2024 hello B+, there are two options, the easiest is parallel projection and the trickier but more realistic one is perspective projection say you have 3D coord variables x, y, z and you wish to convert them to 2D coords, lets call them p, q for parallel: p = x + 0.7*z q = y + 0.7*z where 0.7 is a kind of arbitrary number which you can mod until it looks right for perspective p = x * d/z q = y * d/z where d is like a field of vision value that corresponds to the relative distance between your eye and the monitor (the plane of projection) and getting these values correct requires a bit of math or a lot of modding -- consider an offset to prevent negative z or a division by zero. I usually use the former to do something like a quick plot to get an idea and will mod my way to the latter for more serious mods. see SUB proj in the following example Code: (Select All) defdbl a-z speaking of maptriangle, its been on my backburner to translate that over to QBJS but I ran into a few brick walls due to my lack of JS (not JB) knowledge, mainly the image loading and webGL stuff, and kinda lost interest, but there has been some renewed interest in webGL in one of the math communities i'm into so I may give that another shot in the near future. I was able to at least find the formula to match 3D to 2D coordinates 1:1 with QB64's maptri and can share that mod if there's interest RE: Wanted: Very Simple 3D system - bplus - 02-15-2024 +1 Thanks vince, you, dbox, MasterGy and ubi44 have given me plenty to ponder. RE: Wanted: Very Simple 3D system - Abazek - 02-16-2024 Thanks vince! Great and concise explanation of Parallel Projection and Perspective Projection, and nice code to demo it! RE: Wanted: Very Simple 3D system - bplus - 02-19-2024 Hey @vince I started digging into your 128 LOC above. And i am trying to imagine the setup of this pyramid. You explained d as distance eye is from monitor = projection screen. what are z0, oy? a is some rotation angle but whch way around like clock hands on wall, central axis of merry-go-round? or around x axis BTW where is origin for "real" and projected image? Best way might to describe setup is a sheet of glass in front of model and we trace lines on the glass of what we see behind glass. The other way is have model in front of projection screen and from eye point we draw lines from model points onto projection screen behind, ha! like see through shadows ![]() Is the pyramid in front of projection screen, behind it or split somewhere through plane of projection screen i am imaging vertical x, y like movie screen and actual object in from or back or split by screen. The base would have all positive coordinates y = 0 at top y near height of screen a bottom the base where are the negative numbers coming from here: dim x(5), y(5), z(5) x( 0) = 0: y( 0) = 70: z( 0) = 0 x( 1) = 70: y( 1) =-70: z( 1) = 70 x( 2) =-70: y( 2) =-70: z( 2) = 70 x( 3) =-70: y( 3) =-70: z( 3) =-70 x( 4) = 70: y( 4) =-70: z( 4) =-70 x( 5) = 70: y( 5) =-70: z( 5) = 70 also I put a Sleep command before the loop around command and looking at the very first appearance of our pyramid, something looks wrong! It is impossible to be real pyramid with square base: RE: Wanted: Very Simple 3D system - bplus - 02-19-2024 Damn i thought I could sketch in Paint, my mistake I need a quick QB64 app. If we are seeing bottom base of Pryramid the top line of base should be slightly longer than back parallel line at base bottom most and the right corner is top line not bottom, assuming the left lower corner is correct. ![]() Code: (Select All) _Title "Quick Sketch" ' b+ 2024-02-19 RE: Wanted: Very Simple 3D system - bert22306 - 02-19-2024 Here's driving down a road at night. I just kinda fudged the 3D stuff. Code: (Select All) Dim x(200), y(200) RE: Wanted: Very Simple 3D system - vince - 02-20-2024 (02-19-2024, 11:17 AM)bplus Wrote: Hey @vince I started digging into your 128 LOC above. And i am trying to imagine the setup of this pyramid.the object is behind the projection screen, so anything behind it is z > 0. But having the requirement of z>0 can be annoying to work with so I add a z0 offset to allow for negative z for things like rotation, shifting the axis over so you can rotate around the x, y, or z axis without having to shift it over to the middle of the pyramid every time. oy in this case looks to be another offset, to give it more of a top down view rather than a straight ahead which can look strange. rot x, y, a will rotate points x and y around the z axis in the +a direction, you can call it counter clockwise or, more precisely, defer to the right hand rule |