void GPUTileStorage::generateMipMap() { if (changes) { int level = 1; int width = tileSize / 2; while (width >= 1) { fbo->setViewport(vec4i(0, 0, width, width)); for (unsigned int n = 0; n < textures.size(); ++n) { fbo->setTextureBuffer(BufferId(1 << n), textures[n], level, -1); } for (unsigned int n = 0; n < textures.size(); ++n) { fbo->setDrawBuffer(BufferId(1 << n)); set<GPUSlot*>::iterator i = dirtySlots[n].begin(); while (i != dirtySlots[n].end()) { GPUSlot *s = *i; mipmapParams->set(vec4i(s->index, s->l, level - 1, width)); fbo->drawQuad(mipmapProg); ++i; } } width /= 2; level += 1; } for (unsigned int n = 0; n < textures.size(); ++n) { dirtySlots[n].clear(); } changes = false; } }
void Spritesheet::draw() { used = 0; glBindTexture(GL_TEXTURE_2D, image.id ); for ( LDEuint s = 0; s < frames.size(); ++s ) { LDErectp( image.size, vec4i( frames[s].pos.x, frames[s].pos.y, frames[s].size.x, frames[s].size.y), vec4i( frames[s].pos_window.x + frames[s].margin.x, frames[s].pos_window.y + frames[s].margin.y, frames[s].size_100.x, frames[s].size_100.y) ); } glDisable(GL_TEXTURE_2D); glEnable(GL_LINE_STIPPLE); glLineStipple(1,0x0101); for ( LDEuint s = 0; s < frames.size(); ++s ) { // Test coi if ( cursor_pos.x >= window_pos.x + frames[s].pos_window.x && cursor_pos.x <= window_pos.x + frames[s].pos_window.x + 100 && cursor_pos.y >= window_pos.y + frames[s].pos_window.y && cursor_pos.y <= window_pos.y + frames[s].pos_window.y + 100 && test_coi ) { glColor3f( 0, 1, 0 ); used = 1; // If left clicked on that one for ( LDEuint i = 0; i < mouse.size(); ++i ) { if ( mouse[i].left && mouse[i].down ) { selected = s; mouse_down = 1; } } } else glColor4f( 1, 1, 1, 0.3 ); LDErectw( frames[s].pos_window.x, frames[s].pos_window.y, 100, 100); } glDisable(GL_LINE_STIPPLE); glEnable(GL_TEXTURE_2D); // If left clicked on that one for ( LDEuint i = 0; i < mouse.size(); ++i ) { if ( mouse[i].left && !mouse[i].down ) { selected = -1; mouse_down = 0; } } mouse.erase( mouse.begin(), mouse.end() ); }
static inline void drawtri_horse(Image *img, Rect *r, short *a, short *b, short *c, uchar *color) { v4int abp_y, bcp_y, cap_y, abp, bcp, cap; v4int abp_dx, bcp_dx, cap_dx; v4int abp_dy, bcp_dy, cap_dy; v4int mask; short u0, v0; enum { ustep = 2, vstep = 2 }; abp_dx = vec4ir(ori2i_dx(a, b)); bcp_dx = vec4ir(ori2i_dx(b, c)); cap_dx = vec4ir(ori2i_dx(c, a)); abp_dy = vec4ir(ori2i_dy(a, b)); bcp_dy = vec4ir(ori2i_dy(b, c)); cap_dy = vec4ir(ori2i_dy(c, a)); short p[2] = { r->u0, r->v0 }; abp_y = vec4ir(ori2i(a, b, p)) + vec4i(0, abp_dx[0], abp_dy[0], abp_dx[0]+abp_dy[0]); bcp_y = vec4ir(ori2i(b, c, p)) + vec4i(0, bcp_dx[0], bcp_dy[0], bcp_dx[0]+bcp_dy[0]); cap_y = vec4ir(ori2i(c, a, p)) + vec4i(0, cap_dx[0], cap_dy[0], cap_dx[0]+cap_dy[0]); abp_y += topleft(a, b); bcp_y += topleft(b, c); cap_y += topleft(c, a); abp_dx = abp_dx * ustep; bcp_dx = bcp_dx * ustep; cap_dx = cap_dx * ustep; abp_dy = abp_dy * vstep; bcp_dy = bcp_dy * vstep; cap_dy = cap_dy * vstep; for(v0 = r->v0; v0 < r->vend; v0 += vstep){ abp = abp_y; bcp = bcp_y; cap = cap_y; for(u0 = r->u0; u0 < r->uend; u0 += ustep){ mask = (abp | bcp | cap) >> 31; if((mask[0]&mask[1]&mask[2]&mask[3]) == 0){ mask |= vec4i(0, -(u0 == r->uend-1), 0, -(u0 == r->uend-1)); mask |= vec4i(0, 0, -(v0 == r->vend-1), -(v0 == r->vend-1)); fragment(img, u0, v0, *(u32int*)color, mask); } abp += abp_dx; bcp += bcp_dx; cap += cap_dx; } abp_y += abp_dy; bcp_y += bcp_dy; cap_y += cap_dy; } }
/// Tesselate Mesh one time /// @param mesh The Mesh to tesselate /// @return The tesselated Mesh Mesh* _tesselate_mesh_once(Mesh* mesh) { auto tesselation = new Mesh(); // Set up the hashtable for adjacency auto adj = EdgeHashTable(mesh->triangle, mesh->quad); // Add vertices to the tessellation tesselation->pos = mesh->pos; // tesselation->norm = mesh->norm; // tesselation->texcoord = mesh->texcoord; // Add edge vertices to the tessellation int evo = tesselation->pos.size(); for(auto e : adj.edges) { tesselation->pos.push_back(mesh->pos[e.x]*0.5+mesh->pos[e.y]*0.5); // if(not tesselation->norm.empty()) tesselation->norm.push_back(normalize(mesh->norm[e.x]*0.5+mesh->norm[e.y]*0.5)); // if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(mesh->texcoord[e.x]*0.5+mesh->texcoord[e.y]*0.5); } // Add face vertices to the tessellation int fvo = tesselation->pos.size(); for(auto f : mesh->quad) { tesselation->pos.push_back(mesh->pos[f.x]*0.25+mesh->pos[f.y]*0.25+mesh->pos[f.z]*0.25+mesh->pos[f.w]*0.25); // if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(mesh->texcoord[f.x]*0.25+mesh->texcoord[f.y]*0.25+mesh->texcoord[f.z]*0.25+mesh->texcoord[f.w]*0.25); } // Add triangles to the tessellation for(auto f : mesh->triangle) { auto ve = vec3i(adj.edge(f.x, f.y),adj.edge(f.y, f.z),adj.edge(f.z, f.x))+vec3i(evo,evo,evo); tesselation->triangle.push_back(vec3i(f.x,ve.x,ve.z)); tesselation->triangle.push_back(vec3i(f.y,ve.y,ve.x)); tesselation->triangle.push_back(vec3i(f.z,ve.z,ve.y)); tesselation->triangle.push_back(ve); } // Add quads to the tessellation for(int fid = 0; fid < mesh->quad.size(); fid ++) { auto f = mesh->quad[fid]; auto ve = vec4i(adj.edge(f.x, f.y),adj.edge(f.y, f.z),adj.edge(f.z, f.w),adj.edge(f.w, f.x))+vec4i(evo,evo,evo,evo); auto vf = fid+fvo; tesselation->quad.push_back(vec4i(f.x,ve.x,vf,ve.w)); tesselation->quad.push_back(vec4i(f.y,ve.y,vf,ve.x)); tesselation->quad.push_back(vec4i(f.z,ve.z,vf,ve.y)); tesselation->quad.push_back(vec4i(f.w,ve.w,vf,ve.z)); } // Add lines to the tessellation if(mesh->_tesselation_lines.size() > 0) { for(auto l : mesh->_tesselation_lines) { int ve = adj.edge(l.x, l.y)+evo; tesselation->_tesselation_lines.push_back(vec2i(l.x,ve)); tesselation->_tesselation_lines.push_back(vec2i(ve,l.y)); } } return tesselation; }
/// Tesselate parametric Shape (two parameters) /// @param shape_frame Function that returns the frame of the Shape at the given vec2f coordinate /// @param ur Number of divisions along first parameter /// @param vr Number of divisions along second parameter /// @param ccw Specifies whether faces are to be generated counter-clockwise or clockwise /// @param smooth Specifies whether the tesselated surface is to have smooth normals /// @return The tesselated shape Shape* _tesselate_shape_uniform(const function<frame3f (const vec2f&)> shape_frame, int ur, int vr, bool ccw, bool smooth) { auto tesselation = new Mesh(); auto line = vector<vec2i>(); for(int i = 0; i <= ur; i ++) { for(int j = 0; j <= vr; j ++) { float u = i / float(ur); float v = j / float(vr); vec2f uv = vec2f(u,v); auto f = shape_frame(uv); tesselation->pos.push_back(f.o); if(smooth) tesselation->norm.push_back(f.z); } } for(int i = 0; i < ur; i ++) { for(int j = 0; j < vr; j ++) { vec4i f = vec4i((i+0)*(vr+1)+(j+0),(i+0)*(vr+1)+(j+1),(i+1)*(vr+1)+(j+1),(i+1)*(vr+1)+(j+0)); if(not ccw) { swap(f.y,f.w); } tesselation->quad.push_back(f); } } return tesselation; }
vec4i Material::getParam(const char *name, vec4i defaultVal) { ParamMap::iterator it = params.find(name); if (it != params.end()) { assert( it->second->type == Param::INT_4 && "Param type mismatch" ); return vec4i(it->second->i[0], it->second->i[1], it->second->i[2], it->second->i[3]); } return defaultVal; }
void TestLinAlg() { // Instantiate templates, check sizes, make sure operators compile etc. static_assert(sizeof(Vec2f) == 8 , "Vec2f size test failed" ); static_assert(sizeof(Vec3f) == 12 , "Vec3f size test failed" ); static_assert(sizeof(Vec4f) == 16 , "Vec4f size test failed" ); static_assert(sizeof(Vec2d) == 16 , "Vec2d size test failed" ); static_assert(sizeof(Vec3d) == 24 , "Vec3d size test failed" ); static_assert(sizeof(Vec4d) == 32 , "Vec4d size test failed" ); static_assert(sizeof(Vec2i) == 8 , "Vec2i size test failed" ); static_assert(sizeof(Vec3i) == 12 , "Vec3i size test failed" ); static_assert(sizeof(Vec4i) == 16 , "Vec4i size test failed" ); static_assert(sizeof(Vec2ui) == 8 , "Vec2ui size test failed" ); static_assert(sizeof(Vec3ui) == 12 , "Vec3ui size test failed" ); static_assert(sizeof(Vec4ui) == 16 , "Vec4ui size test failed" ); static_assert(sizeof(Matrix44f) == 64 , "Matrix44f size test failed"); static_assert(sizeof(Matrix44d) == 128, "Matrix44d size test failed"); Vec2f vec2f(0.0f, 0.0f); Vec3f vec3f(0.0f, 0.0f, 0.0f); Vec4f vec4f(0.0f, 0.0f, 0.0f, 0.0f); Vec2d vec2d(0.0, 0.0); Vec3d vec3d(0.0, 0.0, 0.0); Vec4d vec4d(0.0, 0.0, 0.0, 0.0); Vec2i vec2i(-1, -1); Vec3i vec3i(-1, -1, -1); Vec4i vec4i(-1, -1, -1, -1); Vec2ui vec2ui(0, 0); Vec3ui vec3ui(0, 0, 0); Vec4ui vec4ui(0, 0, 0, 0); float f = 0.0f; bool b = false; b = (vec3f == vec3f); b = (vec3f != vec3f); vec3f = Vec3f(1.0f) + Vec3f(2.0f); vec3f = Vec3f(1.0f) - Vec3f(2.0f); vec3f = Vec3f(1.0f) * Vec3f(2.0f); vec3f = Vec3f(1.0f) / Vec3f(2.0f); vec3f = Vec3f(1.0f) * f; vec3f = f * Vec3f(1.0f); vec3f = Vec3f(1.0f) / f; vec3f = -Vec3f(1.0f); vec3f += Vec3f(1.0f); vec3f -= Vec3f(1.0f); vec3f *= Vec3f(1.0f); vec3f /= Vec3f(1.0f); vec3f *= f; vec3f /= f; f = vec3f[0]; vec3f[0] = f; f = Length(vec3f); f = LengthSquared(vec3f); vec3f = Normalize(vec3f); f = Dot(Vec3f(1.0f), Vec3f(2.0f)); vec3f = Vec3f(1.0f) ^ Vec3f(2.0f); Matrix44f matf; matf.Identity(); Matrix44d matd; matf.RotationX(1); matf.RotationY(1); matf.RotationZ(1); matf.Scaling(1); b = matf == matf; matf = matf * matf; matf.BuildLookAtMatrix(Vec3f(0.0f, 10.0f, 10.0f), Vec3f(0.0f)); matf.BuildProjection(90.0f, 4.0f / 3.0f, 1.0f, 1000.0f); Vec3f out; matf.Transf3x3(vec3f, out); matf.Transf4x4(vec3f, out); matf.Transpose3x3(); matf.Transpose4x4(); matf.Invert(); }
vec4i SceneGraph::viewport() const { GLint vp[4]; glGetIntegerv( GL_VIEWPORT, vp); return vec4i(&vp[0]); }
/// Apply subdivision surface rules on subdiv /// @param subdiv The mesh to subdivide /// @return The subdivided mesh Subdiv* _tesselate_subdiv_once(Subdiv* subdiv) { auto tesselation = new Subdiv(); // linear subdivision like triangle mesh // adjacency auto adj = EdgeHashTable(subdiv->triangle,subdiv->quad); // add vertices tesselation->pos = subdiv->pos; tesselation->texcoord = subdiv->texcoord; // add edge vertices int evo = tesselation->pos.size(); for(auto e : adj.edges) { tesselation->pos.push_back(subdiv->pos[e.x]*0.5+subdiv->pos[e.y]*0.5); if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(subdiv->texcoord[e.x]*0.5+subdiv->texcoord[e.y]*0.5); } // add face vertices int fvo = tesselation->pos.size(); for(auto f : subdiv->quad) { tesselation->pos.push_back(subdiv->pos[f.x]*0.25+subdiv->pos[f.y]*0.25+subdiv->pos[f.z]*0.25+subdiv->pos[f.w]*0.25); if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(subdiv->texcoord[f.x]*0.25+subdiv->texcoord[f.y]*0.25+subdiv->texcoord[f.z]*0.25+subdiv->texcoord[f.w]*0.25); } // add triangles for(auto f : subdiv->triangle) { auto ve = vec3i(adj.edge(f.x, f.y),adj.edge(f.y, f.z),adj.edge(f.z, f.x))+vec3i(evo,evo,evo); tesselation->triangle.push_back(vec3i(f.x,ve.x,ve.z)); tesselation->triangle.push_back(vec3i(f.y,ve.y,ve.x)); tesselation->triangle.push_back(vec3i(f.z,ve.z,ve.y)); tesselation->triangle.push_back(ve); } // add quads for(int fid = 0; fid < subdiv->quad.size(); fid ++) { auto f = subdiv->quad[fid]; auto ve = vec4i(adj.edge(f.x, f.y),adj.edge(f.y, f.z),adj.edge(f.z, f.w),adj.edge(f.w, f.x))+vec4i(evo,evo,evo,evo); auto vf = fid+fvo; tesselation->quad.push_back(vec4i(f.x,ve.x,vf,ve.w)); tesselation->quad.push_back(vec4i(f.y,ve.y,vf,ve.x)); tesselation->quad.push_back(vec4i(f.z,ve.z,vf,ve.y)); tesselation->quad.push_back(vec4i(f.w,ve.w,vf,ve.z)); } // creases tesselation->crease_vertex = subdiv->crease_vertex; for(auto e : subdiv->crease_edge) { tesselation->crease_edge.push_back({e.x,evo+adj.edge(e.x, e.y)}); tesselation->crease_edge.push_back({evo+adj.edge(e.x, e.y),e.y}); } // add lines if(subdiv->_tesselation_lines.size() > 0) { for(auto l : subdiv->_tesselation_lines) { int ve = adj.edge(l.x, l.y)+evo; tesselation->_tesselation_lines.push_back(vec2i(l.x,ve)); tesselation->_tesselation_lines.push_back(vec2i(ve,l.y)); } } // mark creases auto cvertex = vector<bool>(tesselation->pos.size(),false); auto cedge = vector<bool>(tesselation->pos.size(),false); for(auto vid : tesselation->crease_vertex) cvertex[vid] = true; for(auto e : tesselation->crease_edge) for(auto vid : e) cedge[vid] = true; // averaging auto npos = vector<vec3f>(tesselation->pos.size(),zero3f); auto ntexcoord = vector<vec2f>(tesselation->texcoord.size(),zero2f); auto weight = vector<float>(tesselation->pos.size(),0); auto nquad = vector<int>(tesselation->pos.size(),0); auto ntriangle = vector<int>(tesselation->pos.size(),0); for(auto f : tesselation->quad) { for(auto vid : f) { if(cedge[vid] or cvertex[vid]) continue; auto w = pi/2; npos[vid] += (tesselation->pos[f.x]+tesselation->pos[f.y]+tesselation->pos[f.z]+tesselation->pos[f.w])*w/4; if(not ntexcoord.empty()) ntexcoord[vid] += (tesselation->texcoord[f.x]+tesselation->texcoord[f.y]+tesselation->texcoord[f.z]+tesselation->texcoord[f.w])*w/4; weight[vid] += w; nquad[vid] ++; } } for(auto f : tesselation->triangle) { for(int i = 0; i < 3; i ++) { auto vid = f[i]; auto vid1 = f[(i+1)%3]; auto vid2 = f[(i+2)%3]; if(cedge[vid] or cvertex[vid]) continue; auto w = pi/3; npos[vid] += (tesselation->pos[vid]/4+tesselation->pos[vid1]*(3/8.0)+tesselation->pos[vid2]*(3/8.0))*w; if(not ntexcoord.empty()) ntexcoord[vid] += (tesselation->texcoord[vid]/4+tesselation->texcoord[vid1]*(3/8.0)+tesselation->texcoord[vid2]*(3/8.0))*w; weight[vid] += w; ntriangle[vid] ++; } } // handle creases for(auto e : tesselation->crease_edge) { for(auto vid : e) { if(cvertex[vid]) continue; npos[vid] += (tesselation->pos[e.x]+tesselation->pos[e.y])/2; if(not ntexcoord.empty()) ntexcoord[vid] += (tesselation->texcoord[vid]+tesselation->texcoord[vid])/2; weight[vid] += 1; } } for(auto vid : tesselation->crease_vertex) { npos[vid] += tesselation->pos[vid]; if(not ntexcoord.empty()) ntexcoord[vid] += tesselation->texcoord[vid]; weight[vid] += 1; } // normalization for(auto i : range(tesselation->pos.size())) { npos[i] /= weight[i]; if(not ntexcoord.empty()) ntexcoord[i] /= weight[i]; } // correction for(auto i : range(tesselation->pos.size())) { if(cedge[i] or cvertex[i]) continue; float w = 0; if(tesselation->quad.empty()) w = 5/3.0 - (8/3.0)*pow(3/8.0+1/4.0*cos(2*pi/ntriangle[i]),2); else if(tesselation->triangle.empty()) w = 4.0f / nquad[i]; else w = (nquad[i] == 0 and ntriangle[i] == 3) ? 1.5f : 12.0f / (3 * nquad[i] + 2 * ntriangle[i]); npos[i] = tesselation->pos[i] + (npos[i] - tesselation->pos[i])*w; if(not ntexcoord.empty()) ntexcoord[i] = tesselation->texcoord[i] + (ntexcoord[i] - tesselation->texcoord[i])*w; } // set tesselation back tesselation->pos = npos; tesselation->texcoord = ntexcoord; return tesselation; }
/// Apply Catmull-Clark subdivision surface rules on subdiv /// @param subdiv The mesh to subdivide /// @return The subdivided mesh CatmullClarkSubdiv* _tesselate_catmullclark_once(CatmullClarkSubdiv* subdiv) { auto tesselation = new CatmullClarkSubdiv(); // Set up the hash table for adjacency auto adj = EdgeHashTable(vector<vec3i>(), subdiv->quad); // Add vertices to the tessellation tesselation->pos = subdiv->pos; // tesselation->texcoord = subdiv->texcoord; // Add edge vertices to the tessellation int evo = tesselation->pos.size(); for(auto e : adj.edges) { tesselation->pos.push_back(subdiv->pos[e.x]*0.5+subdiv->pos[e.y]*0.5); // if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(subdiv->texcoord[e.x]*0.5+subdiv->texcoord[e.y]*0.5); } // Add face vertices to the tessellation int fvo = tesselation->pos.size(); for(auto f : subdiv->quad) { tesselation->pos.push_back(subdiv->pos[f.x]*0.25+subdiv->pos[f.y]*0.25+subdiv->pos[f.z]*0.25+subdiv->pos[f.w]*0.25); // if(not tesselation->texcoord.empty()) tesselation->texcoord.push_back(subdiv->texcoord[f.x]*0.25+subdiv->texcoord[f.y]*0.25+subdiv->texcoord[f.z]*0.25+subdiv->texcoord[f.w]*0.25); } // Add quads to the tessellation for(int fid = 0; fid < subdiv->quad.size(); fid ++) { auto f = subdiv->quad[fid]; auto ve = vec4i(adj.edge(f.x, f.y),adj.edge(f.y, f.z),adj.edge(f.z, f.w),adj.edge(f.w, f.x))+vec4i(evo,evo,evo,evo); auto vf = fid+fvo; tesselation->quad.push_back(vec4i(f.x,ve.x,vf,ve.w)); tesselation->quad.push_back(vec4i(f.y,ve.y,vf,ve.x)); tesselation->quad.push_back(vec4i(f.z,ve.z,vf,ve.y)); tesselation->quad.push_back(vec4i(f.w,ve.w,vf,ve.z)); } // Perform the averaging step, as described in the lecture notes auto avg_v = vector<vec3f>(tesselation->pos.size(), zero3f); auto avg_n = vector<int>(tesselation->pos.size(), 0); for(auto f : tesselation->quad) { auto c = tesselation->pos[f.x]*0.25 + tesselation->pos[f.y]*0.25 + tesselation->pos[f.z]*0.25 + tesselation->pos[f.w]*0.25; for(auto vid : f) { avg_v[vid] += c; avg_n[vid] += 1; } } for(auto vid : range(avg_n.size())) { avg_v[vid] /= avg_n[vid]; } // Perform the correction step, as described in the lecture notes for(auto vid : range(tesselation->pos.size())) avg_v[vid] = tesselation->pos[vid] + ((avg_v[vid] - tesselation->pos[vid]) * (4.0/avg_n[vid])); // Add lines to the tessellation if(subdiv->_tesselation_lines.size() > 0) { for(auto l : subdiv->_tesselation_lines) { int ve = adj.edge(l.x, l.y)+evo; tesselation->_tesselation_lines.push_back(vec2i(l.x,ve)); tesselation->_tesselation_lines.push_back(vec2i(ve,l.y)); } } // Add the new vertices to the tessellation tesselation->pos = avg_v; return tesselation; }
static inline v4int vec4ir(int v) { return vec4i(v, v, v, v); }
static std::shared_ptr<qube<T>> get( size_t x, size_t y, size_t z, size_t c ) { return instance.get( vec4i(x,y,z,c) ); }
void initMaterials () { gmat = new SLCMaterial ( "material"); gmat->foreground_color = vec4i(155, 0, 0, 255); gmat->background_color = vec4i(255, 255, 255, 255); gmat->linetype = 0xFFFF;//SLCMaterial::LINETYPE_SOLID; gmat->linewidth = 1; gmat->fontfilename = "simsun.ttc"; gmat->texturefilename = "hands.jpg"; nodes.push_back ( gmat ); gmat1 = new SLCMaterial ( "material1"); gmat1->foreground_color = vec4i(0, 0, 155, 255); gmat1->background_color = vec4i(190, 213, 235, 255); gmat1->linetype = 0xFFFF;//SLCMaterial::LINETYPE_SOLID; gmat1->linewidth = 1; gmat1->fontfilename = "simsun.ttc"; gmat1->texturefilename = "hands.jpg"; nodes.push_back ( gmat1 ); gmatLine0 = new SLCMaterial ( "materialLine0"); gmatLine0->foreground_color = vec4i(0, 0, 155, 255); gmatLine0->background_color = vec4i(250, 250, 250, 255); gmatLine0->linetype = 0xFFFF;//SLCMaterial::LINETYPE_SOLID; gmatLine0->linewidth = 10000; gmatLine0->fontfilename = "simsun.ttc"; gmatLine0->texturefilename = "hands.jpg"; nodes.push_back ( gmatLine0 ); gmatLine = new SLCMaterial ( "materialLine"); gmatLine->foreground_color = vec4i(0, 0, 155, 255); gmatLine->background_color = vec4i(255, 255, 252, 255); gmatLine->linetype = 0xFFFF;//SLCMaterial::LINETYPE_SOLID; gmatLine->linewidth = 4000; gmatLine->fontfilename = "simsun.ttc"; gmatLine->texturefilename = "hands.jpg"; nodes.push_back ( gmatLine ); gmatLine2 = new SLCMaterial ( "materialLine2"); gmatLine2->foreground_color = vec4i(0, 0, 155, 255); gmatLine2->background_color = vec4i(255, 255, 254, 255); gmatLine2->linetype = 0xFFFF;//SLCMaterial::LINETYPE_SOLID; gmatLine2->linewidth = 2000; gmatLine2->fontfilename = "simsun.ttc"; gmatLine2->texturefilename = "hands.jpg"; nodes.push_back ( gmatLine2 ); gmatLine3 = new SLCMaterial ( "materialLine3"); gmatLine3->foreground_color = vec4i(0, 0, 155, 255); gmatLine3->background_color = vec4i(255, 255, 250, 255); gmatLine3->linetype = 0xFFFF;//SLCMaterial::LINETYPE_SOLID; gmatLine3->linewidth = 1000; gmatLine3->fontfilename = "simsun.ttc"; gmatLine3->texturefilename = "hands.jpg"; nodes.push_back ( gmatLine3 ); }
namespace cube { template <typename T> mat3x3<T>::mat3x3(const vec3<T> &n) { vy = n; if (abs(n.x) >= abs(n.y)) { const auto inv = rcp(sqrt(n.x*n.x + n.z*n.z)); vx = vec3<T>(-n.z*inv, zero, n.x*inv); } else { const auto inv = rcp(sqrt(n.y*n.y + n.z*n.z)); vx = vec3<T>(zero, n.z*inv, -n.y*inv); } vx = normalize(vx); vy = normalize(vy); vz = cross(vy,vx); } template mat3x3<float>::mat3x3(const vec3f &n); template <typename T> mat4x4<T> mat4x4<T>::inverse(void) const { mat4x4<T> inv; inv.vx.x = vy.y*vz.z*vw.w - vy.y*vz.w*vw.z - vz.y*vy.z*vw.w + vz.y*vy.w*vw.z + vw.y*vy.z*vz.w - vw.y*vy.w*vz.z; inv.vy.x = -vy.x*vz.z*vw.w + vy.x*vz.w*vw.z + vz.x*vy.z*vw.w - vz.x*vy.w*vw.z - vw.x*vy.z*vz.w + vw.x*vy.w*vz.z; inv.vz.x = vy.x*vz.y*vw.w - vy.x*vz.w*vw.y - vz.x*vy.y*vw.w + vz.x*vy.w*vw.y + vw.x*vy.y*vz.w - vw.x*vy.w*vz.y; inv.vw.x = -vy.x*vz.y*vw.z + vy.x*vz.z*vw.y + vz.x*vy.y*vw.z - vz.x*vy.z*vw.y - vw.x*vy.y*vz.z + vw.x*vy.z*vz.y; inv.vx.y = -vx.y*vz.z*vw.w + vx.y*vz.w*vw.z + vz.y*vx.z*vw.w - vz.y*vx.w*vw.z - vw.y*vx.z*vz.w + vw.y*vx.w*vz.z; inv.vy.y = vx.x*vz.z*vw.w - vx.x*vz.w*vw.z - vz.x*vx.z*vw.w + vz.x*vx.w*vw.z + vw.x*vx.z*vz.w - vw.x*vx.w*vz.z; inv.vz.y = -vx.x*vz.y*vw.w + vx.x*vz.w*vw.y + vz.x*vx.y*vw.w - vz.x*vx.w*vw.y - vw.x*vx.y*vz.w + vw.x*vx.w*vz.y; inv.vw.y = vx.x*vz.y*vw.z - vx.x*vz.z*vw.y - vz.x*vx.y*vw.z + vz.x*vx.z*vw.y + vw.x*vx.y*vz.z - vw.x*vx.z*vz.y; inv.vx.z = vx.y*vy.z*vw.w - vx.y*vy.w*vw.z - vy.y*vx.z*vw.w + vy.y*vx.w*vw.z + vw.y*vx.z*vy.w - vw.y*vx.w*vy.z; inv.vy.z = -vx.x*vy.z*vw.w + vx.x*vy.w*vw.z + vy.x*vx.z*vw.w - vy.x*vx.w*vw.z - vw.x*vx.z*vy.w + vw.x*vx.w*vy.z; inv.vz.z = vx.x*vy.y*vw.w - vx.x*vy.w*vw.y - vy.x*vx.y*vw.w + vy.x*vx.w*vw.y + vw.x*vx.y*vy.w - vw.x*vx.w*vy.y; inv.vw.z = -vx.x*vy.y*vw.z + vx.x*vy.z*vw.y + vy.x*vx.y*vw.z - vy.x*vx.z*vw.y - vw.x*vx.y*vy.z + vw.x*vx.z*vy.y; inv.vx.w = -vx.y*vy.z*vz.w + vx.y*vy.w*vz.z + vy.y*vx.z*vz.w - vy.y*vx.w*vz.z - vz.y*vx.z*vy.w + vz.y*vx.w*vy.z; inv.vy.w = vx.x*vy.z*vz.w - vx.x*vy.w*vz.z - vy.x*vx.z*vz.w + vy.x*vx.w*vz.z + vz.x*vx.z*vy.w - vz.x*vx.w*vy.z; inv.vz.w = -vx.x*vy.y*vz.w + vx.x*vy.w*vz.y + vy.x*vx.y*vz.w - vy.x*vx.w*vz.y - vz.x*vx.y*vy.w + vz.x*vx.w*vy.y; inv.vw.w = vx.x*vy.y*vz.z - vx.x*vy.z*vz.y - vy.x*vx.y*vz.z + vy.x*vx.z*vz.y + vz.x*vx.y*vy.z - vz.x*vx.z*vy.y; return inv / (vx.x*inv.vx.x + vx.y*inv.vy.x + vx.z*inv.vz.x + vx.w*inv.vw.x); } template mat4x4<float> mat4x4<float>::inverse(void) const; const vec3f axis[] = {vec3f(1.f,0.f,0.f), vec3f(0.f,1.f,0.f), vec3f(0.f,0.f,1.f)}; const vec3i iaxis[] = {vec3i(1,0,0), vec3i(0,1,0), vec3f(0,0,1)}; const vec3f white(1.f,1.f,1.f), yellow(1.f,1.f,0.f), purple(1.f,0.f,1.f), cyan(0.f,1.f,1.f); const vec3i cubeiverts[8] = { vec3i(0,0,0)/*0*/, vec3i(0,0,1)/*1*/, vec3i(0,1,1)/*2*/, vec3i(0,1,0)/*3*/, vec3i(1,0,0)/*4*/, vec3i(1,0,1)/*5*/, vec3i(1,1,1)/*6*/, vec3i(1,1,0)/*7*/ }; const vec3f cubefverts[8] = { vec3f(0.f,0.f,0.f)/*0*/, vec3f(0.f,0.f,1.f)/*1*/, vec3f(0.f,1.f,1.f)/*2*/, vec3f(0.f,1.f,0.f)/*3*/, vec3f(1.f,0.f,0.f)/*4*/, vec3f(1.f,0.f,1.f)/*5*/, vec3f(1.f,1.f,1.f)/*6*/, vec3f(1.f,1.f,0.f)/*7*/ }; const vec3i cubetris[12] = { vec3i(0,1,2), vec3i(0,2,3), vec3i(4,7,6), vec3i(4,6,5), // -x,+x triangles vec3i(0,4,5), vec3i(0,5,1), vec3i(2,6,7), vec3i(2,7,3), // -y,+y triangles vec3i(3,7,4), vec3i(3,4,0), vec3i(1,5,6), vec3i(1,6,2) // -z,+z triangles }; const vec3i cubenorms[6] = { vec3i(-1,0,0), vec3i(+1,0,0), vec3i(0,-1,0), vec3i(0,+1,0), vec3i(0,0,-1), vec3i(0,0,+1) }; const vec2i cubeedges[12] = { vec2i(0,1),vec2i(1,2),vec2i(2,3),vec2i(3,0), vec2i(4,5),vec2i(5,6),vec2i(6,7),vec2i(7,4), vec2i(1,5),vec2i(2,6),vec2i(0,4),vec2i(3,7) }; const vec4i cubequads[6] = { vec4i(0,1,2,3), vec4i(4,7,6,5), vec4i(0,4,5,1), vec4i(2,6,7,3), vec4i(3,7,4,0), vec4i(1,5,6,2) }; camera::camera(vec3f org, vec3f up, vec3f view, float fov, float ratio) : org(org), up(up), view(view), fov(fov), ratio(ratio) { const float left = -ratio * 0.5f; const float top = 0.5f; dist = 0.5f / tan(fov * float(pi) / 360.f); view = normalize(view); up = normalize(up); xaxis = cross(view, up); xaxis = normalize(xaxis); zaxis = cross(view, xaxis); zaxis = normalize(zaxis); imgplaneorg = dist*view + left*xaxis - top*zaxis; xaxis *= ratio; } } // namespace cube