void Mesh::calcUVSphere(){ for (int i=0; i<numVerts; i++){ Vector3 v = getVertex(i); float r = sqrt(v.x*v.x+v.z*v.z); setUV(i,atan2f(v.x,v.z)/Math::PI+0.5f, atan2f(v.y,r)/Math::PI+0.5f); } }
void Face::setUV(unsigned int facePoint, vector< UV > pointUVs) { unsigned int i; for (i = 0; i < pointUVs.size(); i++) { setUV(facePoint,pointUVs[i],i); } };
void Sprite::loadFromAtlas(const char *key){ std::map<std::string, AtlasInfo>::iterator it = _atlasMap.find(key); if ( it != _atlasMap.end() ){ AtlasInfo& atlas = it->second; _pTextureRes = TextureRes::create(atlas.file.c_str()); if ( _pTextureRes ){ setUV(atlas.u, atlas.v, atlas.w, atlas.h); } } }
Sprite::Sprite(const char* texFileName, bool reserveData, bool &ok) :_u1(0.f), _v1(0.f), _u2(1.f), _v2(1.f) ,_ancX(0.f), _ancY(0.f) , _width(1), _height(1){ _pTextureRes = PODTextureRes::create(texFileName, reserveData); ok = _pTextureRes != NULL; _texW = _pTextureRes->getHeader()->dwWidth; _texH = _pTextureRes->getHeader()->dwHeight; _glId = _pTextureRes->getGlId(); _hasAlpha = _pTextureRes->getHeader()->dwAlphaBitMask != 0; setUV(0, 0, -1, -1); }
void updateSprite(Sprite * sprite, float x, float y, float width, float height, ColorRGBA color, Vec4* uvs, SpriteFlags flags) { Vertex vertexData[6]; float firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY; // Setting the UV coordinates if (flags & SPRITE_REVERSE) { firstX = uvs->x; firstY = uvs->y + uvs->w; secondX = uvs->x + uvs->z; secondY = uvs->y + uvs->w; thirdX = uvs->x + uvs->z; thirdY = uvs->y; fourthX = uvs->x; fourthY = uvs->y; } else { firstX = uvs->x + uvs->z; firstY = uvs->y + uvs->w; secondX = uvs->x; secondY = uvs->y + uvs->w; thirdX = uvs->x; thirdY = uvs->y; fourthX = uvs->x + uvs->z; fourthY = uvs->y; } //First Triangle setPosition(&vertexData[0], x + width, y + height); setUV(&vertexData[0], firstX, firstY); setPosition(&vertexData[1], x, y + height); setUV(&vertexData[1], secondX, secondY); setPosition(&vertexData[2], x, y); setUV(&vertexData[2], thirdX, thirdY); //Second Triangle setPosition(&vertexData[3], x, y); setUV(&vertexData[3], thirdX, thirdY); setPosition(&vertexData[4], x + width, y); setUV(&vertexData[4], fourthX, fourthY); setPosition(&vertexData[5], x + width, y + height); setUV(&vertexData[5], firstX, firstY); //Set all vertex colors to magenta for (int i = 0; i < 6; i++) { vertexData[i].color = color; } // Binding buffer with our buffer id glBindBuffer(GL_ARRAY_BUFFER, sprite->vbo); // Uploading data glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW); // Unbinding buffer at the end glBindBuffer(GL_ARRAY_BUFFER, 0); }
void Plan::initialize() { if (!is_init) { this->_geometry->pushVertex(glm::vec3(-0.5, 0, 0.5)); this->_geometry->pushVertex(glm::vec3(0.5, 0, 0.5)); this->_geometry->pushVertex(glm::vec3(0.5, 0, -0.5)); this->_geometry->pushVertex(glm::vec3(-0.5, 0, -0.5)); setUV(); this->_geometry->build(); is_init = true; } }
void Mesh::calcUVPlaneXZ(){ float maxX = 0; float maxZ = 0; for (int i=0; i<numVerts; i++){ Vector3 v = getVertex(i); if (fabs(v.x)>maxX) maxX = fabs(v.x); if (fabs(v.z)>maxZ) maxZ = fabs(v.z); } for (int i=0; i<numVerts; i++){ Vector3 v = getVertex(i); setUV(i,v.x/maxX/2.0f+0.5f, v.z/maxZ/2.0f+0.5f); } }
void Mesh::calcUVPlaneXY(){ float maxX = 0; float maxY = 0; for (int i=0; i<numVerts; i++){ Vector3 v = getVertex(i); if (fabs(v.x)>maxX) maxX = fabs(v.x); if (fabs(v.y)>maxY) maxY = fabs(v.y); } for (int i=0; i<numVerts; i++){ Vector3 v = getVertex(i); setUV(i,v.x/maxX/2.0f+0.5f, v.y/maxY/2.0f+0.5f); } }
void Block::paste(int u, int v, MatrixXf * target, Vector<Vector<Point> > * targetAsPos) { setUV(u, v); float final; MatrixXf mask = getCutMask(u, v, target); for(int y = 0; y < BlockSize; y++) { for(int x = 0; x < BlockSize; x++) { if(mask(y,x)) { final = (*src)(p.y + y, p.x + x); (*target)(y + v, x + u) = final; (*targetAsPos)[y + v][x + u] = Point(p.x + x, p.y + y); } } }
void VertexBuffer::setUVBulk( Vec2 *uv, int num ) { for(int i=0;i<num;i++) { setUV( i, uv[i] ); } }
Sprite::Sprite(GLuint glId, int w, int h, bool hasAlpha, bool &ok) :_pTextureRes(NULL), _texW(w), _texH(h), _glId(glId), _hasAlpha(hasAlpha),_ancX(0.f), _ancY(0.f){ setUV(0, 0, -1, -1); ok = true; }
TextureUVCoordinateSet::TextureUVCoordinateSet(float minU, float minV, float maxU, float maxV, int width, int height) { setUV(minU, minV, maxU, maxV); this->width = width; this->height = height; }