ScratchData LogoScratchData
Back to DadOfMrLog's profile

3D Engine -part 4 (drawing 'thick' lines)

DADadOfMrLog•Created April 6, 2013
3D Engine -part 4 (drawing 'thick' lines)
88
57
2977 views
View on Scratch

Instructions

******************************************** More steps for the 3D engine in this studio: http://scratch.mit.edu/studios/202972 ******************************************** The 4th of these 3D Engine projects shows how to draw a 'thick' 3D line in such a way that the part nearer the camera appears thicker, and the part further away appears thinner - just as the laser bolts appear in MrLog's InterXeptor 3D space game. This step just takes the previous project's starfield (with very slight modification), and adds some 3D lines. Use the arrow keys and WASD to fly through the stars and follow the pointers home :) Hit space to reset the camera back to your starting point.

Description

* UPDATE * - added frame pause variable, which sets the amount of time it waits for between frames. If you experience lag while pressing keys (and you've already switched off/minimised your key-repeat rate), try bumping this up a bit (might need to wait a few secs after changing it so your machine can catch up...) After the first three parts of this 3D Engine, we now have everything in place to make this part fairly straightforward: we know how to transform a point's 3D co-ordinates to camera's P.o.V. 3D co-ordinates when moving the camera around (part 3); how to project from camera P.o.V. 3D co-ordinates to 2D screen (part 2); how to work out the size a sphere or disc at a given distance should appear on-screen (also part 2); and now we finally get to use the "draw-off-edge-of-screen" custom pen blocks that were introduced in the very first part. All that's needed here, then, is to draw a 3D line in segments, such that the pen-size for a segment changes as the segment's distance from the camera changes. See the "Render 3D Line" custom block (far right of scripts), and its comments. Note there's no ordering here yet (still to come...), so if you draw an object with different colour lines within the project as it is now, it can look a bit odd from certain angles.

Project Details

Project ID10103602
CreatedApril 6, 2013
Last ModifiedApril 6, 2013
SharedApril 7, 2013
Visibilityvisible
CommentsAllowed