void Sphere::DrawLense(sf::RenderWindow *window) { fillVertex(); window->draw(&circle1[0], circle1.size(), sf::Lines); //cout << "I AM HERE" << endl; window->draw(&circle2[0], circle2.size(), sf::Lines); }
void PUParticle3DQuadRender::render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) { //batch and generate draw const ParticlePool &particlePool = particleSystem->getParticlePool(); if (!_isVisible || particlePool.empty()) return; if (_vertexBuffer == nullptr) { GLsizei stride = sizeof(VertexInfo); _vertexBuffer = VertexBuffer::create(stride, 4 * particleSystem->getParticleQuota()); if (_vertexBuffer == nullptr) { CCLOG("PUParticle3DQuadRender::render create vertex buffer failed"); return; } _vertexBuffer->retain(); } if (_indexBuffer == nullptr) { _indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, 6 * particleSystem->getParticleQuota()); if (_indexBuffer == nullptr) { CCLOG("PUParticle3DQuadRender::render create index buffer failed"); return; } _indexBuffer->retain(); } const ParticlePool::PoolList &activeParticleList = particlePool.getActiveDataList(); if (_vertices.size() < activeParticleList.size() * 4) { _vertices.resize(activeParticleList.size() * 4); _indices.resize(activeParticleList.size() * 6); } auto camera = Camera::getVisitingCamera(); auto cameraMat = camera->getNodeToWorldTransform(); //for (auto iter : activeParticleList){ // iter->depthInView = -(viewMat.m[2] * iter->positionInWorld.x + viewMat.m[6] * iter->positionInWorld.y + viewMat.m[10] * iter->positionInWorld.z + viewMat.m[14]); //} //std::sort(activeParticleList.begin(), activeParticleList.end(), compareParticle3D); Vec3 right(cameraMat.m[0], cameraMat.m[1], cameraMat.m[2]); Vec3 up(cameraMat.m[4], cameraMat.m[5], cameraMat.m[6]); Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]); Mat4 pRotMat; Vec3 position; //particle position int vertexindex = 0; int index = 0; int offsetX,offsetY; getOriginOffset(offsetX, offsetY); if (_type == PERPENDICULAR_COMMON) { up = _commonUp; up.normalize(); Vec3::cross(up, _commonDir, &right); right.normalize(); backward = _commonDir; } else if (_type == ORIENTED_COMMON) { up = _commonDir; up.normalize(); Vec3::cross(up, backward, &right); right.normalize(); } for (auto iter : activeParticleList) { auto particle = static_cast<PUParticle3D *>(iter); determineUVCoords(particle); if (_type == ORIENTED_SELF) { Vec3 direction = particle->direction; //transform.transformVector(particle->direction, &direction); up = direction; up.normalize(); Vec3::cross(direction, backward, &right); right.normalize(); } else if (_type == PERPENDICULAR_SELF) { Vec3 direction = particle->direction; //transform.transformVector(particle->direction, &direction); direction.normalize(); //up = PUUtil::perpendicular(direction); //up.normalize(); Vec3::cross(_commonUp, direction, &right); right.normalize(); Vec3::cross(direction, right, &up); up.normalize(); backward = direction; } else if (_type == ORIENTED_SHAPE) { up.set(particle->orientation.x, particle->orientation.y, particle->orientation.z); up.normalize(); Vec3::cross(up, backward, &right); right.normalize(); } Vec3 halfwidth = particle->width * 0.5f * right; Vec3 halfheight = particle->height * 0.5f * up; Vec3 offset = halfwidth * offsetX + halfheight * offsetY; //transform.transformPoint(particle->position, &position); position = particle->position; if (_rotateType == TEXTURE_COORDS) { float costheta = cosf(-particle->zRotation); float sintheta = sinf(-particle->zRotation); Vec2 texOffset = 0.5f * (particle->lb_uv + particle->rt_uv); Vec2 val; val.set((particle->lb_uv.x - texOffset.x), (particle->lb_uv.y - texOffset.y)); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); fillVertex(vertexindex, (position + (-halfwidth - halfheight + offset)), particle->color, val + texOffset); val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); fillVertex(vertexindex + 1, (position + (halfwidth - halfheight + offset)), particle->color, val + texOffset); val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); fillVertex(vertexindex + 2, (position + (-halfwidth + halfheight + offset)), particle->color, val + texOffset); val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); fillVertex(vertexindex + 3, (position + (halfwidth + halfheight + offset)), particle->color, val + texOffset); } else { Mat4::createRotation(backward, -particle->zRotation, &pRotMat); fillVertex(vertexindex , (position + pRotMat * (- halfwidth - halfheight + offset)), particle->color, particle->lb_uv); fillVertex(vertexindex + 1, (position + pRotMat * (halfwidth - halfheight + offset)), particle->color, Vec2(particle->rt_uv.x, particle->lb_uv.y)); fillVertex(vertexindex + 2, (position + pRotMat * (-halfwidth + halfheight + offset)), particle->color, Vec2(particle->lb_uv.x, particle->rt_uv.y)); fillVertex(vertexindex + 3, (position + pRotMat * (halfwidth + halfheight + offset)), particle->color, particle->rt_uv); } fillTriangle(index, vertexindex, vertexindex + 1, vertexindex + 3); fillTriangle(index + 3, vertexindex, vertexindex + 3, vertexindex + 2); //_posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex].color = particle->color; //_posuvcolors[vertexindex].uv.set(val.x + texOffset.x, val.y + texOffset.y); //val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y); //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); //_posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex + 1].color = particle->color; //_posuvcolors[vertexindex + 1].uv.set(val.x + texOffset.x, val.y + texOffset.y); // //val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); //_posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex + 2].color = particle->color; //_posuvcolors[vertexindex + 2].uv.set(val.x + texOffset.x, val.y + texOffset.y); // //val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); //_posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex + 3].color = particle->color; //_posuvcolors[vertexindex + 3].uv.set(val.x + texOffset.x, val.y + texOffset.y); // // //_indexData[index] = vertexindex; //_indexData[index + 1] = vertexindex + 1; //_indexData[index + 2] = vertexindex + 3; //_indexData[index + 3] = vertexindex; //_indexData[index + 4] = vertexindex + 3; //_indexData[index + 5] = vertexindex + 2; index += 6; vertexindex += 4; } _vertices.erase(_vertices.begin() + vertexindex, _vertices.end()); _indices.erase(_indices.begin() + index, _indices.end()); if (!_vertices.empty() && !_indices.empty()) { _vertexBuffer->updateVertices(&_vertices[0], vertexindex/* * sizeof(_posuvcolors[0])*/, 0); _indexBuffer->updateIndices(&_indices[0], index/* * sizeof(unsigned short)*/, 0); _stateBlock->setBlendFunc(particleSystem->getBlendFunc()); GLuint texId = (_texture ? _texture->getName() : 0); _meshCommand->init(0, texId, _glProgramState, _stateBlock, _vertexBuffer->getVBO(), _indexBuffer->getVBO(), GL_TRIANGLES, GL_UNSIGNED_SHORT, index, transform, Node::FLAGS_RENDER_AS_3D); _meshCommand->setSkipBatching(true); _meshCommand->setTransparent(true); _glProgramState->setUniformVec4("u_color", Vec4(1,1,1,1)); renderer->addCommand(_meshCommand); } }