diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-05-04 23:45:29 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-05-04 23:45:29 +0800 |
commit | 56eaa27d4daca9264dac2e822b1126cf6eb8cbf4 (patch) | |
tree | b4da915a530814cd6e1705e72b1bde5ad196d8d2 /visualization/extrasmeltutils.cpp | |
parent | 015a45c276caf34be3ce9175a1bcce644d736a0b (diff) | |
download | QMidiPlayer-56eaa27d4daca9264dac2e822b1126cf6eb8cbf4.tar.xz |
Piano keyboard: first steps.
Diffstat (limited to 'visualization/extrasmeltutils.cpp')
-rw-r--r-- | visualization/extrasmeltutils.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/visualization/extrasmeltutils.cpp b/visualization/extrasmeltutils.cpp new file mode 100644 index 0000000..3e86549 --- /dev/null +++ b/visualization/extrasmeltutils.cpp @@ -0,0 +1,91 @@ +#include "extrasmeltutils.hpp" +SMELT *smEntity3D::sm=NULL; +smEntity3D::smEntity3D() +{ + sm=smGetInterface(SMELT_APILEVEL); + surfaces.clear(); +} +void smEntity3D::pushSurface(smQuad q) +{surfaces.push_back(q);} +void smEntity3D::pushCube(smvec3d a,smvec3d b,DWORD color,DWORD mask) +{ + //a: top left corner b: bottom right corner + smQuad q;q.blend=BLEND_ALPHABLEND;q.tex=0; + for(int i=0;i<4;++i)q.v[i].col=color,q.v[i].tx=q.v[i].ty=0; + //top + if(mask&1) + { + q.v[0].x=a.x;q.v[0].y=a.y;q.v[0].z=a.z; + q.v[1].x=b.x;q.v[1].y=a.y;q.v[1].z=a.z; + q.v[2].x=b.x;q.v[2].y=b.y;q.v[2].z=a.z; + q.v[3].x=a.x;q.v[3].y=b.y;q.v[3].z=a.z; + pushSurface(q); + } + //bottom + if(mask&2) + { + q.v[0].x=a.x;q.v[0].y=a.y;q.v[0].z=b.z; + q.v[1].x=b.x;q.v[1].y=a.y;q.v[1].z=b.z; + q.v[2].x=b.x;q.v[2].y=b.y;q.v[2].z=b.z; + q.v[3].x=a.x;q.v[3].y=b.y;q.v[3].z=b.z; + pushSurface(q); + } + //left + if(mask&4) + { + q.v[0].x=a.x;q.v[0].y=b.y;q.v[0].z=a.z; + q.v[1].x=a.x;q.v[1].y=b.y;q.v[1].z=b.z; + q.v[2].x=a.x;q.v[2].y=a.y;q.v[2].z=b.z; + q.v[3].x=a.x;q.v[3].y=a.y;q.v[3].z=a.z; + pushSurface(q); + } + //right + if(mask&8) + { + q.v[0].x=b.x;q.v[0].y=b.y;q.v[0].z=a.z; + q.v[1].x=b.x;q.v[1].y=b.y;q.v[1].z=b.z; + q.v[2].x=b.x;q.v[2].y=a.y;q.v[2].z=b.z; + q.v[3].x=b.x;q.v[3].y=a.y;q.v[3].z=a.z; + pushSurface(q); + } + //front + if(mask&16) + { + q.v[0].x=a.x;q.v[0].y=b.y;q.v[0].z=a.z; + q.v[1].x=b.x;q.v[1].y=b.y;q.v[1].z=a.z; + q.v[2].x=b.x;q.v[2].y=b.y;q.v[2].z=b.z; + q.v[3].x=a.x;q.v[3].y=b.y;q.v[3].z=b.z; + pushSurface(q); + } + //back + if(mask&32) + { + q.v[0].x=a.x;q.v[0].y=a.y;q.v[0].z=a.z; + q.v[1].x=b.x;q.v[1].y=a.y;q.v[1].z=a.z; + q.v[2].x=b.x;q.v[2].y=a.y;q.v[2].z=b.z; + q.v[3].x=a.x;q.v[3].y=a.y;q.v[3].z=b.z; + pushSurface(q); + } +} +void smEntity3D::drawAt(smvec3d p) +{ + for(unsigned i=0;i<surfaces.size();++i) + { + smQuad tq=surfaces[i]; + for(unsigned j=0;j<4;++j)tq.v[j].x+=p.x,tq.v[j].y+=p.y,tq.v[j].z+=p.z; + sm->smRenderQuad(&tq); + } +} +void smEntity3D::drawWithTransformation(smMatrix t,smvec3d p) +{ + for(unsigned i=0;i<surfaces.size();++i) + { + smQuad tq=surfaces[i]; + for(unsigned j=0;j<4;++j) + { + smvec3d tp=t*smvec3d(tq.v[j].x,tq.v[j].y,tq.v[j].z); + tq.v[j].x=tp.x+p.x;tq.v[j].y=tp.y+p.y;tq.v[j].z=tp.z+p.z; + } + sm->smRenderQuad(&tq); + } +} |