ScratchData LogoScratchData
Back to DadOfMrLog's profile

3D Engine -part 5 (structures, components, rotations, shifts)

DADadOfMrLog•Created April 12, 2013
3D Engine -part 5 (structures, components, rotations, shifts)
119
86
3555 views
View on Scratch

Instructions

******************************************** More steps for the 3D engine in this studio: http://scratch.mit.edu/studios/202972 ******************************************** Use arrow keys & WASD to fly the ships (taken from the InterXeptor 3D game) through the starfield. Hit space to switch between controlling the camera and each ship. Hit R to reset the camera or ship to its original position & orientation. This step of the 3D Engine shows how to define distinct 3D objects (called "structures" in the project) via points, lines, surfaces & volumes. And then to control these objects in 3D using rotations and position shifts applied to the points of the structure during the transformation to camera viewpoint. It is at this point that we are beginning to have a true 3D Engine, rather than just a demonstration of some rotating 3D object, because we can control such structures, and the camera viewpoint, as independent objects within a real 3D game.

Description

==== NOTE : Drag "Frame Pause" slider to zero ==== ** Scratch 3 has messed up the "timer" block during non-refresh, so timing for the 'frame pause' fails... :( ======================================== The structures that make up the ships are defined in the "Setup Structures" sprite in terms of points, lines, surfaces & volumes. This methodology is basically the same as that used in InterXeptor. Various blocks inside the "Change Structures" sprite allow manipulation of the structures (i.e. the ships) in 3D space - moving and rotating in any way desired. All of the rotation and movement of a structure is performed in such a way that it is relative to that structure's notion of 'forwards', 'right', 'up', 'horizontal angle', 'vertical angle', 'roll angle'. This makes it much simpler to move something around from its point of view, rather than having to work through how it needs to move or rotate via the fixed axes in which the structure's points are originally defined. Also, applying rotations and shifts to a structure's points, which remain fixed, is (usually) more efficient than changing all the point locations in the points list, since a rotation and shift has only 12 components, whereas a structure may have lots of points (any more than 4 points means more than 12 components). [For very small items that move in a simple way, for example a single line of a laserbolt moving forward, it is quicker to manipulate the actual point locations, so better not to define via a structure.] See inside for many more explanatory comments. What is still to come in subsequent steps: >> clipping of surfaces that intersect the minimum render Z plane (at the moment, if you fly the camera through a ship, you may notice some things go wrong - clipping the surfs will clear that up); >> filling the surfaces (as seen in InterXeptor); >> lighting the surfaces and lines (yes, lines need lighting!) >> sorting the render, to ensure things that are further away do not get drawn on top of things that are closer.

Project Details

Project ID10109256
CreatedApril 12, 2013
Last ModifiedMay 21, 2021
SharedApril 17, 2013
Visibilityvisible
CommentsAllowed