/** * Perform drawing. All layers will be drawn starting from the one with the * lowest index. * * @param event Painting event. */ void PolarPlot2D::paintEvent(QPaintEvent * /*event*/) { initPainterCoordinates(); updateScreenData(); drawBackground(); drawGraphBackground(); drawGrids(); drawGraphs(); //drawAxes(); //drawItems(); drawBoundaries(); }
/*! Draw container content \param pDA Draw arguments */ void fp_FrameContainer::draw(dg_DrawArgs* pDA) { FV_View * pView = getView(); UT_return_if_fail( pView); xxx_UT_DEBUGMSG(("FrameContainer %x called, page %x \n",this,getPage())); if(getPage() == NULL) { getSectionLayout()->format(); getSectionLayout()->setNeedsReformat(getSectionLayout()); if(getPage() == NULL) { return; } } if(pView) { if(pView->getFrameEdit()->getFrameEditMode() == FV_FrameEdit_DRAG_EXISTING) { if((pView->getFrameEdit()->getFrameContainer() == this)) { return; } } } // // Only draw the lines in the clipping region. // /* [Somewhere down here is where the logic to only draw the region of the frame which is within the complement of the union of all higher frames needs to be. We need to draw the applicable region of the rectangle we're on, then unify it with (if applicable) the higher union.] <-- Possibly obsolete comment, not sure. I think I might have landed on an alternative solution involving more rearranging of the storage of the FrameContainers, based on their z-index. Not sure how far I got with that or if it worked either. See also abi bug 7664 and the original discussions about defining the undefinedness of layered frame behaviour. */ if(m_bOverWrote) { pDA->bDirtyRunsOnly = false; } dg_DrawArgs da = *pDA; GR_Graphics * pG = da.pG; UT_return_if_fail( pG); UT_sint32 x = pDA->xoff - m_iXpad; UT_sint32 y = pDA->yoff - m_iYpad; getPage()->expandDamageRect(x,y,getFullWidth(),getFullHeight()); if(!pDA->bDirtyRunsOnly || m_bNeverDrawn) { if(m_bNeverDrawn) { pDA->bDirtyRunsOnly= false; } UT_sint32 srcX,srcY; getSectionLayout()->checkGraphicTick(pG); srcX = -m_iXpad; srcY = -m_iYpad; // // Only fill to the bottom of the viewed page. // UT_sint32 iFullHeight = getFullHeight(); fl_DocSectionLayout * pDSL = getDocSectionLayout(); UT_sint32 iMaxHeight = 0; if(!pG->queryProperties(GR_Graphics::DGP_PAPER) && (pView->getViewMode() != VIEW_PRINT)) { iMaxHeight = pDSL->getActualColumnHeight(); } else { iMaxHeight = getPage()->getHeight(); } UT_sint32 iBot = getFullY()+iFullHeight; if(iBot > iMaxHeight) { iFullHeight = iFullHeight - (iBot-iMaxHeight); } getFillType()->Fill(pG,srcX,srcY,x,y,getFullWidth(),iFullHeight); m_bNeverDrawn = false; } UT_uint32 count = countCons(); UT_DEBUGMSG(("Number of containers in frame %d \n",count)); const UT_Rect * pPrevRect = pDA->pG->getClipRect(); UT_Rect * pRect = getScreenRect(); UT_Rect newRect; bool bRemoveRectAfter = false; bool bSetOrigClip = false; bool bSkip = false; if((pPrevRect == NULL) && pG->queryProperties(GR_Graphics::DGP_SCREEN)) { pDA->pG->setClipRect(pRect); UT_DEBUGMSG(("Clip bottom is %d \n",pRect->top + pRect->height)); bRemoveRectAfter = true; } else if(pPrevRect && !pRect->intersectsRect(pPrevRect)) { bSkip = true; xxx_UT_DEBUGMSG(("External Clip bottom is %d \n",pRect->top + pRect->height)); } else if(pPrevRect) { newRect.top = UT_MAX(pPrevRect->top,pRect->top); UT_sint32 iBotPrev = pPrevRect->height + pPrevRect->top; UT_sint32 iBot = pRect->height + pRect->top; newRect.height = UT_MIN(iBotPrev,iBot) - newRect.top; newRect.width = pPrevRect->width; newRect.left = pPrevRect->left; if((newRect.height > 0) && pDA->pG->queryProperties(GR_Graphics::DGP_SCREEN)) { pDA->pG->setClipRect(&newRect); bSetOrigClip = true; } else { bSkip = true; } } if(!bSkip) { for (UT_uint32 i = 0; i<count; i++) { fp_ContainerObject* pContainer = static_cast<fp_ContainerObject*>(getNthCon(i)); da.xoff = pDA->xoff + pContainer->getX(); da.yoff = pDA->yoff + pContainer->getY(); pContainer->draw(&da); } } m_bNeverDrawn = false; m_bOverWrote = false; if(bRemoveRectAfter) { pDA->pG->setClipRect(NULL); } if(bSetOrigClip) { pDA->pG->setClipRect(pPrevRect); } delete pRect; drawBoundaries(pDA); }
void Scene::render(){ for(int t = 0; t < timeStep; t++){ //for every timestep glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the color buffer glMatrixMode(GL_MODELVIEW); // indicate we are specifying camera transformations glLoadIdentity(); gluLookAt(0.0, 1.0, -0.25, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0 ); // if(t % 5 == 0) { // init(); // } //Draw the boundaries drawBoundaries(); vector<vector<Particle * > > neighbors; //density calculations #pragma omp for for(int i = 0; i < particles->size(); i++){ //for every particle Particle *particle = particles->at(i); double density = MASS; vector<Particle *> findNeighs; for(int j = 0; j < particles->size(); j++){ //comparison to all other particles to see if they're close enough to effect the density Particle *tempParticle = particles->at(j); double dist = particle->getDistance(*tempParticle); if (dist <= H && i != j){ //if the particle is close enough, add its mass * kernel to the density double kern = particle->getKernel(dist); density += tempParticle->getMass() * kern; findNeighs.push_back(tempParticle); } } neighbors.push_back(findNeighs); particle->setDensity(density); } //second iteration of particles and only their neighbors #pragma omp for for(int i = 0; i < particles->size(); i++){ Particle *particle = particles->at(i); Vector3f position = particle->getPosition(); Vector3f velocity = particle->getVelocity(); //http://stackoverflow.com/questions/17565664/gluproject-and-2d-display //Render particle GLdouble posX, posY, posZ;//3D point posX=convert(position.x(), WIDTH); posY=convert(position.y(), HEIGHT); posZ=convert(position.z(), LENGTH); glPushMatrix(); glTranslated(posX, posY, posZ); glutSolidSphere(SRADIUS, 10, 10); glPopMatrix(); //Force calculations Vector3f viscosityForce = Vector3f::Zero(); Vector3f pressureForce = Vector3f::Zero(); Vector3f surfaceNormal = Vector3f::Zero(); double colorField = 0; double pressureJ = particle->calcPressure(); vector<Particle * > curNeighs = neighbors[i]; for(int j = 0; j < curNeighs.size(); j++){//currNeighs.size(); j++){ Particle *tempParticle = curNeighs[j];// currNeighs[j]->p; double tempMass = tempParticle->getMass(); double tempDens = tempParticle->getDensity(); Vector3f tempVel = tempParticle->getVelocity(); double dist = particle->getDistance(*tempParticle); double kern = particle->getKernel(dist); colorField += tempMass / tempDens * kern; //Pressure and surfaceNormal Vector3f rij = tempParticle->getPosition() - position; Vector3f kernDerive = particle->getKernDerive(dist, rij); double pressureK = tempParticle->calcPressure(); pressureForce += tempMass * (pressureJ + pressureK) / (2 * tempDens) * kernDerive; surfaceNormal += tempMass / tempDens * kernDerive; //Viscosity double kernSecond = particle->getKernSecond(dist); viscosityForce += (tempVel - velocity) * tempMass / tempDens * kernSecond; } pressureForce *= -1; viscosityForce *= VISC; Vector3f surfaceTension = Vector3f::Zero(); Vector3f gravityForce(0, particle->getDensity() * GRAVITY, 0); // cout << "pForce: " << pressureForce << endl; // //cout << "dens: " << particle->getDensity() << endl; // cout << "glForce: " << gravityForce << endl; // cout << "vForce: " << viscosityForce << endl; //Update next position Vector3f totalForce = gravityForce + pressureForce + viscosityForce; //cout << "totalForce: " << totalForce << endl; Vector3f acceleration = totalForce/particle->getDensity(); //cout << "1. " << particle->getVelocity() << endl; velocity = velocity + DELTAT * acceleration; //maybe implement some kind of terminal velocity? //cout << "2. " << velocity << endl; Vector3f newPosition = position + DELTAT * velocity; //Boundary check next position bool bounce = false; while((newPosition.x() - RADIUS <= LEFT) || (newPosition.y() - RADIUS <= BOTTOM) || (newPosition.x() + RADIUS >= RIGHT) || (newPosition.y() + RADIUS >= TOP) || (newPosition.z() + RADIUS <= BACK) || (newPosition.z() - RADIUS >= FRONT)){ bounce = true; velocity *= 0.9; newPosition = position + DELTAT * velocity; } if(bounce) velocity *= -1; // if(newPosition.y() - RADIUS <= BOTTOM){ // int boundTime = (BOTTOM - position.y()) / velocity; // Vector3f collision = position + boundTime * velocity; // Vector3f collNorm(collision.x(), 1, collision.z()).normalized(); // double penDist = newPosition.dist(collision); // newPosition = newPosition + penDist * collNorm; // velocity = velocity - 0.3 * (velocity.dot(collNorm)) * collNorm; // } particle->setPosition(newPosition); particle->setVelocity(velocity); } saveImage(t); glFlush(); glutSwapBuffers(); glPopMatrix(); } }