static void drawBoundingBox(double bmin[3], double bmax[3]) { double center[3]; double width[3]; width[0] = (bmax[0] - bmin[0]) * 0.5; width[1] = (bmax[1] - bmin[1]) * 0.5; width[2] = (bmax[2] - bmin[2]) * 0.5; center[0] = bmin[0] + width[0]; center[1] = bmin[1] + width[1]; center[2] = bmin[2] + width[2]; glPushMatrix(); glTranslatef(center[0], center[1], center[2]); glScalef(width[0], width[1], width[2]); glEnable(GL_BLEND); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.3f, 0.6f, 0.3f, 0.2f); drawCube(2.0); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); glColor3f(1.0f, 1.0f, 0.0f); drawWireCube(2.0); glPopMatrix(); glEnable(GL_LIGHTING); }
void View::drawSkeleton(bool drawTransparent) const { if (doc->mesh.balls.isEmpty()) return; // draw model if (drawTransparent) { // set depth buffer before so we never blend the same pixel twice glClear(GL_DEPTH_BUFFER_BIT); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); doc->mesh.drawKeyBalls(); if (drawInterpolated) doc->mesh.drawInBetweenBalls(); else doc->mesh.drawBones(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // draw blended key balls and bones glDepthFunc(GL_EQUAL); glEnable(GL_BLEND); glEnable(GL_LIGHTING); doc->mesh.drawKeyBalls(0.25); glColor4f(0.75, 0.75, 0.75, 0.25); if (drawInterpolated) doc->mesh.drawInBetweenBalls(); else doc->mesh.drawBones(); glDisable(GL_LIGHTING); glDisable(GL_BLEND); glDepthFunc(GL_LESS); } else { // draw key balls and in-between balls glEnable(GL_LIGHTING); doc->mesh.drawKeyBalls(); glColor3f(0.75, 0.75, 0.75); if (drawInterpolated) doc->mesh.drawInBetweenBalls(); else doc->mesh.drawBones(); glDisable(GL_LIGHTING); } // draw box around selected ball if (selectedBall != -1) { const Ball &selection = doc->mesh.balls[selectedBall]; float radius = selection.maxRadius(); // enable line drawing glDepthMask(GL_FALSE); glEnable(GL_BLEND); if (mode == MODE_ADD_JOINTS || mode == MODE_ANIMATE_MESH) { glDisable(GL_DEPTH_TEST); glColor4f(0, 0, 0, 0.25); drawWireCube(selection.center - radius, selection.center + radius); glEnable(GL_DEPTH_TEST); glColor3f(0, 0, 0); drawWireCube(selection.center - radius, selection.center + radius); // find the currently selected cube face and display the cursor Raytracer tracer; Vector3 ray = tracer.getRayForPixel(mouseX, mouseY); HitTest result; if (Raytracer::hitTestCube(selection.center - radius, selection.center + radius, currentCamera->eye, ray, result)) { float size = (result.hit - currentCamera->eye).length() * CURSOR_SIZE / height(); Vector2 angles = result.normal.toAngles(); glColor3f(0, 0, 0); glDisable(GL_DEPTH_TEST); glPushMatrix(); glTranslatef(result.hit.x, result.hit.y, result.hit.z); glRotatef(90 - angles.x * 180 / M_PI, 0, 1, 0); glRotatef(-angles.y * 180 / M_PI, 1, 0, 0); glScalef(size, size, size); drawMoveCursor(); glPopMatrix(); glEnable(GL_DEPTH_TEST); } } else if (mode == MODE_SCALE_JOINTS) { // display the cursor Raytracer tracer; Vector3 ray = tracer.getRayForPixel(mouseX, mouseY); HitTest result; if (Raytracer::hitTestSphere(selection.center, radius, currentCamera->eye, ray, result)) { camera2D(); glColor3f(0, 0, 0); glDisable(GL_DEPTH_TEST); glTranslatef(mouseX, mouseY, 0); glScalef(CURSOR_SIZE, CURSOR_SIZE, 0); drawScaleCursor(); glEnable(GL_DEPTH_TEST); camera3D(); } Vector3 delta = currentCamera->eye - selection.center; Vector2 angles = delta.toAngles(); // adjust the radius to the profile of the ball as seen from the camera radius = radius / sinf(acosf(radius / delta.length())); // draw a circle around the selected ball radius *= 1.1; glPushMatrix(); glTranslatef(selection.center.x, selection.center.y, selection.center.z); glRotatef(90 - angles.x * 180 / M_PI, 0, 1, 0); glRotatef(-angles.y * 180 / M_PI, 1, 0, 0); glScalef(radius, radius, radius); glDisable(GL_DEPTH_TEST); glColor4f(0, 0, 0, 0.25); drawWireDisk(); glEnable(GL_DEPTH_TEST); glColor3f(0, 0, 0); drawWireDisk(); glPopMatrix(); } // disable line drawing glDisable(GL_BLEND); glDepthMask(GL_TRUE); } }
void Tracker::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); PSMoveTrackerRGBImage image = psmove_tracker_get_image(m_tracker); glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width, image.height, 0, GL_RGB, GL_UNSIGNED_BYTE, image.data); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Draw the camera image, filling the screen */ glColor3f(1., 1., 1.); glBegin(GL_QUADS); glTexCoord2f(0., 1.); glVertex2f(-1., -1.); glTexCoord2f(1., 1.); glVertex2f(1., -1.); glTexCoord2f(1., 0.); glVertex2f(1., 1.); glTexCoord2f(0., 0.); glVertex2f(-1., 1.); glEnd(); glDisable(GL_TEXTURE_2D); /* Clear the depth buffer to allow overdraw */ glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadMatrixf(psmove_fusion_get_projection_matrix(m_fusion)); /* Render the trace */ if (m_trace.size()) { Point3D center = m_trace[0]; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(center.x + m_offset.x, center.y + m_offset.y, center.z + m_offset.z); glRotatef(m_rotation, 0., 1., 0.); std::vector<Point3D>::iterator it; glColor3f(1., 0., 0.); glEnable(GL_LIGHTING); //glBegin(GL_TRIANGLE_STRIP); for (it=m_trace.begin(); it != m_trace.end(); ++it) { Point3D point = *it; Point3D moved(point.x - center.x, point.y - center.y, point.z - center.z); //glVertex3f(moved.x, moved.y, moved.z); glPushMatrix(); glTranslatef(moved.x, moved.y, moved.z); drawSolidCube(.5f); glPopMatrix(); } //glEnd(); glDisable(GL_LIGHTING); } for (int i=0; i<m_count; i++) { glMatrixMode(GL_MODELVIEW); glLoadMatrixf(psmove_fusion_get_modelview_matrix(m_fusion, m_moves[i])); if (m_items[i] == WIRE_CUBE) { glColor3f(1., 0., 0.); drawWireCube(1.); glColor3f(0., 1., 0.); glPushMatrix(); glScalef(1., 1., 4.5); glTranslatef(0., 0., -.5); drawWireCube(1.); glPopMatrix(); glColor3f(0., 0., 1.); drawWireCube(3.); } else if (m_items[i] == SOLID_CUBE) { glEnable(GL_LIGHTING); drawSolidCube(2.); glDisable(GL_LIGHTING); } } }
void GR_Fluid::renderWire(GU_Detail *gdp, RE_Render &ren, const GR_AttribOffset & /*ptinfo*/, const GR_DisplayOption *dopt, float /*lod*/, const GU_PrimGroupClosure * /*hidden_geometry*/) { GEO_AttributeHandle fluidAh= gdp->getDetailAttribute("cudaFluidPreview"); fluidAh.setElement(gdp); GEO_AttributeHandle fluid3DAh= gdp->getDetailAttribute("cudaFluid3DPreview"); fluid3DAh.setElement(gdp); GEO_AttributeHandle fluid3DSliceAh= gdp->getDetailAttribute("sliceDisplay"); fluid3DSliceAh.setElement(gdp); GEO_AttributeHandle fluidAh= gdp->getDetailAttribute("cudaFluidPreview"); fluidAh.setElement(gdp); GEO_AttributeHandle fluidIdAh= gdp->getDetailAttribute("solverId"); fluidIdAh.setElement(gdp); if (fluidAh.getI()== 1) { VHFluidSolver* currSolver = VHFluidSolver::solverList[fluidIdAh.getI()]; UT_Vector4 fluidPos(0,0,0); UT_Vector3D fluidRot(0,0,0); if(gdp->volumeCount() == 1) { GEO_Primitive* pprim = gdp->primitives().head(); GU_PrimVolume* volume = (GU_PrimVolume *)pprim; UT_Matrix4 fluidRotMat; volume->getTransform4(fluidRotMat); UT_XformOrder rotOrder; UT_Vector3D scale, trans; fluidRotMat.explode(rotOrder, fluidRot, scale, trans); fluidRot.radToDeg(); fluidPos = volume->getVertex().getPt()->getPos(); } float sizeX = currSolver->fluidSize.x*0.5; float sizeY = currSolver->fluidSize.y*0.5; int newResX = currSolver->res.x; int newResY = currSolver->res.y; if(displayX != newResX || displayY != newResY) { displayX = newResX; displayY = newResY; initPixelBuffer(true); } cu::cutilSafeCall(cu::cudaGraphicsMapResources(1, &cuda_pbo_resource, 0)); cu::float4 *d_output; size_t num_bytes; cu::cutilSafeCall(cu::cudaGraphicsResourceGetMappedPointer((void **)&d_output, &num_bytes, cuda_pbo_resource)); cu::cudaMemset(d_output, 0, displayX*displayY*sizeof(cu::float4)); currSolver->renderFluid(d_output); cu::cutilSafeCall(cu::cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0)); //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo); glBindTexture(GL_TEXTURE_2D, gl_Tex); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, displayX, displayY, GL_RGBA, GL_FLOAT, 0); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(fluidPos.x(),fluidPos.y(),fluidPos.z()); glRotatef(fluidRot.z(),0,0,1); glRotatef(fluidRot.y(),0,1,0); glRotatef(fluidRot.x(),1,0,0); //glColor3f(1.0,1.0,1.0); //glDisable(GL_BLEND); //glDisable(GL_LIGHTING); //glBegin( GL_QUADS ); //glTexCoord2f(0.0f, 0.0f); glVertex3f(-sizeX,-sizeY,0.0f); //glTexCoord2f(0.0f, 1.0f); glVertex3f(-sizeX,sizeY,0.0f); //glTexCoord2f(1.0f, 1.0f); glVertex3f(sizeX,sizeY,0.0f); //glTexCoord2f(1.0f, 0.0f); glVertex3f(sizeX,-sizeY,0.0f); //glEnd(); ren.setColor(1,1,1,1); ren.blend(0); ren.toggleLighting(0); const float t0[] = {0,0}; const float t1[] = {0,1}; const float t2[] = {1,1}; const float t3[] = {1,0}; ren.beginQuads(); ren.t2DW(t0); ren.vertex3DW(-sizeX,-sizeY,0.0f); ren.t2DW(t1); ren.vertex3DW(-sizeX,sizeY,0.0f); ren.t2DW(t2); ren.vertex3DW(sizeX,sizeY,0.0f); ren.t2DW(t3); ren.vertex3DW(sizeX,-sizeY,0.0f); ren.endQuads(); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); ren.beginClosedLine(); ren.vertex3DW(-sizeX,-sizeY,0.0f); ren.vertex3DW(-sizeX,sizeY,0.0f); ren.vertex3DW(sizeX,sizeY,0.0f); ren.vertex3DW(sizeX,-sizeY,0.0f); ren.endClosedLine(); ren.toggleLighting(1); glPopMatrix(); } if (fluid3DAh.getI() == 1 || fluid3DSliceAh.getI()== 1) { ren.toggleLighting(0); VHFluidSolver3D* curr3DSolver = VHFluidSolver3D::solverList[fluidIdAh.getI()]; UT_Vector4 fluidPos(0,0,0); UT_Vector3D fluidRot(0,0,0); if(gdp->volumeCount() == 1) { GEO_Primitive* pprim = gdp->primitives().head(); GU_PrimVolume* volume = (GU_PrimVolume *)pprim; UT_Matrix4 fluidRotMat; volume->getTransform4(fluidRotMat); UT_XformOrder rotOrder; UT_Vector3D scale, trans; fluidRotMat.explode(rotOrder, fluidRot, scale, trans); fluidRot.radToDeg(); fluidPos = volume->getVertex().getPt()->getPos(); } float sizeX = curr3DSolver->fluidSize.x*0.5; float sizeY = curr3DSolver->fluidSize.y*0.5; float sizeZ = curr3DSolver->fluidSize.z*0.5; if(curr3DSolver->drawCube) { glPushMatrix(); glTranslatef(fluidPos.x(),fluidPos.y(),fluidPos.z()); glRotatef(fluidRot.z(),0,0,1); glRotatef(fluidRot.y(),0,1,0); glRotatef(fluidRot.x(),1,0,0); drawWireCube(sizeX,sizeY,sizeZ, ren); glPopMatrix(); } if (fluid3DAh.getI()== 1) { curr3DSolver->drawFluid(); } if (fluid3DSliceAh.getI()== 1) { curr3DSolver->drawFluidSlice(); } ren.toggleLighting(1); } }
/** Draw a tree. \param node Node \param draw_blends If true, only objects that use blending are drawn. Otherwise objects with blending are not drawn. \return True if the tree contained one or more objects that use blending */ bool GLRenderInstance::drawNode(WorldObject& node, bool draw_blends) { double M[16]; BoundingBox bb; vec3d bmin, bmax, t, d; bool render_flag = true; bool res = false; WorldObject::ChildIterator it; for(it=node.childsBegin(); it!=node.childsEnd(); it++) { glPushMatrix(); // Set the local transformation it->second->localTransform().toList(M); glMultMatrixd(M); // Draw the geom (if visible) boost::shared_ptr<GeomObject> geom = it->second->getGeom(); if (geom.get()!=0 && (it->second->visible.getValue())) { // Render by default if draw_blends is false render_flag = !draw_blends; // Set material boost::shared_ptr<Material> mat = it->second->getMaterial(); Material* bmat = dynamic_cast<Material*>(mat.get()); // Check if the object should be postponed because blending is used... if (bmat!=0) { if (bmat->usesBlending()) { res = true; render_flag = draw_blends; } } if (render_flag) { // Set material glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT); if (bmat!=0) { bmat->applyGL(); } if (draw_solid) { clearGLError(); geom->drawGL(); } // Draw bounding box if (draw_bboxes) { bb = geom->boundingBox(); if (!bb.isEmpty()) { glDisable(GL_LIGHTING); bb.getBounds(bmin, bmax); t = 0.5*(bmax+bmin); d = bmax-bmin; glPushMatrix(); glTranslated(t.x, t.y, t.z); drawWireCube(d.x, d.y, d.z); glPopMatrix(); glEnable(GL_LIGHTING); } } glPopAttrib(); // restore material } } // Draw the children res |= drawNode(*(it->second), draw_blends); glPopMatrix(); } return res; }
void GR_CudaHardware::renderWire(GU_Detail *gdp, RE_Render &ren, const GR_AttribOffset & /*ptinfo*/, const GR_DisplayOption *dopt, float /*lod*/, const GU_PrimGroupClosure * /*hidden_geometry*/) { GEO_AttributeHandle fluidAh= gdp->getDetailAttribute("cudaFluidPreview"); fluidAh.setElement(gdp); if (fluidAh.getI()== 1) { GEO_AttributeHandle fluidIdAh= gdp->getDetailAttribute("solverId"); fluidIdAh.setElement(gdp); VHFluidSolver* currSolver = VHFluidSolver::solverList[fluidIdAh.getI()]; UT_Vector4 fluidPos(0,0,0); UT_Vector3D fluidRot(0,0,0); if(gdp->volumeCount() == 1) { GEO_Primitive* pprim = gdp->primitives().head(); GU_PrimVolume* volume = (GU_PrimVolume *)pprim; UT_Matrix4 fluidRotMat; volume->getTransform4(fluidRotMat); UT_XformOrder rotOrder; UT_Vector3D scale, trans; fluidRotMat.explode(rotOrder, fluidRot, scale, trans); fluidRot.radToDeg(); fluidPos = volume->getVertex().getPt()->getPos(); } currSolver->drawFluid(fluidRot.x(), fluidRot.y(), fluidRot.z(), fluidPos.x(), fluidPos.y(), fluidPos.z()); } GEO_AttributeHandle partsAh= gdp->getDetailAttribute("cudaParticlesPreview"); partsAh.setElement(gdp); if (partsAh.getI()== 1) { GEO_AttributeHandle partsIdAh= gdp->getDetailAttribute("systemId"); partsIdAh.setElement(gdp); ren.toggleLighting(0); VHParticlesSystem* currSystem = VHParticlesSystem::systemsList[partsIdAh.getI()]; glClear(GL_COLOR_BUFFER_BIT); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE ); currSystem->draw(); glDisable( GL_BLEND ); ren.toggleLighting(1); } GEO_AttributeHandle fluid3DAh= gdp->getDetailAttribute("cudaFluid3DPreview"); fluid3DAh.setElement(gdp); GEO_AttributeHandle fluid3DSliceAh= gdp->getDetailAttribute("sliceDisplay"); fluid3DSliceAh.setElement(gdp); if (fluid3DAh.getI() == 1 || fluid3DSliceAh.getI()== 1) { GEO_AttributeHandle fluidIdAh= gdp->getDetailAttribute("solverId"); fluidIdAh.setElement(gdp); ren.toggleLighting(0); VHFluidSolver3D* curr3DSolver = VHFluidSolver3D::solverList[fluidIdAh.getI()]; UT_Vector4 fluidPos(0,0,0); UT_Vector3D fluidRot(0,0,0); if(gdp->volumeCount() > 0) { GEO_Primitive* pprim = gdp->primitives().head(); GU_PrimVolume* volume = (GU_PrimVolume *)pprim; UT_Matrix4 fluidRotMat; volume->getTransform4(fluidRotMat); UT_XformOrder rotOrder; UT_Vector3D scale, trans; fluidRotMat.explode(rotOrder, fluidRot, scale, trans); fluidRot.radToDeg(); fluidPos = volume->getVertex().getPt()->getPos(); } float sizeX = curr3DSolver->fluidSize.x*0.5; float sizeY = curr3DSolver->fluidSize.y*0.5; float sizeZ = curr3DSolver->fluidSize.z*0.5; if(curr3DSolver->drawCube) { glPushMatrix(); glTranslatef(fluidPos.x(),fluidPos.y(),fluidPos.z()); glRotatef(fluidRot.z(),0,0,1); glRotatef(fluidRot.y(),0,1,0); glRotatef(fluidRot.x(),1,0,0); drawWireCube(sizeX,sizeY,sizeZ, ren); glPopMatrix(); } if (fluid3DAh.getI()== 1) { curr3DSolver->drawFluid(fluidRot.x(), fluidRot.y(), fluidRot.z(), fluidPos.x(), fluidPos.y(), fluidPos.z()); } if (fluid3DSliceAh.getI()== 1) { curr3DSolver->drawFluidSlice(fluidRot.x(), fluidRot.y(), fluidRot.z(), fluidPos.x(), fluidPos.y(), fluidPos.z()); } ren.toggleLighting(1); } }