Posts

Showing posts with the label Vector

3.1.1: A Walk Through A View Part 2

Image
Last time, we created two types that will provide us the ability to simply some code that would other wise appear very dense and complex.  Generally, I have tried to write these tutorials in such a way that each step is broken down to be readily understandable and approachable regardless of ones programming background.  Moving objects or moving one's point of view through three dimensional space, involves very complex math.  Part 1 of this tutorial was an attempt to make the math concepts understandable for use here in Part 2 and onward. Utilizing Vector3 and Matrix4 In SwiftOpenGLView.swift of the OnTheMove project, add a few new variables to the SwiftOpenGLView class after the declaration of the others:  cameraPosition, cameraOrientation, the view matrix and the projection matrix. var cameraPosition = Vector3 (v0: 0.0 , v1: 0.0 , v2: - 5 .0 ) var cameraOrientation = Vector3 (v0: 0.0 , v1: 0.0 , v2: 0.0 ) private var view = Matrix4 () private var...

3.1.0: A Walk Through the View Part 1

Image
Movement in three dimensions is not a quick and easy topic.  There are many difficult concepts involved and a lot of math.  To help us encapsulate the data and make it both easier to understand and to work with, we'll create two new types:  a vector and a matrix.  We will do a basic implementation  for each which we can develop further a later date.  Create a new target (not a duplicate) and call it OnTheMove.  Add our two new types to the SwiftOpenGLView.swift file right after the module imports. Vector3 Above the SwiftOpenGLView class, define a new struct called Vector3.  It will have three properties, numbered 0-2.  These may be used to represent x, y, z coordinates, or pitch, yaw, roll values, etc.  Swift does not have an equivalent Union type per se that allows us to define types whose property names change based upon which is allocated upon creation.  They do have enums which may, arguably, be an appropriate choice to impl...