Commits

Jason McKesson committed a51129f

Added last .svg images to Tutorial 4

Comments (0)

Files changed (5)

Documents/Positioning/GenRectViewFrustum.lua

+require "SvgWriter"
+require "vmath"
+
+local imageWidth, imageHeight = 500, 500;
+
+local yAngle = math.rad(45);
+local zAngle = math.rad(20);
+
+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();
+
+styleLib:AddStyle(nil, "black",
+	SvgWriter.Style():stroke("black"):stroke_width("1px"));
+	
+styleLib:AddStyle(nil, "dashed",
+	SvgWriter.Style():stroke_dasharray({3, 3}));
+	
+	
+styleLib:AddStyle(nil, "fill_black",
+	SvgWriter.Style():fill("black"));
+	
+styleLib:AddStyle(nil, "fill_transluscent",
+	SvgWriter.Style():fill("blue"):fill_opacity(0.1));
+
+styleLib:AddStyle(nil, "arrowended",
+	SvgWriter.Style():marker_end(SvgWriter.uriLocalElement("arrowhead")));
+
+local arrowheadPath = SvgWriter.Path();
+arrowheadPath:M{10, 4}:L{0, 0}:L{0, 8}:Z();
+
+
+	
+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:Path(arrowheadPath, "black");
+		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();
+
+
+

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");
Add a comment to this file

Documents/Positioning/RectViewFrustum.svg

Added
New image
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" height="500px" width="500px" viewbox="0 0 500 500" >
+	<style type="text/css" ><![CDATA[.fill_transluscent
+{
+	fill-opacity: 0.1;
+	fill: blue;
+}
+
+.dashed
+{
+	stroke-dasharray: 3,3;
+}
+
+.fill_black
+{
+	fill: black;
+}
+
+.black
+{
+	stroke-width: 1px;
+	stroke: black;
+}
+
+.arrowended
+{
+	marker-end: url(#arrowhead);
+}]]></style>
+	<defs >
+		<marker markerWidth="10" markerHeight="8" refX="10" refY="4" markerUnits="strokeWidth" orient="auto" id="arrowhead" >
+			<path d="M 10 4 L 0 0 L 0 8 Z" class="black" />
+		</marker>
+	</defs>
+	<line x2="73.223304703363" y2="189.53880933801" y1="223.18546194141" x1="171.59953563594" class="black arrowended" />
+	<line x2="250" y2="15.076844803523" y1="191.26921120088" x1="250" class="black arrowended" />
+	<line x2="426.77669529664" y2="189.53880933801" y1="219.769404669" x1="338.38834764832" class="black arrowended" />
+	<polygon points="212.87689398771,270.81122137758 212.87689398771,82.872697220397 130.32217728418,246.03664906418 130.32217728418,293.02128010347" class="black fill_transluscent" />
+	<polygon points="463.89980130893,356.66611211761 212.87689398771,270.81122137758 130.32217728418,293.02128010347 192.90112741919,314.42454159782" class="black fill_transluscent" />
+	<polygon points="463.89980130893,356.66611211761 212.87689398771,270.81122137758 212.87689398771,82.872697220397 463.89980130893,168.72758796043" class="black fill_transluscent" />
+	<line x2="171.59953563594" y2="223.18546194141" y1="276.81453805859" x1="328.40046436406" class="black dashed" />
+	<line x2="250" y2="191.26921120088" y1="308.73078879912" x1="250" class="black dashed" />
+	<line x2="161.61165235168" y2="280.230595331" y1="219.769404669" x1="338.38834764832" class="black dashed" />
+	<polygon points="463.89980130893,356.66611211761 463.89980130893,168.72758796043 192.90112741919,267.43991055852 192.90112741919,314.42454159782" class="black fill_transluscent" />
+	<polygon points="463.89980130893,168.72758796043 212.87689398771,82.872697220397 130.32217728418,246.03664906418 192.90112741919,267.43991055852" class="black fill_transluscent" />
+	<polygon points="192.90112741919,314.42454159782 130.32217728418,293.02128010347 130.32217728418,246.03664906418 192.90112741919,267.43991055852" class="black fill_transluscent" />
+	<line x2="426.77669529664" y2="310.46119066199" y1="276.81453805859" x1="328.40046436406" class="black arrowended" />
+	<line x2="250" y2="484.92315519648" y1="308.73078879912" x1="250" class="black arrowended" />
+	<line x2="73.223304703363" y2="310.46119066199" y1="280.230595331" x1="161.61165235168" class="black arrowended" />
+</svg>

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
Add a comment to this file

Documents/Positioning/ViewFrustum.svg

Old
Old image
New
New image
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
 
-<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" height="500px" width="500px" >
-	<style type="text/css" ><![CDATA[.fill_transluscent
-{
-	fill-opacity: 0.1;
-	fill: blue;
-}
-
-.dashed
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" height="500px" width="500px" viewbox="0 0 500 500" >
+	<style type="text/css" ><![CDATA[.dashed
 {
 	stroke-dasharray: 3,3;
 }
 	stroke: black;
 }
 
+.fill_transluscent
+{
+	fill-opacity: 0.1;
+	fill: blue;
+}
+
 .arrowended
 {
 	marker-end: url(#arrowhead);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.