void Sprite::Update(){ vertex[0]=-width/2; vertex[1]=-height/2; vertex[2]=-width/2; vertex[3]=height/2; vertex[4]=width/2; vertex[5]=height/2; vertex[6]=width/2; vertex[7]=-height/2; if(ReferenceObject!=NULL){ setPos(ReferenceObject->GetPosition().x,ReferenceObject->GetPosition().y,ReferenceObject->GetAngle()); } /* textureCords[0]=0; textureCords[1]=1; textureCords[2]=0; textureCords[3]=0; textureCords[4]=1; textureCords[5]=0; textureCords[6]=1; textureCords[7]=1; */ if(glfwGetTime()-start>(*CurrentAnimation)[frame].duration){ frame++; if(frame==CurrentAnimation->size()){ frame=0; } start=glfwGetTime(); SetTexCoords(); } }
void Sprite::SetAnimation(std::string nAni){ if(CurrentAnimation!=&AnimationDatabase[nAni]){ CurrentAnimation=&AnimationDatabase[nAni]; start=glfwGetTime(); frame=0; SetTexCoords(); } }
void VertexArray::SetTo2DQuad(float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2, float z) { float vcorners[12]; float uvs[8]; int bfaces[6]; SetVertexData2DQuad(x1,y1,x2,y2,u1,v1,u2,v2, vcorners, uvs, bfaces); for (int i = 2; i < 12; i += 3) vcorners[i] = z; SetFaces(bfaces, 6); SetVertices(vcorners, 12); SetTexCoordSets(1); SetTexCoords(0, uvs, 8); }
void VertexArray::Add( const unsigned char newcol[], int newcolcount, const float newnorm[], int newnormcount, const float newvert[], int newvertcount, const int newfaces[], int newfacecount, const float newtc[], int newtccount) { assert(texcoords.size() == 1); SetFaces(newfaces, newfacecount, faces.size(), vertices.size() / 3); SetVertices(newvert, newvertcount, vertices.size()); SetNormals(newnorm, newnormcount, normals.size()); SetColors(newcol, newcolcount, colors.size()); SetTexCoords(0, newtc, newtccount, texcoords[0].size()); }
void PhysicSprite::Update(){ for(unsigned int i=0;i<ReferencePolygon->Vertex.size();i++){ vertex[i*2]=ReferencePolygon->Vertex[i].x; vertex[i*2+1]=ReferencePolygon->Vertex[i].y; } if(glfwGetTime()-start>(*CurrentAnimation)[frame].duration){ frame++; if(frame==CurrentAnimation->size()){ frame=0; } start=glfwGetTime(); SetTexCoords(); } }
void VertexArray::SetTo2DButton(float x, float y, float w, float h, float sidewidth, bool flip) { float vcorners[12*3]; float uvs[8*3]; int bfaces[6*3]; //y1 = 1.0 - y1; //y2 = 1.0 - y2; Vec2 corner1; Vec2 corner2; Vec2 dim; dim.Set(w,h); Vec2 center; center.Set(x,y); corner1 = center - dim*0.5; corner2 = center + dim*0.5; float x1 = corner1[0]; float y1 = corner1[1]; float x2 = corner2[0]; float y2 = corner2[1]; if (flip) { float y3 = y1; y1 = y2; y2 = y3; } //left SetVertexData2DQuad(x1-sidewidth,y1,x1,y2, 0,0,0.5,1, vcorners, uvs, bfaces); //center SetVertexData2DQuad(x1,y1,x2,y2, 0.5,0,0.5,1, &(vcorners[12]), &(uvs[8]), &(bfaces[6]), 4); //right SetVertexData2DQuad(x2,y1,x2+sidewidth,y2, 0.5,0,1,1, &(vcorners[12*2]), &(uvs[8*2]), &(bfaces[6*2]), 8); SetFaces(bfaces, 6*3); SetVertices(vcorners, 12*3); SetTexCoordSets(1); SetTexCoords(0, uvs, 8*3); }
void VertexArray::SetToBillboard(float x1, float y1, float x2, float y2) { int bfaces[6]; bfaces[0] = 0; bfaces[1] = 1; bfaces[2] = 2; bfaces[3] = 0; bfaces[4] = 2; bfaces[5] = 3; SetFaces(bfaces, 6); float normals[12]; for (int i = 0; i < 12; i+=3) { normals[i] = 0; normals[i+1] = 0; normals[i+2] = 1; } SetNormals(normals, 12); //build this: //x1, y1, 0 //x2, y1, 0 //x2, y2, 0 //x1, y2, 0 float verts[12]; verts[2] = verts[5] = verts[8] = verts[11] = 0.0; verts[0] = verts[9] = x1; verts[3] = verts[6] = x2; verts[1] = verts[4] = y1; verts[7] = verts[10] = y2; SetVertices(verts, 12); float tc[8]; tc[0] = tc[1] = tc[3] = tc[6] = 0.0; tc[2] = tc[4] = tc[5] = tc[7] = 1.0; SetTexCoordSets(1); SetTexCoords(0, tc, 8); }
void VertexArray::SetTo2DBox(float x, float y, float w, float h, float marginwidth, float marginheight, float clipx) { const unsigned int quads = 9; float vcorners[12*quads]; float uvs[8*quads]; int bfaces[6*quads]; //y1 = 1.0 - y1; //y2 = 1.0 - y2; Vec2 corner1; Vec2 corner2; Vec2 dim; dim.Set(w,h); Vec2 center; center.Set(x,y); corner1 = center - dim*0.5; corner2 = center + dim*0.5; Vec2 margin; margin.Set(marginwidth, marginheight); float lxmax = std::max((corner1-margin)[0],std::min(clipx,corner1[0])); float cxmax = std::max(corner1[0],std::min(clipx,corner2[0])); float rxmax = std::max(corner2[0],std::min(clipx,(corner2+margin)[0])); float lumax = (lxmax-(corner1-margin)[0])/(corner1[0]-(corner1-margin)[0])*0.5; float rumax = (rxmax-corner2[0])/((corner2+margin)[0]-corner2[0])*0.5+0.5; //upper left SetVertexData2DQuad((corner1-margin)[0],(corner1-margin)[1],lxmax,corner1[1], 0,0,lumax,0.5, vcorners,uvs,bfaces); //upper center SetVertexData2DQuad(corner1[0],(corner1-margin)[1],cxmax,corner1[1], 0.5,0,0.5,0.5, &(vcorners[12*1]),&(uvs[8*1]),&(bfaces[6*1]),4*1); //upper right SetVertexData2DQuad(corner2[0],(corner1-margin)[1],rxmax,corner1[1], 0.5,0,rumax,0.5, &(vcorners[12*2]),&(uvs[8*2]),&(bfaces[6*2]),4*2); //center left SetVertexData2DQuad((corner1-margin)[0],corner1[1],lxmax,corner2[1], 0,0.5,lumax,0.5, &(vcorners[12*3]),&(uvs[8*3]),&(bfaces[6*3]),4*3); //center center SetVertexData2DQuad(corner1[0],corner1[1],cxmax,corner2[1], 0.5,0.5,0.5,0.5, &(vcorners[12*4]),&(uvs[8*4]),&(bfaces[6*4]),4*4); //center right SetVertexData2DQuad(corner2[0],corner1[1],rxmax,corner2[1], 0.5,0.5,rumax,0.5, &(vcorners[12*5]),&(uvs[8*5]),&(bfaces[6*5]),4*5); //lower left SetVertexData2DQuad((corner1-margin)[0],corner2[1],lxmax,(corner2+margin)[1], 0,0.5,lumax,1, &(vcorners[12*6]),&(uvs[8*6]),&(bfaces[6*6]),4*6); //lower center SetVertexData2DQuad(corner1[0],corner2[1],cxmax,(corner2+margin)[1], 0.5,0.5,0.5,1, &(vcorners[12*7]),&(uvs[8*7]),&(bfaces[6*7]),4*7); //lower right SetVertexData2DQuad(corner2[0],corner2[1],rxmax,(corner2+margin)[1], 0.5,0.5,rumax,1, &(vcorners[12*8]),&(uvs[8*8]),&(bfaces[6*8]),4*8); SetFaces(bfaces, 6*quads); SetVertices(vcorners, 12*quads); SetTexCoordSets(1); SetTexCoords(0, uvs, 8*quads); }