# Commits

committed a51129f

Added last .svg images to Tutorial 4

• Participants
• Parent commits 79148ac
• Branches default

# File Documents/Positioning/GenRectViewFrustum.lua

+require "SvgWriter"
+require "vmath"
+
+local imageWidth, imageHeight = 500, 500;
+
+
+local ySin, yCos = math.sin(yAngle), math.cos(yAngle);
+local zSin, zCos = math.sin(zAngle), math.cos(zAngle);
+
+local yMat = vmath.mat4(
+	vmath.vec4(yCos, 0, ySin, 0),
+	vmath.vec4(0, 1, 0, 0),
+	vmath.vec4(-ySin, 0, yCos, 0),
+	vmath.vec4(0, 0, 0, 1))
+
+local zMat = vmath.mat4(
+	vmath.vec4(1, 0, 0, 0),
+	vmath.vec4(0, zCos, -zSin, 0),
+	vmath.vec4(0, zSin, zCos, 0),
+	vmath.vec4(0, 0, 0, 1))
+
+local worldScale = 0.1;
+
+local scalingMatrix = vmath.mat4(
+	vmath.vec4(worldScale, 0, 0, 0),
+	vmath.vec4(0, worldScale, 0, 0),
+	vmath.vec4(0, 0, worldScale, 0),
+	vmath.vec4(0, 0, 0, 1))
+
+local fullMat = (scalingMatrix * zMat) * yMat
+
+local function LocalTransform(listOfPoints)
+	local ret = {};
+	for i, point in ipairs(listOfPoints) do
+		ret[#ret + 1] = fullMat:Transform(point);
+	end
+
+	return ret;
+end
+
+local viewportMatrix = vmath.mat4(
+	vmath.vec4(imageWidth / 2, 0, 0, imageWidth / 2),
+	vmath.vec4(0, imageHeight / 2, 0, imageHeight / 2),
+	vmath.vec4(0, 0, 1, 0),
+	vmath.vec4(0, 0, 0, 1))
+
+local function ViewportTransform(listOfPoints)
+	local ret = {};
+	for i, point in ipairs(listOfPoints) do
+		ret[#ret + 1] = vmath.vec2(viewportMatrix:Transform(point));
+	end
+
+	return ret;
+end
+
+local initialBoxPoints = {
+	vmath.vec3(		 7.1,	 4.0,	 5.0),
+	vmath.vec3(		-7.1,	 4.0,	 5.0),
+	vmath.vec3(		 7.1,	-4.0,	 5.0),
+	vmath.vec3(		-7.1,	-4.0,	 5.0),
+	vmath.vec3(		 1.77,	 1.0,	-5.0),
+	vmath.vec3(		-1.77,	 1.0,	-5.0),
+	vmath.vec3(		 1.77,	-1.0,	-5.0),
+	vmath.vec3(		-1.77,	-1.0,	-5.0),
+}
+
+local initialAxisPoints =
+{
+	vmath.vec3(4.435, 0.0, 0.0),
+	vmath.vec3(10.0, 0.0, 0.0),
+
+	vmath.vec3(-4.435, 0.0, 0.0),
+	vmath.vec3(-10.0, 0.0, 0.0),
+
+	vmath.vec3(0.0, 2.5, 0.0),
+	vmath.vec3(0.0, 10.0, 0.0),
+
+	vmath.vec3(0.0, -2.5, 0.0),
+	vmath.vec3(0.0, -10.0, 0.0),
+
+	vmath.vec3(0.0, 0.0, 5.0),
+	vmath.vec3(0.0, 0.0, 10.0),
+
+	vmath.vec3(0.0, 0.0, -5.0),
+	vmath.vec3(0.0, 0.0, -10.0),
+}
+
+local boxPoints = ViewportTransform(LocalTransform(initialBoxPoints));
+local axisPoints = ViewportTransform(LocalTransform(initialAxisPoints));
+
+
+local boxIndexList =
+{
+	{2, 4, 8, 6},
+	{1, 2, 6, 5},
+	{1, 2, 4, 3},
+
+	{1, 3, 7, 5},
+	{3, 4, 8, 7},
+	{5, 6, 8, 7},
+}
+
+local boxList = {}
+
+for i, box in ipairs(boxIndexList) do
+	boxList[i] = {
+		boxPoints[box[1]],
+		boxPoints[box[2]],
+		boxPoints[box[3]],
+		boxPoints[box[4]]}
+end
+
+local styleLib = SvgWriter.StyleLibrary();
+
+	SvgWriter.Style():stroke("black"):stroke_width("1px"));
+
+	SvgWriter.Style():stroke_dasharray({3, 3}));
+
+
+	SvgWriter.Style():fill("black"));
+
+	SvgWriter.Style():fill("blue"):fill_opacity(0.1));
+
+
+
+
+
+local writer = SvgWriter.SvgWriter("RectViewFrustum.svg", {imageWidth .."px", imageHeight .. "px"}, true);
+	writer:StyleLibrary(styleLib);
+	writer:BeginDefinitions();
+		writer:BeginMarker({10, 8}, {10, 4}, "auto", nil, nil, "arrowhead");
+		writer:EndMarker();
+	writer:EndDefinitions();
+
+	--Draw the rear-most lines, with markers.
+	writer:Line(axisPoints[3], axisPoints[4], {"black", "arrowended"});
+	writer:Line(axisPoints[7], axisPoints[8], {"black", "arrowended"});
+	writer:Line(axisPoints[9], axisPoints[10], {"black", "arrowended"});
+
+	--Draw the rear-most box sides.
+	writer:Polygon(boxList[1], {"black", "fill_transluscent"});
+	writer:Polygon(boxList[2], {"black", "fill_transluscent"});
+	writer:Polygon(boxList[3], {"black", "fill_transluscent"});
+
+	--Draw the internal lines, no markers.
+	writer:Line(axisPoints[1], axisPoints[3], {"black", "dashed"});
+	writer:Line(axisPoints[5], axisPoints[7], {"black", "dashed"});
+	writer:Line(axisPoints[9], axisPoints[11], {"black", "dashed"});
+
+	--Draw the front-most boxes.
+	writer:Polygon(boxList[4], {"black", "fill_transluscent"});
+	writer:Polygon(boxList[5], {"black", "fill_transluscent"});
+	writer:Polygon(boxList[6], {"black", "fill_transluscent"});
+
+	--Draw the front-most lines, with markers.
+	writer:Line(axisPoints[1], axisPoints[2], {"black", "arrowended"});
+	writer:Line(axisPoints[5], axisPoints[6], {"black", "arrowended"});
+	writer:Line(axisPoints[11], axisPoints[12], {"black", "arrowended"});
+
+writer:Close();
+
+
+

# File Documents/Positioning/GenViewFrustum.lua

-local writer = SvgWriter.SvgWriter("ViewFrustum.svg", {imageWidth .."px", imageHeight .. "px"});
+local writer = SvgWriter.SvgWriter("ViewFrustum.svg", {imageWidth .."px", imageHeight .. "px"}, true);
writer:StyleLibrary(styleLib);
writer:BeginDefinitions();
writer:BeginMarker({10, 8}, {10, 4}, "auto", nil, nil, "arrowhead");

# File Documents/Positioning/Tutorial 04.xml

<para>Currently, our perspective matrix defines a square-shaped frustum. That is, the top
and bottom of the frustum (if it were visualized in camera space) would be squares. What
we need to do instead is create a rectangular frustum.</para>
-        <!--TODO: Create an image of a square frustum and a rectangular frustum.-->
+        <figure>
+            <title>Widescreen Aspect Ratio Frustum</title>
+            <mediaobject>
+                <imageobject>
+                    <imagedata fileref="RectViewFrustum.svg" format="SVG"/>
+                </imageobject>
+            </mediaobject>
+        </figure>
<para>We already have some control over the shape of the frustum. We said originally that we
-            did not need to move the eye position from (0, 0, -1), because we could simply scale the
-            X and Y positions of everything to achieve the same effect. We scale the X and Y by the
-            same value; this produces a uniform scale. It also produces a square frustum, as seen in
-            camera space. Since we want a rectangular frustum, we need to use a non-uniform scale,
-            where the X and Y positions are scaled by different values.</para>
+            did not need to move the eye position from the origin because we could simply scale the
+            X and Y positions of everything to achieve a similar effect. When we do this, we scale
+            the X and Y by the same value; this produces a uniform scale. It also produces a square
+            frustum, as seen in camera space. Since we want a rectangular frustum, we need to use a
+            non-uniform scale, where the X and Y positions are scaled by different values.</para>
<para>What this will do is show <emphasis>more</emphasis> of the world. But in what
direction do we want to show more? Human vision tends to be more horizontal than
vertical. This is why movies tend to use a minimum of 16:9 width:height aspect ratio