diff options
author | KT <tran0563@umn.edu> | 2021-09-21 10:05:57 -0500 |
---|---|---|
committer | KT <tran0563@umn.edu> | 2021-09-21 10:05:57 -0500 |
commit | a75b08b76f91451bb586b154fdca872955d8a57a (patch) | |
tree | dd1c30f65162c1e12b8f6481bbd102d69f5c7196 /dev/MinGfx/src/quick_shapes.cc | |
parent | Upload a1 (diff) | |
download | csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.gz csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.bz2 csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.lz csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.xz csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.zst csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.zip |
publish a2
Diffstat (limited to 'dev/MinGfx/src/quick_shapes.cc')
-rw-r--r-- | dev/MinGfx/src/quick_shapes.cc | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/dev/MinGfx/src/quick_shapes.cc b/dev/MinGfx/src/quick_shapes.cc index 388aa3d..01f187a 100644 --- a/dev/MinGfx/src/quick_shapes.cc +++ b/dev/MinGfx/src/quick_shapes.cc @@ -11,6 +11,7 @@ #include <iostream> #include <string> +#include "gfxmath.h" namespace mingfx { @@ -180,11 +181,10 @@ void QuickShapes::initCyl() { const int nslices = 20; for (int s=1; s<nslices+1; s++) { - int slast = s - 1; - GLfloat xlast = std::cosf(-TWOPI * (float)slast / (float)nslices); - GLfloat zlast = std::sinf(-TWOPI * (float)slast/(float)nslices); - GLfloat xnew = std::cosf(-TWOPI * (float)(s)/(float)nslices); - GLfloat znew = std::sinf(-TWOPI * (float)(s)/(float)nslices); + GLfloat xlast = GfxMath::cos(-TWOPI * (float)(s-1)/(float)nslices); + GLfloat zlast = GfxMath::sin(-TWOPI * (float)(s-1)/(float)nslices); + GLfloat xnew = GfxMath::cos(-TWOPI * (float)(s)/(float)nslices); + GLfloat znew = GfxMath::sin(-TWOPI * (float)(s)/(float)nslices); // one triangle on the top verts.push_back(top); @@ -245,11 +245,10 @@ void QuickShapes::initCone() { const int nslices = 20; for (int s=1; s<nslices+1; s++) { - int slast = s - 1; - GLfloat xlast = std::cosf(-TWOPI * (float)slast/(float)nslices); - GLfloat zlast = std::sinf(-TWOPI * (float)slast/(float)nslices); - GLfloat xnew = std::cosf(-TWOPI * (float)(s)/(float)nslices); - GLfloat znew = std::sinf(-TWOPI * (float)(s)/(float)nslices); + GLfloat xlast = GfxMath::cos(-TWOPI * (float)(s-1)/(float)nslices); + GLfloat zlast = GfxMath::sin(-TWOPI * (float)(s-1)/(float)nslices); + GLfloat xnew = GfxMath::cos(-TWOPI * (float)(s)/(float)nslices); + GLfloat znew = GfxMath::sin(-TWOPI * (float)(s)/(float)nslices); // one triangle on the side // normals are a bit more complex than for other shapes... @@ -309,28 +308,30 @@ void QuickShapes::initSph() { const int nslices = 40; const int nstacks = 40; for (int s=1; s<nslices+1; s++) { - int slast = s - 1; - GLfloat xlast = std::cosf(-TWOPI * (float)slast/(float)nslices); - GLfloat zlast = std::sinf(-TWOPI * (float)slast/(float)nslices); - GLfloat xnew = std::cosf(-TWOPI * (float)(s)/(float)nslices); - GLfloat znew = std::sinf(-TWOPI * (float)(s)/(float)nslices); + GLfloat xlast = GfxMath::cos(-TWOPI * (float)(s-1)/(float)nslices); + GLfloat zlast = GfxMath::sin(-TWOPI * (float)(s-1)/(float)nslices); + GLfloat xnew = GfxMath::cos(-TWOPI * (float)(s)/(float)nslices); + GLfloat znew = GfxMath::sin(-TWOPI * (float)(s)/(float)nslices); float stackstep = PI/(float)nstacks; // one triangle on the top verts.push_back(top); - verts.push_back(Vertex(std::sinf(stackstep)*xlast,std::cosf(stackstep),std::sinf(stackstep)*zlast, - std::sinf(stackstep)*xlast,std::cosf(stackstep),std::sinf(stackstep)*zlast)); - verts.push_back(Vertex(std::sinf(stackstep)*xnew,std::cosf(stackstep),std::sinf(stackstep)*znew, - std::sinf(stackstep)*xnew,std::cosf(stackstep),std::sinf(stackstep)*znew)); + verts.push_back(Vertex(GfxMath::sin(stackstep)*xlast,GfxMath::cos(stackstep), + GfxMath::sin(stackstep)*zlast, + GfxMath::sin(stackstep)*xlast,GfxMath::cos(stackstep), + GfxMath::sin(stackstep)*zlast)); + verts.push_back(Vertex(GfxMath::sin(stackstep)*xnew,GfxMath::cos(stackstep), + GfxMath::sin(stackstep)*znew, + GfxMath::sin(stackstep)*xnew,GfxMath::cos(stackstep), + GfxMath::sin(stackstep)*znew)); for (int t=2; t<nstacks; t++) { - int tlast = t - 1; - GLfloat ylast = std::cosf(PI*(float)(tlast)/(float)nstacks); - GLfloat ynew = std::cosf(PI*(float)(t)/(float)nstacks); + GLfloat ylast = GfxMath::cos(PI*(float)(t-1)/(float)nstacks); + GLfloat ynew = GfxMath::cos(PI*(float)(t)/(float)nstacks); - GLfloat rlast = std::sinf(PI * (float)(tlast)/(float)nstacks); - GLfloat rnew = std::sinf(PI * (float)(t)/(float)nstacks); + GLfloat rlast = GfxMath::sin(PI * (float)(t-1)/(float)nstacks); + GLfloat rnew = GfxMath::sin(PI * (float)(t)/(float)nstacks); // two triangles to create a rect on the side verts.push_back(Vertex(rlast*xlast,ylast,rlast*zlast, rlast*xlast,ylast,rlast*zlast)); @@ -344,12 +345,17 @@ void QuickShapes::initSph() { // one triangle on the bottom verts.push_back(bot); - verts.push_back(Vertex(std::sinf(stackstep)*xnew,std::cosf(PI-stackstep),std::sinf(stackstep)*znew, - std::sinf(stackstep)*xnew,std::cosf(PI-stackstep),std::sinf(stackstep)*znew)); - verts.push_back(Vertex(std::sinf(stackstep)*xlast,std::cosf(PI-stackstep),std::sinf(stackstep)*zlast, - std::sinf(stackstep)*xlast,std::cosf(PI-stackstep),std::sinf(stackstep)*zlast)); + verts.push_back(Vertex(GfxMath::sin(stackstep)*xnew,GfxMath::cos(PI-stackstep), + GfxMath::sin(stackstep)*znew, + GfxMath::sin(stackstep)*xnew,GfxMath::cos(PI-stackstep), + GfxMath::sin(stackstep)*znew)); + verts.push_back(Vertex(GfxMath::sin(stackstep)*xlast,GfxMath::cos(PI-stackstep), + GfxMath::sin(stackstep)*zlast, + GfxMath::sin(stackstep)*xlast,GfxMath::cos(PI-stackstep), + GfxMath::sin(stackstep)*zlast)); } + std::vector<Point3> vertices; std::vector<Vector3> normals; for (int i = 0; i < verts.size(); i++) { |