void screenOperations::fillTopTriangle(std::vector<Ponto> &in_pontos, std::vector<Ponto> &in_proj, std::vector<Vetor> &normais, int a, int b, int c) { Ponto p1 = in_proj[a], p2 = in_proj[b], p3 = in_proj[c]; double a1 = (p3.x_-p1.x_)/(p3.y_-p1.y_); double a2 = (p3.x_-p2.x_)/(p3.y_-p2.y_); double xmin = p3.x_, xmax = p3.x_; int botx = std::min(p1.x_, std::min(p2.x_, p3.x_)); int topx = std::max(p1.x_, std::max(p2.x_, p3.x_)); int qtd = (int)ceil(p3.y_-p1.y_)+1, id = 0; for(int y = (int)floor(p3.y_+0.5); id < qtd; ++id, --y, xmin -= a1, xmax -= a2) { for(int x = (int)floor(xmin+0.5); x <= (int)ceil(xmax+0.5); ++x) { int printy = std::max(y, (int)floor(p1.y_)); printy = std::min(printy, (int)ceil(p3.y_)); int printx = std::max(x, (int)botx); printx = std::min(printx, (int)topx); if(valid(printx, printy)) { Ponto toPlace = Ponto(printx, printy, 0.0); this->placeBuffer(in_pontos, in_proj, normais, toPlace, a, b, c); } } } }
static int regplayer(lua_State *L) { const char *name = lua_tostring(L, 1); double x = lua_tonumber(L, 2); double y = lua_tonumber(L, 3); (*play)[name] = Ponto(x, y); return 0; }
void EdicaoCallback::translate(int key) { switch(key) { case GLUT_KEY_UP: objetoCorrente->aplicaTransformacao(Transformacao::translacao(Ponto(0, TRANSLACAO))); break; case GLUT_KEY_RIGHT: objetoCorrente->aplicaTransformacao(Transformacao::translacao(Ponto(TRANSLACAO, 0))); break; case GLUT_KEY_DOWN: objetoCorrente->aplicaTransformacao(Transformacao::translacao(Ponto(0, -TRANSLACAO))); break; case GLUT_KEY_LEFT: objetoCorrente->aplicaTransformacao(Transformacao::translacao(Ponto(-TRANSLACAO, 0))); break; } }
std::vector<Ponto> viewOperations::screenProjection(std::vector<Ponto> in, double resX, double resY) { std::vector<Ponto> res; for(int i = 0; i < (int)in.size(); ++i) { //if(in[i].z_ < this->d + EPS) continue; Ponto act = Ponto(); //std::cout<< "oi"; act.x_ = (this->d/this->hx)*(in[i].x_/in[i].z_); act.y_ = (this->d/this->hy)*(in[i].y_/in[i].z_); act.z_ = 0.0; act.h_ = 1.0; act.x_ = ((act.x_+1.0)/2.0)*(resX-1.0); act.y_ = ((1.0-act.y_)/2.0)*(resY-1.0); res.push_back(act); } return res; }
Ponto viewOperations::worldToView(const Ponto &p, const Ponto &c) { Vetor res = Vetor(); res = (this->camCoords_) * (p-c); Ponto p_ = Ponto(res.x_,res.y_,res.z_); return p_; }
void screenOperations::scanLine(std::vector<Ponto> &in_pontos, std::vector<Vetor> &normais, std::vector<int> &in_nproj, std::vector<Ponto> &in_proj, int resX, int resY) { //std::cout << "entra" << std::endl; for(int i = 0; i < (int)in_nproj.size(); i += 3) { int arr[3]; arr[0] = in_nproj[i]; arr[1] = in_nproj[i+1]; arr[2] = in_nproj[i+2]; while(true) { //if(i==42) std::cout << in_proj[] bool swapped = false; for(int j = 0; j < 2; ++j) { if(!cmpByY(in_proj[arr[j]], in_proj[arr[j+1]])) { std::swap(arr[j], arr[j+1]); swapped = true; } } if(!swapped) break; } if(cmp(in_proj[arr[1]].y_, in_proj[arr[2]].y_) == 0) { this->fillBottomTriangle(in_pontos, in_proj, normais, arr[0], arr[1], arr[2]); } else if(cmp(in_proj[arr[0]].y_, in_proj[arr[1]].y_) == 0) { this->fillTopTriangle(in_pontos, in_proj, normais, arr[0], arr[1], arr[2]); } else { int guardat2 = arr[1], guardat3 = arr[2]; Ponto t1 = in_proj[arr[0]], t2 = in_proj[arr[1]], t3 = in_proj[arr[2]]; Ponto t4 = Ponto(floor(t1.x_+(t2.y_-t1.y_)*(t3.x_-t1.x_)/(t3.y_-t1.y_)+0.5), floor(t2.y_+0.5), 0.0); std::pair<double, std::pair<double, double> > resultado = cord_baricentricas(t4, t1, t2, t3); Ponto vt4 = in_pontos[arr[0]]*resultado.first + in_pontos[arr[1]]*resultado.second.first + in_pontos[arr[2]]*resultado.second.second; Vetor nova_normal = normais[arr[0]]*resultado.first + normais[arr[1]]*resultado.second.first + normais[arr[2]]*resultado.second.second; in_pontos.push_back(vt4); in_proj.push_back(t4); normais.push_back(nova_normal); int novo = (int)in_proj.size()-1; arr[2] = novo; while(1) { bool swapped = false; for(int j = 0; j < 2; ++j) { if(!cmpByY(in_proj[arr[j]], in_proj[arr[j+1]])) { std::swap(arr[j], arr[j+1]); swapped = true; } } if(!swapped) break; } this->fillBottomTriangle(in_pontos, in_proj, normais, arr[0], arr[1], arr[2]); arr[0] = guardat2; arr[1] = guardat3; arr[2] = novo; while(1) { bool swapped = false; for(int j = 0; j < 2; ++j) { if(!cmpByY(in_proj[arr[j]], in_proj[arr[j+1]])) { std::swap(arr[j], arr[j+1]); swapped = true; } } if(!swapped) break; } this->fillTopTriangle(in_pontos, in_proj, normais, arr[0], arr[1], arr[2]); } } //std::cout <<"pow" << std::endl; //std::cout << "ENTREI" << std::endl; //std::cout << "TAMANHO " << (int)in_nproj.size() << std::endl; /*for(int i = 0; i < (int)in_nproj.size(); i += 3){ //std::cout << in_nproj[i] << " " << in_nproj[i+1] << " "<< in_nproj[i+2] << std::endl; Ponto arr[3]; arr[0] = in_proj[in_nproj[i]]; arr[1] = in_proj[in_nproj[i+1]]; arr[2] = in_proj[in_nproj[i+2]]; std::sort(arr, arr+3, cmpByY); Ponto t1 = arr[0], t2 = arr[1], t3 = arr[2]; int v1, v2, v3; for(int j = i; j < i+3; ++j) { if(cmpPoint(t1, in_proj[in_nproj[j]])) v1 = in_nproj[j]; else if(cmpPoint(t2, in_proj[in_nproj[j]])) v2 = in_nproj[j]; else v3 = in_nproj[j]; } //std::cout << v1 << " " << v2 << " " << v3 << std::endl; if(cmp(t2.y_, t3.y_) == 0){ //std::cout << "chamei do if" << std::endl; this->fillBottomTriangle(in_pontos, normais, t1, t2, t3, v1, v2, v3); } else if(cmp(t1.y_, t2.y_) == 0){ //std::cout << "chamei do else if" << std::endl; this->fillTopTriangle(in_pontos, normais, t1, t2, t3, v1, v2, v3); } else { //std::cout << "chamei do else" << std::endl; Ponto t4 = Ponto(floor(t1.x_+(t2.y_-t1.y_)*(t3.x_-t1.x_)/(t3.y_-t1.y_)+0.5), floor(t2.y_+0.5), 0.0); std::pair<double, std::pair<double, double> > aux = cord_baricentricas(t4, t1, t2, t3); Ponto vt4 = in_pontos[v1]*aux.first+in_pontos[v2]*aux.second.first+in_pontos[v3]*aux.second.second; in_pontos.push_back(vt4); normais.push_back(normais[v1]*aux.first+normais[v2]*aux.second.first+normais[v3]*aux.second.second); int novo = (int)in_pontos.size()-1; arr[0] = t1; arr[1] = t2; arr[2] = t4; std::sort(arr, arr+3,cmpByY); int fp, sp, tp; if(cmpPoint(t1, arr[0])) fp = v1; else if(cmpPoint(t1, arr[1])) sp = v1; else tp = v1; if(cmpPoint(t2,arr[0])) fp = v2; else if(cmpPoint(t2, arr[1])) sp = v2; else tp = v2; if(cmpPoint(t4, arr[0])) fp = novo; else if(cmpPoint(t4, arr[1])) sp = novo; else tp = novo; this->fillBottomTriangle(in_pontos, normais, arr[0], arr[1], arr[2], fp, sp, tp); arr[0] = t2; arr[1] = t3; arr[2] = t4; std::sort(arr, arr+3, cmpByY); if(cmpPoint(t2,arr[0])) fp = v2; else if(cmpPoint(t2, arr[1])) sp = v2; else tp = v2; if(cmpPoint(t3, arr[0])) fp = v3; else if(cmpPoint(t3, arr[1])) sp = v3; else tp = v3; if(cmpPoint(t4, arr[0])) fp = novo; else if(cmpPoint(t4, arr[1])) sp = novo; else tp = novo; this->fillTopTriangle(in_pontos, normais, arr[0], arr[1], arr[2], fp, sp, tp); //if(i==0) std::cout << i << std::endl; } }*/ //std::cout << "SAI" << std::endl; }
screenOperations::screenOperations() : cameraCoord_(Ponto()), cameraCoordView_(Ponto()),lightSource_(Ponto()), lightSourceView_(Ponto()), ka_(0.0), Ia_(Vetor()), kd_(0.0), Od_(Vetor()), ks_(0.0), Il_(Vetor()), alpha_(0.0) {}
Ponto MemoriaInterna::keyToPonto(int k) { int x = (k / MAP_DIM) + MAP_MIN; int y = (k % MAP_DIM) + MAP_MIN; return Ponto(x, y); }
/** Função kibada da internet :) **/ Ponto Camada::getPossicaoNaOrbita(double anguloRotacao, double raio, double anguloOrbita) { double x = (raio * cos(paraRadianos(anguloRotacao)) * cos(paraRadianos(anguloOrbita))); double y = (raio * sin(paraRadianos(anguloRotacao)) * cos(paraRadianos(anguloOrbita))); double z = (raio * sin(paraRadianos(anguloRotacao))); return Ponto(x,y,z); }
Vertice::Vertice(GLint x, GLint y) { this->p = Ponto(x, y); selecionado = false; }
Ponto Pontos::keyToPonto(int k) { int x = (k / MAP_DIM) + MAP_MIN; int y = (k % MAP_DIM) + MAP_MIN; return Ponto(x, y); }