SlideShare a Scribd company logo
I'm looking for coding help I don't really need this to be explained
I'm currently trying to draw a grid and a cube but I also need that cube to rotate
issue is I've been given so much information at once and there are so many missing pieces
mostly do to it not being explained or I've forgotten how to do it that I'm just at a lost
Here's my current code
Defines.h
#pragma once
#define Width 500
#define Height 500
#define NumPixels (Width * Height)
unsigned colorArray[NumPixels];
void ColorBuffer(unsigned int color)
{
for (unsigned int i = 0; i < NumPixels; i++)
{
colorArray[i] = color;
}
}
void drawPixel(unsigned int x, unsigned int y, unsigned int color)
{
unsigned int index = convertCoords(x, y);
colorArray[index] = color;
}
struct Float4
{
union
{
struct
{
float V[4];
};
struct
{
float x;
float y;
float z;
float w;
};
};
};
struct Matrix4x4
{
union
{
struct
{
float V[16];
};
struct
{
float xx;
float xy;
float xz;
float xw;
float yx;
float yy;
float yz;
float yw;
float zx;
float zy;
float zz;
float zw;
float wx;
float wy;
float wz;
float ww;
};
struct
{
Float4 AxisX;
Float4 AxisY;
Float4 AxisZ;
Float4 AxisW;
};
};
};
struct Vertex {
Float4 Position;
unsigned int color;
};
MyMath.h
#pragma once
#include "Defines.h"
float DotProduct(Float4 v1, Float4 v2)
{
return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z) + (v1.w * v2.w);
}
Matrix4x4 MultiplyMatrixByMatrix(const matrix& m1, const matrix& m2)
{
Matrix4x4 mOut;
mOut.xx = DotProduct(m1.Row0, m2.Column0);
mOut.xy = DotProduct(m1.Row0, m2.Column1);
mOut.xz = DotProduct(m1.Row0, m2.Column2);
mOut.xw = DotProduct(m1.Row0, m2.Column3);
mOut.yx = DotProduct(m1.Row1, m2.Column0);
mOut.yy = DotProduct(m1.Row1, m2.Column1);
mOut.yz = DotProduct(m1.Row1, m2.Column2);
mOut.yw = DotProduct(m1.Row1, m2.Column3);
mOut.zx = DotProduct(m1.Row2, m2.Column0);
mOut.zy = DotProduct(m1.Row2, m2.Column1);
mOut.zz = DotProduct(m1.Row2, m2.Column2);
mOut.zw = DotProduct(m1.Row2, m2.Column3);
mOut.wx = DotProduct(m1.Row3, m2.Column0);
mOut.wy = DotProduct(m1.Row3, m2.Column1);
mOut.wz = DotProduct(m1.Row3, m2.Column2);
mOut.ww = DotProduct(m1.Row3, m2.Column3);
return mOut;
}
unsigned int convertCoords(unsigned int x, unsigned int y)
{
return y * Width + x;
}
RasterFunc.h
#pragma once
#include "Shaders.h"
// Draws a line using one of the line equations.
void DrawLine(const Vertex& start, const Vertex& end)
{
// Copy input data and send through shaders
Vertex copy_start = start;
Vertex copy_end = end;
// Use vertex shader to modify incoming copies only.
if (VertexShader)
{
VertexShader(copy_start);
VertexShader(copy_end);
}
// original plotting variables adapted to use new cartesian data
SCREEN_XY screen_start = CartesianToScreen(copy_start);
SCREEN_XY screen_end = CartesianToScreen(copy_end);
// Standard line drawing code follows using integer coordinates...
for (numPixels)
{
A_PIXEL copyColor = currColor; // Just like a Vertex, copy original.
if (PixelShader) PixelShader(copyColor); // Modify copy.
PlotPixel(currX, currY, copyColor); // Display the copy.
}
}
Shaders.h
#pragma once
#include "MyMath.h"
// The active vertex shader. Modifies an incoming vertex. Pre-Rasterization.
void (*VertexShader)(Vertex&) = 0;
// The active pixel shader. Modifies an outgoing pixel. Post-Rasterization.
void (*PixelShader)(A_PIXEL&) = 0;
// All Shader Variables (Always Pre-fixed by SV_)
Matrix4x4 SV_WorldMatrix;
// Various custom vertex and pixel shaders, (Pre-fixed by VS_ & PS_)
// Can be swapped using above function pointers as needed for flexibility.
// Applys the current world matrix to all
void VS_World(Vertex& multiplyMe)
{
MultiplyVertexByMatrix(multiplyMe, SV_WorldMatrix);
}
// Basic pixel shader returns the color white
void PS_White(A_PIXEL& makeWhite)
{
makeWhite = 0xFFFFFFFF;
}
Main.cpp
#include "RasterSurface.h"
#include
#include "Defines.h"
#include "RasterFunc.h"
int main()
{
RS_Initialize("", Width, Height);
do
{
ColorBuffer(0);
Matrix4x4 CubeWorldMatrix;
Matrix4x4 GridWorldMatrix;
SV_WorldMatrix = GridWorldMatrix;
} while (RS_Update(colorArray, NumPixels));
RS_Shutdown();
}
Below is all info given to me
// MATRIX/VECTOR MULTIPLY //I/////////////////////////////// Matrix-Matrix-Multiply (and also
Vector-Matrix-Multiply) can be thought of as a series of DotProducts, where each result in the
final matrix is the dot-product of the row from one matrix, and the column of another, that
intersect at the location of the result: matrix4x4 MultiplyMatrixByMatrix(const matrix &m1,
const matrix &m2) { matrix4x4 mOut; mOut. xx= DotProduct (m1. Row, m2. Column ); mOut.
xy=DotProduct(m1. Row, m2. Column1); ... m0ut. zy = DotProduct (m1. Row2, m2. Column1);
// need to do this for all 16 floats in mOut return mout; } float DotProduct(vec4 v1, vec4 v2)
{return(v1.xv2.x)+(v1.yv2.y)+(v1.zv2.z)+(v1.wv2.w);} float DotProduct(vec4 v1, vec4 v2) {
return (v1.xv2.x)+(v1.yv2y)+(v1.zv2.z)+(v1.wv2.w); } (edited) ////////////////////////////// //
ROTATING A MATRIX: Matrix mRotation = MakeRotationY(fRotateRate * fDeltaTime); //
the rotation increment for this frame only mCubeMatrix = MatrixMultiply(mRotation,
mCubeMatrix); // applies the rotation to the existing CubeMatrix
struct Vertex { Float4 Position; Float2 UV; // added later, would need to define Float2; unsigned
int Color; } ; Note that the size of the "Float4" struct is still only 16 bytes, or 4 floats. "V", and
"x,y,z,w" are just 2 different ways to access the same memory space, because everything inside
the union sits in the same memory location. So ".V[1]" and ".y" are the same thing. Setting one
would set the other. I also recommend having some sort of float4/vec4 struct that only contains 4
floats, and then have a separate "vertex" struct that contains a vec4, plus any other members the
Vertex struct needs to contain (UVs, Color, etc...), as shown in the example code above.
Here is an alternate version of Orthonormal Inverse (Fast Matrix Inverse). The math is ultimately
the same as the version in the slides, this is just a different way of conceptualiz
I////////////////////////////////////////////////// // ORTHONORMAL INVERSE (Fast Inverse)
I///////////////////////////////////////////////// matrix OrthonormalInverse(const matrix &mIn) { matrix m;
m=33 transpose of mIn; set default 0.05 and 1.0s for the.w components of m; // calculate new
position: m.AxisW.x =-DotProduct(mIn.Axisx, mIn.AxisW); // float3 dot product, not float 4
m.AxisW.y =-DotProduct(mIn.AxisY, mIn.AxisW); // float3 dot product, not float 4 m.AxisW.z
=-DotProduct(mIn.AxisZ, mIn.AxisW); // float3 dot product, not float 4 return m; } float
DotProduct(const vec3 &v1, const vec3 &v2) {return(v1.xv2.x)+(v1.yv2.y)+(v1.zv2.z);} float
DotProduct(const vec3 &v1, const vec3 &v2) { return (v1.xv2.x)+(v1.yv2.y)+(v1.zv2.z); }
struct Matrix 44 { union { struct f float v[16]; }; struct { float xx; float xy; float xz; float XW;
float yx; float yy; float yz; float yw; float zx; float zy; float zz; float zw; float wx; float wy; float
wz; float ww; }; struct f Float4 AxisX; Float4 AxisY; Float4 AxisZ; Float4 AxisW; }; ; };
struct Vertex { Float4 Position; Float2 UV; // added later, would need to define Float2; unsigned
int Color; };
JRAWING THE CUBE: nside the main while-loop, Set the VS_World matrix that is used by the
VertexShader to the Cube's world matrix that you created during initialization, and rotated
above. Then pass each of the cube's verts (actually a copy of each of the cube's verts) through the
VertexShader, which will use that world matrix to transform all the verts. Now you can do
NDCtoScreen() on each of the cube's verts, and use DrawLine() or FillTriangle() to draw the
Cube. PRAWING THE GRID: nside the main while-loop, Set the VS_World matrix that is used
by the VertexShader to the Grid's world matrix that you created during initialization. Then pass
each of the grid's rerts (actually a copy of each of the grid's verts) through the VertexShader,
which will use that world matrix to transform all the verts. Now you can do NDCtoScreen() on
each of the arid's verts, and use DrawLine() to draw the Grid. NORLD MATRICES PORTION
Norld Matrices for CGS Week 2 assignment: Create a World Matrix for the Grid, and initialize it
to identity. You can do this wherever you declare and initialize the verts for the grid. Create a
World Matrix for the Cube, and initialize it to identity. Then translate it up on the Y axis. You
can do this wherever you declare and initialize the verts for the cube. nside your main while-
loop: Each frame, slightly rotate the Cube's world matrix that you created above about its Y-axis.
To do this, you create a Y-rotation matrix with a small amount of rotation, and multiply it y the
existing Cube matrix. The result is a slightly-Y-rotated version of the cube matrix's previous
state.
1. First we should start by creating the vertex information for our grid and our cube. We need to
draw lines so take a few minutes to think about how many total vertices we will need for our
objects. The grid will be 1010. Meaning we will have 11 horizontal lines and 11 vertical lines. I
shouldn't have to go into a lot of detail about the cube, but if you are still confused on the total
amount of lines needed to draw a cube then I suggest drawing this out. 2. Keep in mind we
would like for the grid to be placed around the origin (0,0,0). For the cube, make sure to create it
around the origin as well but we will be translating this upwards by half of its height. 3. The grid
will have a total width of 1 and a total depth of 1 . (Hint: If we are placing this directly in the
middle of our screen, where would the left and right side of our grid be located) 4. The cube will
have a total width of 0.5 and height of 0.5 and lastly a depth of 0.5 . 5. Once we have our
geometry, the next step would be to create the world matrices for each. The world matrix for our
grid can be the identity. No translation, rotation, or scaling for this matrix needed. We simply
want the grid to be drawn at the origin.
recommended order of includes when you refactor your code for week 2:
// UNIONS/VERTEX/MATRIX STRUCTS struct Float4 { union { struct { float V[4]; };
struct { float x; float y; float z; float w; }; }; };
1) Before your while-loop, initialize the verts of the cube and store them in an array, 2) Inside
your while-loop, convert all the verts of the cube from NDC coordinates to pixel-coordinate,
using a function you write (NDCtoScreen()). 3) Also inside the while-loop, pass the converted
screen-space pixel coordinates to your DrawLine() function to connect them. At this point you
should see the cube as a square in the center of the screen, as shown in the '25%' portion of the
doc. BUILDING THE CUBE (CGS) The Cube should be declared either in global space, or in
main() BEFORE your main while loop, as an array of 8 verts. Verts are a structure you create.
The w's of each vert will always be initialized to 1.0. The cube has a total width, height, and
depth, of 0.5 , and it's centered about its own origin. So every vert on the cube, in local space,
will be {0.25f,0.25f,0.25f}, but with some combination of positive and negative values. So for
example, the Top-Left-Front vert would be: (0.25,0.25,0.25) negative X is left, positive Y is top,
and negative Z is near. You can initially just set up the 4 verts of the cube's near face, and try
drawing the 4 lines that connect them to form a square on-screen. (sdited)
Ad

More Related Content

Similar to Im looking for coding help I dont really need this to be explained.pdf (20)

Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++
Satalia
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
Philip Schwarz
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
Mohammad Shaker
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
AMD Developer Central
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
W M Harris
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
shelfrog
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
Mohamed Yaser
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
Philip Schwarz
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
Mark Kilgard
 
webgpu shader language (wgsl) and shaders - computer graphics
webgpu shader language (wgsl) and shaders - computer graphicswebgpu shader language (wgsl) and shaders - computer graphics
webgpu shader language (wgsl) and shaders - computer graphics
contact14711
 
How do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfHow do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdf
krishnac481
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
Ishin Vin
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
JinTaek Seo
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
tamillarasan
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
Naman Dwivedi
 
Will th ebelow code work andif not please help me fix it. Basically .pdf
Will th ebelow code work andif not please help me fix it. Basically .pdfWill th ebelow code work andif not please help me fix it. Basically .pdf
Will th ebelow code work andif not please help me fix it. Basically .pdf
michaelazach6427
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
PrabhakarSingh646829
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
Robyn Overstreet
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithm
KALAIRANJANI21
 
Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++
Satalia
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
Philip Schwarz
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
AMD Developer Central
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
W M Harris
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
shelfrog
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
Philip Schwarz
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
Mark Kilgard
 
webgpu shader language (wgsl) and shaders - computer graphics
webgpu shader language (wgsl) and shaders - computer graphicswebgpu shader language (wgsl) and shaders - computer graphics
webgpu shader language (wgsl) and shaders - computer graphics
contact14711
 
How do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfHow do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdf
krishnac481
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
Ishin Vin
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
JinTaek Seo
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
tamillarasan
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
Naman Dwivedi
 
Will th ebelow code work andif not please help me fix it. Basically .pdf
Will th ebelow code work andif not please help me fix it. Basically .pdfWill th ebelow code work andif not please help me fix it. Basically .pdf
Will th ebelow code work andif not please help me fix it. Basically .pdf
michaelazach6427
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithm
KALAIRANJANI21
 

More from contact41 (14)

Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdfNeed to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
contact41
 
Manufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdfManufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdf
contact41
 
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdfMake sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
contact41
 
John Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdfJohn Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdf
contact41
 
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdfJoe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
contact41
 
In the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdfIn the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdf
contact41
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
Imagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdfImagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdf
contact41
 
In September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdfIn September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdf
contact41
 
Im writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdfIm writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdf
contact41
 
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdfImagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
contact41
 
I. Common stocks increase. III. Accounts .pdf
I.   Common stocks increase.                         III.  Accounts .pdfI.   Common stocks increase.                         III.  Accounts .pdf
I. Common stocks increase. III. Accounts .pdf
contact41
 
Node file code below#ifndef NODE_H#define NODE_H#include .pdf
Node file code below#ifndef NODE_H#define NODE_H#include .pdfNode file code below#ifndef NODE_H#define NODE_H#include .pdf
Node file code below#ifndef NODE_H#define NODE_H#include .pdf
contact41
 
I. Inventories increase. III. Accounts rece.pdf
I.   Inventories increase.                     III.  Accounts rece.pdfI.   Inventories increase.                     III.  Accounts rece.pdf
I. Inventories increase. III. Accounts rece.pdf
contact41
 
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdfNeed to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
contact41
 
Manufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdfManufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdf
contact41
 
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdfMake sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
contact41
 
John Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdfJohn Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdf
contact41
 
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdfJoe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
contact41
 
In the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdfIn the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdf
contact41
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
Imagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdfImagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdf
contact41
 
In September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdfIn September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdf
contact41
 
Im writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdfIm writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdf
contact41
 
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdfImagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
contact41
 
I. Common stocks increase. III. Accounts .pdf
I.   Common stocks increase.                         III.  Accounts .pdfI.   Common stocks increase.                         III.  Accounts .pdf
I. Common stocks increase. III. Accounts .pdf
contact41
 
Node file code below#ifndef NODE_H#define NODE_H#include .pdf
Node file code below#ifndef NODE_H#define NODE_H#include .pdfNode file code below#ifndef NODE_H#define NODE_H#include .pdf
Node file code below#ifndef NODE_H#define NODE_H#include .pdf
contact41
 
I. Inventories increase. III. Accounts rece.pdf
I.   Inventories increase.                     III.  Accounts rece.pdfI.   Inventories increase.                     III.  Accounts rece.pdf
I. Inventories increase. III. Accounts rece.pdf
contact41
 
Ad

Recently uploaded (20)

K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Ad

Im looking for coding help I dont really need this to be explained.pdf

  • 1. I'm looking for coding help I don't really need this to be explained I'm currently trying to draw a grid and a cube but I also need that cube to rotate issue is I've been given so much information at once and there are so many missing pieces mostly do to it not being explained or I've forgotten how to do it that I'm just at a lost Here's my current code Defines.h #pragma once #define Width 500 #define Height 500 #define NumPixels (Width * Height) unsigned colorArray[NumPixels]; void ColorBuffer(unsigned int color) { for (unsigned int i = 0; i < NumPixels; i++) { colorArray[i] = color; } } void drawPixel(unsigned int x, unsigned int y, unsigned int color) { unsigned int index = convertCoords(x, y); colorArray[index] = color; } struct Float4 { union { struct { float V[4]; }; struct {
  • 2. float x; float y; float z; float w; }; }; }; struct Matrix4x4 { union { struct { float V[16]; }; struct { float xx; float xy; float xz; float xw; float yx; float yy; float yz; float yw; float zx; float zy; float zz; float zw; float wx; float wy; float wz; float ww; }; struct {
  • 3. Float4 AxisX; Float4 AxisY; Float4 AxisZ; Float4 AxisW; }; }; }; struct Vertex { Float4 Position; unsigned int color; }; MyMath.h #pragma once #include "Defines.h" float DotProduct(Float4 v1, Float4 v2) { return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z) + (v1.w * v2.w); } Matrix4x4 MultiplyMatrixByMatrix(const matrix& m1, const matrix& m2) { Matrix4x4 mOut; mOut.xx = DotProduct(m1.Row0, m2.Column0); mOut.xy = DotProduct(m1.Row0, m2.Column1); mOut.xz = DotProduct(m1.Row0, m2.Column2); mOut.xw = DotProduct(m1.Row0, m2.Column3); mOut.yx = DotProduct(m1.Row1, m2.Column0); mOut.yy = DotProduct(m1.Row1, m2.Column1); mOut.yz = DotProduct(m1.Row1, m2.Column2); mOut.yw = DotProduct(m1.Row1, m2.Column3); mOut.zx = DotProduct(m1.Row2, m2.Column0); mOut.zy = DotProduct(m1.Row2, m2.Column1); mOut.zz = DotProduct(m1.Row2, m2.Column2); mOut.zw = DotProduct(m1.Row2, m2.Column3); mOut.wx = DotProduct(m1.Row3, m2.Column0); mOut.wy = DotProduct(m1.Row3, m2.Column1);
  • 4. mOut.wz = DotProduct(m1.Row3, m2.Column2); mOut.ww = DotProduct(m1.Row3, m2.Column3); return mOut; } unsigned int convertCoords(unsigned int x, unsigned int y) { return y * Width + x; } RasterFunc.h #pragma once #include "Shaders.h" // Draws a line using one of the line equations. void DrawLine(const Vertex& start, const Vertex& end) { // Copy input data and send through shaders Vertex copy_start = start; Vertex copy_end = end; // Use vertex shader to modify incoming copies only. if (VertexShader) { VertexShader(copy_start); VertexShader(copy_end); } // original plotting variables adapted to use new cartesian data SCREEN_XY screen_start = CartesianToScreen(copy_start); SCREEN_XY screen_end = CartesianToScreen(copy_end); // Standard line drawing code follows using integer coordinates... for (numPixels) { A_PIXEL copyColor = currColor; // Just like a Vertex, copy original. if (PixelShader) PixelShader(copyColor); // Modify copy. PlotPixel(currX, currY, copyColor); // Display the copy. } }
  • 5. Shaders.h #pragma once #include "MyMath.h" // The active vertex shader. Modifies an incoming vertex. Pre-Rasterization. void (*VertexShader)(Vertex&) = 0; // The active pixel shader. Modifies an outgoing pixel. Post-Rasterization. void (*PixelShader)(A_PIXEL&) = 0; // All Shader Variables (Always Pre-fixed by SV_) Matrix4x4 SV_WorldMatrix; // Various custom vertex and pixel shaders, (Pre-fixed by VS_ & PS_) // Can be swapped using above function pointers as needed for flexibility. // Applys the current world matrix to all void VS_World(Vertex& multiplyMe) { MultiplyVertexByMatrix(multiplyMe, SV_WorldMatrix); } // Basic pixel shader returns the color white void PS_White(A_PIXEL& makeWhite) { makeWhite = 0xFFFFFFFF; } Main.cpp #include "RasterSurface.h" #include #include "Defines.h" #include "RasterFunc.h" int main() { RS_Initialize("", Width, Height); do { ColorBuffer(0); Matrix4x4 CubeWorldMatrix; Matrix4x4 GridWorldMatrix;
  • 6. SV_WorldMatrix = GridWorldMatrix; } while (RS_Update(colorArray, NumPixels)); RS_Shutdown(); } Below is all info given to me // MATRIX/VECTOR MULTIPLY //I/////////////////////////////// Matrix-Matrix-Multiply (and also Vector-Matrix-Multiply) can be thought of as a series of DotProducts, where each result in the final matrix is the dot-product of the row from one matrix, and the column of another, that intersect at the location of the result: matrix4x4 MultiplyMatrixByMatrix(const matrix &m1, const matrix &m2) { matrix4x4 mOut; mOut. xx= DotProduct (m1. Row, m2. Column ); mOut. xy=DotProduct(m1. Row, m2. Column1); ... m0ut. zy = DotProduct (m1. Row2, m2. Column1); // need to do this for all 16 floats in mOut return mout; } float DotProduct(vec4 v1, vec4 v2) {return(v1.xv2.x)+(v1.yv2.y)+(v1.zv2.z)+(v1.wv2.w);} float DotProduct(vec4 v1, vec4 v2) { return (v1.xv2.x)+(v1.yv2y)+(v1.zv2.z)+(v1.wv2.w); } (edited) ////////////////////////////// // ROTATING A MATRIX: Matrix mRotation = MakeRotationY(fRotateRate * fDeltaTime); // the rotation increment for this frame only mCubeMatrix = MatrixMultiply(mRotation, mCubeMatrix); // applies the rotation to the existing CubeMatrix struct Vertex { Float4 Position; Float2 UV; // added later, would need to define Float2; unsigned
  • 7. int Color; } ; Note that the size of the "Float4" struct is still only 16 bytes, or 4 floats. "V", and "x,y,z,w" are just 2 different ways to access the same memory space, because everything inside the union sits in the same memory location. So ".V[1]" and ".y" are the same thing. Setting one would set the other. I also recommend having some sort of float4/vec4 struct that only contains 4 floats, and then have a separate "vertex" struct that contains a vec4, plus any other members the Vertex struct needs to contain (UVs, Color, etc...), as shown in the example code above. Here is an alternate version of Orthonormal Inverse (Fast Matrix Inverse). The math is ultimately the same as the version in the slides, this is just a different way of conceptualiz I////////////////////////////////////////////////// // ORTHONORMAL INVERSE (Fast Inverse) I///////////////////////////////////////////////// matrix OrthonormalInverse(const matrix &mIn) { matrix m; m=33 transpose of mIn; set default 0.05 and 1.0s for the.w components of m; // calculate new position: m.AxisW.x =-DotProduct(mIn.Axisx, mIn.AxisW); // float3 dot product, not float 4 m.AxisW.y =-DotProduct(mIn.AxisY, mIn.AxisW); // float3 dot product, not float 4 m.AxisW.z =-DotProduct(mIn.AxisZ, mIn.AxisW); // float3 dot product, not float 4 return m; } float DotProduct(const vec3 &v1, const vec3 &v2) {return(v1.xv2.x)+(v1.yv2.y)+(v1.zv2.z);} float DotProduct(const vec3 &v1, const vec3 &v2) { return (v1.xv2.x)+(v1.yv2.y)+(v1.zv2.z); } struct Matrix 44 { union { struct f float v[16]; }; struct { float xx; float xy; float xz; float XW; float yx; float yy; float yz; float yw; float zx; float zy; float zz; float zw; float wx; float wy; float wz; float ww; }; struct f Float4 AxisX; Float4 AxisY; Float4 AxisZ; Float4 AxisW; }; ; }; struct Vertex { Float4 Position; Float2 UV; // added later, would need to define Float2; unsigned int Color; }; JRAWING THE CUBE: nside the main while-loop, Set the VS_World matrix that is used by the VertexShader to the Cube's world matrix that you created during initialization, and rotated above. Then pass each of the cube's verts (actually a copy of each of the cube's verts) through the VertexShader, which will use that world matrix to transform all the verts. Now you can do NDCtoScreen() on each of the cube's verts, and use DrawLine() or FillTriangle() to draw the Cube. PRAWING THE GRID: nside the main while-loop, Set the VS_World matrix that is used by the VertexShader to the Grid's world matrix that you created during initialization. Then pass each of the grid's rerts (actually a copy of each of the grid's verts) through the VertexShader, which will use that world matrix to transform all the verts. Now you can do NDCtoScreen() on each of the arid's verts, and use DrawLine() to draw the Grid. NORLD MATRICES PORTION Norld Matrices for CGS Week 2 assignment: Create a World Matrix for the Grid, and initialize it to identity. You can do this wherever you declare and initialize the verts for the grid. Create a
  • 8. World Matrix for the Cube, and initialize it to identity. Then translate it up on the Y axis. You can do this wherever you declare and initialize the verts for the cube. nside your main while- loop: Each frame, slightly rotate the Cube's world matrix that you created above about its Y-axis. To do this, you create a Y-rotation matrix with a small amount of rotation, and multiply it y the existing Cube matrix. The result is a slightly-Y-rotated version of the cube matrix's previous state. 1. First we should start by creating the vertex information for our grid and our cube. We need to draw lines so take a few minutes to think about how many total vertices we will need for our objects. The grid will be 1010. Meaning we will have 11 horizontal lines and 11 vertical lines. I shouldn't have to go into a lot of detail about the cube, but if you are still confused on the total amount of lines needed to draw a cube then I suggest drawing this out. 2. Keep in mind we would like for the grid to be placed around the origin (0,0,0). For the cube, make sure to create it around the origin as well but we will be translating this upwards by half of its height. 3. The grid will have a total width of 1 and a total depth of 1 . (Hint: If we are placing this directly in the middle of our screen, where would the left and right side of our grid be located) 4. The cube will have a total width of 0.5 and height of 0.5 and lastly a depth of 0.5 . 5. Once we have our geometry, the next step would be to create the world matrices for each. The world matrix for our grid can be the identity. No translation, rotation, or scaling for this matrix needed. We simply want the grid to be drawn at the origin. recommended order of includes when you refactor your code for week 2: // UNIONS/VERTEX/MATRIX STRUCTS struct Float4 { union { struct { float V[4]; }; struct { float x; float y; float z; float w; }; }; }; 1) Before your while-loop, initialize the verts of the cube and store them in an array, 2) Inside your while-loop, convert all the verts of the cube from NDC coordinates to pixel-coordinate, using a function you write (NDCtoScreen()). 3) Also inside the while-loop, pass the converted screen-space pixel coordinates to your DrawLine() function to connect them. At this point you should see the cube as a square in the center of the screen, as shown in the '25%' portion of the doc. BUILDING THE CUBE (CGS) The Cube should be declared either in global space, or in main() BEFORE your main while loop, as an array of 8 verts. Verts are a structure you create. The w's of each vert will always be initialized to 1.0. The cube has a total width, height, and depth, of 0.5 , and it's centered about its own origin. So every vert on the cube, in local space, will be {0.25f,0.25f,0.25f}, but with some combination of positive and negative values. So for
  • 9. example, the Top-Left-Front vert would be: (0.25,0.25,0.25) negative X is left, positive Y is top, and negative Z is near. You can initially just set up the 4 verts of the cube's near face, and try drawing the 4 lines that connect them to form a square on-screen. (sdited)