void CGraphic::DrawSkyBoard( const CFRect& rt, uint32 Color, ITexture* pTexture, const float& uoffset, const float& voffset, ERenderStyle rs, float z ) { if ( Color == 0 ) return; float x1 = (float)rt.left; float y1 = (float)rt.top; float x2 = (float)rt.right; float y2 = (float)rt.bottom; if ( pTexture ) { Vertex2D* pVB; GetRenderStack( rs, pTexture, NULL, PT_TRIANGLESTRIP, 4, 2, Vertex2D::Format, sizeof(Vertex2D), (void**)&pVB, NULL ); float u1 = 0.00001f+uoffset; float v1 = 0.00001f+voffset; float u2 = 1.00001f+uoffset; float v2 = 1.00001f+voffset; pVB[0] = Vertex2D( x1, y2, z, Color, u1, v2 ); //对点写数据 pVB[1] = Vertex2D( x1, y1, z, Color, u1, v1 ); pVB[2] = Vertex2D( x2, y2, z, Color, u2, v2 ); pVB[3] = Vertex2D( x2, y1, z, Color, u2, v1 ); } }
// this function draws the shape of the object with a black outline (no solid fill) // only used in the editor and not the game // // this is called after the grid lines have been drawn on the map. draws a solid // outline over the grid lines // void DispReel::Render(Sur * const psur) { if (!GetPTable()->GetEMReelsEnabled()) return; psur->SetBorderColor(RGB(0, 0, 0), false, 0); psur->SetFillColor(-1); psur->SetObject(this); psur->SetObject(NULL); // draw background box psur->Rectangle(m_d.m_v1.x, m_d.m_v1.y, m_d.m_v2.x, m_d.m_v2.y); // draw n reels in the box for (int i = 0; i < m_d.m_reelcount; ++i) { // set up top corner point const float fi = (float)i; const float x = m_d.m_v1.x + fi*(m_d.m_width + m_d.m_reelspacing) + m_d.m_reelspacing; const float y = m_d.m_v1.y + m_d.m_reelspacing; const float x2 = x + m_d.m_width; const float y2 = y + m_d.m_height; // set up points (clockwise) const Vertex2D rgv[4] = { Vertex2D(x, y), Vertex2D(x2, y), Vertex2D(x2, y2), Vertex2D(x, y2) }; psur->Polygon(rgv, 4); } }
// this function draws the shape of the object with a solid fill // only used in the editor and not the game // // this is called before the grid lines are drawn on the map // void DispReel::PreRender(Sur * const psur) { psur->SetBorderColor(-1, false, 0); psur->SetFillColor(m_d.m_backcolor); psur->SetObject(this); // draw background box psur->Rectangle(m_d.m_v1.x, m_d.m_v1.y, m_d.m_v2.x, m_d.m_v2.y); // draw n reels in the box (in blue) psur->SetFillColor(RGB(0, 0, 255)); for (int i = 0; i < m_d.m_reelcount; ++i) { // set up top corner point const float fi = (float)i; const float x = m_d.m_v1.x + fi*(m_d.m_width + m_d.m_reelspacing) + m_d.m_reelspacing; const float y = m_d.m_v1.y + m_d.m_reelspacing; const float x2 = x + m_d.m_width; const float y2 = y + m_d.m_height; // set up points (clockwise) const Vertex2D rgv[4] = { Vertex2D(x, y), Vertex2D(x2, y), Vertex2D(x2, y2), Vertex2D(x, y2) }; psur->Polygon(rgv, 4); } }
void Spinner::GetHitShapes(vector<HitObject*> &pvho) { const float height = m_ptable->GetSurfaceHeight(m_d.m_szSurface, m_d.m_vCenter.x, m_d.m_vCenter.y); const float h = m_d.m_height + 30.0f; const float angleMin = min(m_d.m_angleMin, m_d.m_angleMax); // correct angle inversions const float angleMax = max(m_d.m_angleMin, m_d.m_angleMax); m_d.m_angleMin = angleMin; m_d.m_angleMax = angleMax; HitSpinner * const phitspinner = new HitSpinner(this, height); m_phitspinner = phitspinner; pvho.push_back(phitspinner); if (m_d.m_fShowBracket) { /*add a hit shape for the bracket if shown, just in case if the bracket spinner height is low enough so the ball can hit it*/ const float halflength = m_d.m_length * 0.5f + (m_d.m_length*0.1875f); const float radangle = ANGTORAD(m_d.m_rotation); const float sn = sinf(radangle); const float cs = cosf(radangle); HitCircle *phitcircle; phitcircle = new HitCircle(Vertex2D(m_d.m_vCenter.x + cs*halflength, m_d.m_vCenter.y + sn*halflength), m_d.m_length*0.075f, height + m_d.m_height, height + h); pvho.push_back(phitcircle); phitcircle = new HitCircle(Vertex2D(m_d.m_vCenter.x - cs*halflength, m_d.m_vCenter.y - sn*halflength), m_d.m_length*0.075f, height + m_d.m_height, height + h); pvho.push_back(phitcircle); } }
void CGraphic::DrawRect( const CFRect& rt, uint32 Color, ITexture* pTexture, const CFRect* rtText, ERenderStyle RS, float z ) { if ( Color == 0 ) return; float x1 = (float)rt.left; float y1 = (float)rt.top; float x2 = (float)rt.right; float y2 = (float)rt.bottom; if ( pTexture ) { Vertex2D* pVB; GetRenderStack( RS, pTexture, NULL, PT_TRIANGLESTRIP, 4, 2, Vertex2D::Format, sizeof(Vertex2D), (void**)&pVB, NULL ); float u1 = 0.00001f; float v1 = 0.00001f; float u2 = 1.00001f; float v2 = 1.00001f; if ( rtText ) { u1 = ( rtText->left + 0.25f )/pTexture->GetWidth(); v1 = ( rtText->top + 0.25f )/pTexture->GetHeight(); u2 = ( rtText->right + 0.25f )/pTexture->GetWidth(); v2 = ( rtText->bottom + 0.25f )/pTexture->GetHeight(); } pVB[0] = Vertex2D( x1, y2, z, Color, u1, v2 ); //对点写数据 pVB[1] = Vertex2D( x1, y1, z, Color, u1, v1 ); pVB[2] = Vertex2D( x2, y2, z, Color, u2, v2 ); pVB[3] = Vertex2D( x2, y1, z, Color, u2, v1 ); } else { VerColor2D* pVB; GetRenderStack( RS, NULL, NULL, PT_TRIANGLESTRIP, 4, 2, VerColor2D::Format, sizeof(VerColor2D), (void**)&pVB, NULL ); pVB[0] = VerColor2D( x1, y2, z, Color ); pVB[1] = VerColor2D( x1, y1, z, Color ); pVB[2] = VerColor2D( x2, y2, z, Color ); pVB[3] = VerColor2D( x2, y1, z, Color ); } }
void CGraphic::DrawRect( const CFRect& rt, uint32 Color, ITexture* pTexture, const CPosRect& rtText, ERenderStyle RS, float z ) { if ( Color == 0 ) return; float x1 = rt.left; float y1 = rt.top; float x2 = rt.right; float y2 = rt.bottom; if ( pTexture ) { Vertex2D* pVB; GetRenderStack( RS, pTexture, NULL, PT_TRIANGLESTRIP, 4, 2, Vertex2D::Format, sizeof(Vertex2D), (void**)&pVB, NULL ); float uLT = ( rtText.ptLT.x + 0.25f )/pTexture->GetWidth(); float vLT = ( rtText.ptLT.y + 0.25f )/pTexture->GetHeight(); float uRT = ( rtText.ptRT.x + 0.25f )/pTexture->GetWidth(); float vRT = ( rtText.ptRT.y + 0.25f )/pTexture->GetHeight(); float uLB = ( rtText.ptLB.x + 0.25f )/pTexture->GetWidth(); float vLB = ( rtText.ptLB.y + 0.25f )/pTexture->GetHeight(); float uRB = ( rtText.ptRB.x + 0.25f )/pTexture->GetWidth(); float vRB = ( rtText.ptRB.y + 0.25f )/pTexture->GetHeight(); pVB[0] = Vertex2D( x1, y2, z, Color, uLB, vLB ); pVB[1] = Vertex2D( x1, y1, z, Color, uLT, vLT ); pVB[2] = Vertex2D( x2, y2, z, Color, uRB, vRB ); pVB[3] = Vertex2D( x2, y1, z, Color, uRT, vRT ); } else { VerColor2D* pVB; GetRenderStack( RS, NULL, NULL, PT_TRIANGLESTRIP, 4, 2, VerColor2D::Format, sizeof(VerColor2D), (void**)&pVB, NULL ); pVB[0] = VerColor2D( x1, y2, z, Color ); pVB[1] = VerColor2D( x1, y1, z, Color ); pVB[2] = VerColor2D( x2, y2, z, Color ); pVB[3] = VerColor2D( x2, y1, z, Color ); } }
Image::Image() { // Initialize Vertex and Index buffer vBuffer = 0; iBuffer = 0; int j; int i; for(i = 0; i < 4; i++) verts[i] = Vertex2D(VertexPos2D(0, 0), TexCoord(0, 0)); for(i = 0; i < 4; i++) indices[i] = 0; }
void Image::initVBO() { if(vBuffer != 0) glDeleteBuffers(1, &vBuffer); if(iBuffer != 0) glDeleteBuffers(1, &iBuffer); vBuffer = 0; iBuffer = 0; // Assign vertices verts[0] = Vertex2D(VertexPos2D(0, 0), TexCoord(1.0f, 0.0f)); verts[1] = Vertex2D(VertexPos2D((GLfloat)tex.width(), 0), TexCoord(0.0f, 0.0f)); verts[2] = Vertex2D(VertexPos2D((GLfloat)tex.width(), (GLfloat)tex.height()), TexCoord(0.0f, 1.0f)); verts[3] = Vertex2D(VertexPos2D(0, (GLfloat)tex.height()), TexCoord(1.0f, 1.0f)); // Initialize indices indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 3; // Create VBO glGenBuffers(1, &vBuffer); glBindBuffer(GL_ARRAY_BUFFER, vBuffer); glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex2D), verts, GL_DYNAMIC_DRAW); // Create IBO glGenBuffers(1, &iBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4 * sizeof(GLuint), indices, GL_DYNAMIC_DRAW); // Unbind Buffers glBindBuffer(GL_ARRAY_BUFFER, NULL); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL); }
void SuperShape2D::fillVertexBuffer() { float radius = 0; float p = 2*M_PI /(float) v_points; int i = 0; for( float y = 0; y < 2*M_PI; y += p) { radius = evaluateR(y); float xC = 5*radius * cos(y); float yC = 5*radius * sin(y); int c = 0xff0000; vertexBuffer[i] = Vertex2D(xC,yC, c); i++; } }
void Scene::loadRoom(XMLDocument& doc){ XMLElement *room = doc.FirstChildElement("scene")->FirstChildElement("room"); std::unique_ptr<glimac::Image> wallTexture = glimac::loadImage(room->FirstChildElement("walls")->GetText()); std::unique_ptr<glimac::Image> floorTexture = glimac::loadImage(room->FirstChildElement("floor")->GetText()); std::unique_ptr<glimac::Image> roofTexture = glimac::loadImage(room->FirstChildElement("roof")->GetText()); if (wallTexture == NULL || floorTexture == NULL || roofTexture == NULL) { std::cerr << "Erreur lors du chargement de l'image" << std::endl; } _width = atof(room->FirstChildElement("width")->GetText()); _height = atof(room->FirstChildElement("height")->GetText()); _depth = atof(room->FirstChildElement("depth")->GetText()); _wallLimits.x = atof(room->FirstChildElement("xmax")->GetText()); _wallLimits.y = atof(room->FirstChildElement("xmin")->GetText()); _wallLimits.z = atof(room->FirstChildElement("zmax")->GetText()); _wallLimits.w = atof(room->FirstChildElement("zmin")->GetText()); // Create an array of texture and bind each texture glGenTextures(3, _texturesArray); glBindTexture(GL_TEXTURE_2D, _texturesArray[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wallTexture->getWidth(), wallTexture->getHeight(), 0, GL_RGBA, GL_FLOAT, wallTexture->getPixels()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D,0); glBindTexture(GL_TEXTURE_2D, _texturesArray[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, floorTexture->getWidth(), floorTexture->getHeight(), 0, GL_RGBA, GL_FLOAT, floorTexture->getPixels()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D,0); glBindTexture(GL_TEXTURE_2D, _texturesArray[2]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, roofTexture->getWidth(), roofTexture->getHeight(), 0, GL_RGBA, GL_FLOAT, roofTexture->getPixels()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D,0); glGenBuffers (1, &_vbo); glBindBuffer(GL_ARRAY_BUFFER, _vbo); // Quad (wall) coordonates // TODO hardcoded, pass it as a parameter to the function ? Vertex2D vertices[] = { Vertex2D(glm::vec3(0, 0,0), glm::vec2(4, 0)), // Sommet 0 Vertex2D(glm::vec3(_width, 0,0), glm::vec2(0, 0)), // Sommet 1 Vertex2D(glm::vec3(_width, _height,0), glm::vec2(0, 4)), // Sommet 2 Vertex2D(glm::vec3(0, _height,0), glm::vec2(4, 4)) // Sommet 3 }; glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex2D), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); GLuint ibo; glGenBuffers(1, &ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); uint32_t indices[] = { 0, 1, 2, 0, 2, 3 }; glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(uint32_t), indices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glGenVertexArrays(1, &_vao); glBindVertexArray(_vao); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); const GLuint VERTEX_ATTR_POSITION = 0; const GLuint VERTEX_ATTR_COLOR = 1; glEnableVertexAttribArray(VERTEX_ATTR_POSITION); glEnableVertexAttribArray(VERTEX_ATTR_COLOR); glBindBuffer(GL_ARRAY_BUFFER, _vbo); glVertexAttribPointer(VERTEX_ATTR_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (const GLvoid*) offsetof(Vertex2D, position)); glVertexAttribPointer(VERTEX_ATTR_COLOR, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (const GLvoid*) offsetof(Vertex2D, texture)); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); }
void CRenderTarget::Flip() { m_matPreDeltaView = m_matCurDeltaView; m_matCurDeltaView.Identity(); CGraphic* pGph = CGraphic::GetInst(); for ( int i = 0; i < m_nNearCount; i++ ) { Vertex2D* pVB; RenderState* pRS; if( pGph->GetRenderStack( RS_DEFAULT, m_NearFilter[i].pText, NULL, PT_TRIANGLESTRIP, 4, 2, Vertex2D::Format, sizeof(Vertex2D), (void**)&pVB, NULL, (void**)&pRS ) ) { if ( m_NearFilter[i].bRatio ) { pVB[0] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.bottom), 0.99999994f, m_NearFilter[i].dwColor, m_NearFilter[i].cTexRt.left, m_NearFilter[i].cTexRt.bottom ); pVB[1] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.top), 0.99999994f, m_NearFilter[i].dwColor, m_NearFilter[i].cTexRt.left, m_NearFilter[i].cTexRt.top ); pVB[2] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.bottom),0.99999994f, m_NearFilter[i].dwColor, m_NearFilter[i].cTexRt.right, m_NearFilter[i].cTexRt.bottom ); pVB[3] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.top), 0.99999994f, m_NearFilter[i].dwColor, m_NearFilter[i].cTexRt.right, m_NearFilter[i].cTexRt.top ); pRS->m_UAddr_S0 = m_NearFilter[i].eSamp; pRS->m_VAddr_S0 = m_NearFilter[i].eSamp; } else { pVB[0] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.bottom), 0.99999994f, m_NearFilter[i].dwColor, 0, 1 ); pVB[1] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.top), 0.99999994f, m_NearFilter[i].dwColor, 0, 0 ); pVB[2] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.bottom),0.99999994f, m_NearFilter[i].dwColor, 1, 1 ); pVB[3] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.top), 0.99999994f, m_NearFilter[i].dwColor, 1, 0 ); } if(m_NearFilter[i].pText == NULL) { pRS->m_TexOP_S0 = TOP_SELECTARG2; pRS->m_AlpOP_S0 = TOP_SELECTARG2; } else pRS->m_AlpOP_S0 = TOP_MODULATE; pRS->m_LightEnable = FALSE; if ( !m_NearFilter[i].bMulti ) pRS->m_DestBlend = BLEND_ONE; } } m_nNearCount = 0; for ( int i = 0; i < m_nFarCount; i++ ) { Vertex2D* pVB; RenderState* pRS; if( pGph->GetRenderStack( RS_DEFAULT, m_FarFilter[i].pText, NULL, PT_TRIANGLESTRIP, 4, 2, Vertex2D::Format, sizeof(Vertex2D), (void**)&pVB, NULL, (void**)&pRS ) ) { if ( m_FarFilter[i].bRatio ) { pVB[0] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.bottom), 0.000018f, m_FarFilter[i].dwColor, m_FarFilter[i].cTexRt.left, m_FarFilter[i].cTexRt.bottom ); pVB[1] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.top), 0.000018f, m_FarFilter[i].dwColor, m_FarFilter[i].cTexRt.left, m_FarFilter[i].cTexRt.top ); pVB[2] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.bottom),0.000018f, m_FarFilter[i].dwColor, m_FarFilter[i].cTexRt.right, m_FarFilter[i].cTexRt.bottom ); pVB[3] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.top), 0.000018f, m_FarFilter[i].dwColor, m_FarFilter[i].cTexRt.right, m_FarFilter[i].cTexRt.top ); pRS->m_UAddr_S0 = m_FarFilter[i].eSamp; pRS->m_VAddr_S0 = m_FarFilter[i].eSamp; } else { pVB[0] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.bottom), 0.000018f, m_FarFilter[i].dwColor, 0, 1 ); pVB[1] = Vertex2D( float(m_rcViewPort.left),float(m_rcViewPort.top), 0.000018f, m_FarFilter[i].dwColor, 0, 0 ); pVB[2] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.bottom),0.000018f, m_FarFilter[i].dwColor, 1, 1 ); pVB[3] = Vertex2D( float(m_rcViewPort.right),float(m_rcViewPort.top), 0.000018f, m_FarFilter[i].dwColor, 1, 0 ); } if(m_FarFilter[i].pText == NULL) { pRS->m_TexOP_S0 = TOP_SELECTARG2; pRS->m_AlpOP_S0 = TOP_SELECTARG2; } else pRS->m_AlpOP_S0 = TOP_MODULATE; pRS->m_LightEnable = FALSE; if ( !m_FarFilter[i].bMulti ) pRS->m_DestBlend = BLEND_ONE; } } m_nFarCount = 0; for ( int i = 0; i < m_nPostCount; i++ ) { m_PostFilter[i]->RenderFilter(); } m_nPostCount = 0; }
void OpenGlBox::initialiseQuads() { //Screen quad mQuad.quad[0] = Vertex2D(-1.f, -1.f, 0.f, 0.f); mQuad.quad[1] = Vertex2D(1.f, -1.f, 1.f, 0.f); mQuad.quad[2] = Vertex2D(-1.f, 1.f, 0.f, 1.f); mQuad.quad[3] = Vertex2D(-1.f, 1.f, 0.f, 1.f); mQuad.quad[4] = Vertex2D(1.f, -1.f, 1.f, 0.f); mQuad.quad[5] = Vertex2D(1.f, 1.f, 1.f, 1.f); mQuad.VBO = ~0u; glGenBuffers(1, &mQuad.VBO); glBindBuffer(GL_ARRAY_BUFFER, mQuad.VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex2D) * 6, mQuad.quad, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), NULL); mHistQuad.quad[0] = Vertex2D(-1.f, -1.f, 0.f, 0.f); mHistQuad.quad[1] = Vertex2D(1.f, -1.f, 1.f, 0.f); mHistQuad.quad[2] = Vertex2D(-1.f, 1.f, 0.f, 1.f); mHistQuad.quad[3] = Vertex2D(-1.f, 1.f, 0.f, 1.f); mHistQuad.quad[4] = Vertex2D(1.f, -1.f, 1.f, 0.f); mHistQuad.quad[5] = Vertex2D(1.f, 1.f, 1.f, 1.f); mHistQuad.VBO = ~0u; glGenBuffers(1, &mHistQuad.VBO); glBindBuffer(GL_ARRAY_BUFFER, mHistQuad.VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex2D) * 6, mHistQuad.quad, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), NULL); }
void LineLight(RenderContext* render, Vertex2D from, Vertex2D to) { if (from.IsUVNormal() && to.IsUVNormal()) { Vec2i size(render->bmp->bmp_width, render->bmp->bmp_height); from.ToRealUV(size); to.ToRealUV(size); } int x, y, remain = 0; Vec3i color; Vec3f ratio_c; Vec2f textc, ratio_tc; float distance = (to.p - from.p).Length(); ratio_c.x = (to.c.x - from.c.x) / distance; ratio_c.y = (to.c.y - from.c.y) / distance; ratio_c.z = (to.c.z - from.c.z) / distance; ratio_tc.x = (to.tc.x - from.tc.x) / distance; ratio_tc.y = (to.tc.y - from.tc.y) / distance; float length; if (from.p.x == to.p.x && from.p.y == to.p.y) { render->LightPixel(Vertex2D(from.p, to.c, to.tc)); } else if (from.p.x == to.p.x) { int inc = (from.p.y <= to.p.y) ? 1 : -1; for (y = from.p.y; y != to.p.y; y += inc) { length = abs(y - from.p.y); color = Interpolate(from.c, length, ratio_c); textc = Interpolate(from.tc, length, ratio_tc); render->LightPixel(Vertex2D({ from.p.x, y }, color, textc)); } render->LightPixel(Vertex2D(to.p,to.c, to.tc)); } else if (from.p.y == to.p.y) { int inc = (from.p.x <= to.p.x) ? 1 : -1; for (x = from.p.x; x != to.p.x; x += inc) { length = abs(x - from.p.x); color = Interpolate(from.c, length, ratio_c); textc = Interpolate(from.tc, length, ratio_tc); render->LightPixel(Vertex2D({ x, from.p.y }, color, textc)); } render->LightPixel(Vertex2D(to.p, to.c,to.tc)); } else { int dx = (from.p.x < to.p.x) ? to.p.x - from.p.x : from.p.x - to.p.x; int dy = (from.p.y < to.p.y) ? to.p.y - from.p.y : from.p.y - to.p.y; if (dx >= dy) { if (to.p.x < from.p.x) x = from.p.x, y = from.p.y, from.p.x = to.p.x, from.p.y = to.p.y, to.p.x = x, to.p.y = y; for (x = from.p.x, y = from.p.y; x <= to.p.x; x++) { length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio_c); textc = Interpolate(from.tc, length, ratio_tc); render->LightPixel(Vertex2D({ x, y }, color, textc)); remain += dy; if (remain >= dx) { remain -= dx; y += (to.p.y >= from.p.y) ? 1 : -1; length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio_c); textc = Interpolate(from.tc, length, ratio_tc); render->LightPixel(Vertex2D({ x, y }, color, textc)); } } render->LightPixel(Vertex2D(to.p, to.c,to.tc)); } else { if (to.p.y < from.p.y) x = from.p.x, y = from.p.y, from.p.x = to.p.x, from.p.y = to.p.y, to.p.x = x, to.p.y = y; for (x = from.p.x, y = from.p.y; y <= to.p.y; y++) { length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio_c); textc = Interpolate(from.tc, length, ratio_tc); render->LightPixel(Vertex2D({ x, y }, color, textc)); remain += dx; if (remain >= dy) { remain -= dy; x += (to.p.x >= from.p.x) ? 1 : -1; length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio_c); textc = Interpolate(from.tc, length, ratio_tc); render->LightPixel(Vertex2D({ x, y }, color, textc)); } } render->LightPixel(Vertex2D(to.p, to.c,to.tc)); } } }
void LineInterpolate(RenderContext* render, Vertex2D from, Vertex2D to) { int x, y, rem = 0; Vec3i color; float distance = (to.p - from.p).Length(); Vec3f ratio; ratio.x = (to.c.x - from.c.x) / distance; ratio.y = (to.c.y - from.c.y) / distance; ratio.z = (to.c.z - from.c.z) / distance; float length; if (from.p.x == to.p.x && from.p.y == to.p.y) { render->SetPixel(Vertex2D(from.p, to.c)); } else if (from.p.x == to.p.x) { int inc = (from.p.y <= to.p.y) ? 1 : -1; for (y = from.p.y; y != to.p.y; y += inc) { length = abs(y - from.p.y); color = Interpolate(from.c, length, ratio); render->SetPixel(Vertex2D({ from.p.x, y }, color)); } render->SetPixel(Vertex2D(to.p, to.c)); } else if (from.p.y == to.p.y) { int inc = (from.p.x <= to.p.x) ? 1 : -1; for (x = from.p.x; x != to.p.x; x += inc) { length = abs(x - from.p.x); color = Interpolate(from.c, length, ratio); render->SetPixel(Vertex2D({ x, from.p.y }, color)); } render->SetPixel(Vertex2D(to.p, to.c)); } else { int dx = (from.p.x < to.p.x) ? to.p.x - from.p.x : from.p.x - to.p.x; int dy = (from.p.y < to.p.y) ? to.p.y - from.p.y : from.p.y - to.p.y; if (dx >= dy) { if (to.p.x < from.p.x) x = from.p.x, y = from.p.y, from.p.x = to.p.x, from.p.y = to.p.y, to.p.x = x, to.p.y = y; for (x = from.p.x, y = from.p.y; x <= to.p.x; x++) { length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio); render->SetPixel(Vertex2D({ x, y }, color)); rem += dy; if (rem >= dx) { rem -= dx; y += (to.p.y >= from.p.y) ? 1 : -1; length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio); render->SetPixel(Vertex2D({ x, y }, color)); } } render->SetPixel(Vertex2D(to.p, to.c)); } else { if (to.p.y < from.p.y) x = from.p.x, y = from.p.y, from.p.x = to.p.x, from.p.y = to.p.y, to.p.x = x, to.p.y = y; for (x = from.p.x, y = from.p.y; y <= to.p.y; y++) { length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio); render->SetPixel(Vertex2D({ x, y }, color)); rem += dx; if (rem >= dy) { rem -= dy; x += (to.p.x >= from.p.x) ? 1 : -1; length = (Vec2i(x, y) - from.p).Length(); color = Interpolate(from.c, length, ratio); render->SetPixel(Vertex2D({ x, y }, color)); } } render->SetPixel(Vertex2D(to.p, to.c)); } } }