CLGraphicalObject::CLGraphicalObject(const GraphicalObject & sbml, std::map<std::string, std::string> & layoutmap, const CCopasiContainer * pParent) : CLBase(sbml), CCopasiContainer(sbml.getId(), pParent, "LayoutElement"), mKey(CCopasiRootContainer::getKeyFactory()->add("Layout", this)), mModelObjectKey(""), mBBox(*sbml.getBoundingBox()) { RenderGraphicalObjectPlugin* rgoPlugin = (RenderGraphicalObjectPlugin*) sbml.getPlugin("render"); if (rgoPlugin != NULL) mObjectRole = rgoPlugin->getObjectRole(); //add the copasi key to the map layoutmap[sbml.getId()] = mKey; };
END_TEST START_TEST ( test_RenderExtension_writeL3Render ) { RenderPkgNamespaces renderns; LayoutPkgNamespaces layoutns; SBMLDocument doc(3,1); doc.enablePackage(layoutns.getURI(), "layout", true); doc.enablePackage(renderns.getURI(), "render", true); Model* model = doc.createModel(); LayoutModelPlugin *lPlugin = (LayoutModelPlugin*)model->getPlugin("layout"); fail_unless(lPlugin != NULL); Layout* layout = lPlugin->createLayout(); Dimensions dim(&layoutns, 100,100 ); layout->setDimensions(&dim); GraphicalObject* additional = layout->createAdditionalGraphicalObject(); additional->setId("go1"); BoundingBox bb(&layoutns, "bb1", 10, 10, 90, 90); additional->setBoundingBox(&bb); RenderLayoutPlugin *rPlugin = (RenderLayoutPlugin*)layout->getPlugin("render"); fail_unless(rPlugin != NULL); LocalRenderInformation* local = rPlugin->createLocalRenderInformation(); ColorDefinition *black = local->createColorDefinition(); black->setId("black"); black->setColorValue("#000000"); LocalStyle *lStyle = local->createStyle("style_go1"); lStyle->addId("go1"); RenderGroup* group = lStyle->getGroup(); group->setStroke("black"); std::string sbml = writeSBMLToStdString(&doc); fail_unless (sbml.length() != 0); }
void SimObjectRenderer::draw() { // update a moving camera if(moving) { unsigned int now = System::getTime(); int x = 0; int y = 0; if(movingLeftStartTime) { x -= now - movingLeftStartTime; movingLeftStartTime = now; } if(movingRightStartTime) { x += now - movingRightStartTime; movingRightStartTime = now; } if(movingUpStartTime) { y -= now - movingUpStartTime; movingUpStartTime = now; } if(movingDownStartTime) { y += now - movingDownStartTime; movingDownStartTime = now; } moveCamera(float(x) * 0.001f, float(y) * 0.002f); } // set flags if(renderFlags & enableLights) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); if(renderFlags & enableMultisample) glEnable(GL_MULTISAMPLE); else glDisable(GL_MULTISAMPLE); if(renderFlags & enableTextures) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); // clear glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // load camera position glLoadMatrixf(cameraTransformation); // make sure transformations of movable bodies are up-to-date // note: a not-physical-object has a constant offset pose relative its parent. hence there is no transformation update required to draw not-physical-objects PhysicalObject* physicalObject = dynamic_cast<PhysicalObject*>(&simObject); GraphicalObject* graphicalObject = dynamic_cast<GraphicalObject*>(&simObject); if(physicalObject) Simulation::simulation->scene->updateTransformations(); // since each object will be drawn relative to its parent we need to shift the coordinate system when we want the object to be in the center if(&simObject != Simulation::simulation->scene && !(renderFlags & showAsGlobalView)) { const float* transformation = simObject.transformation; Pose3<> pose(Matrix3x3<>(Vector3<>(transformation[0], transformation[1], transformation[2]), Vector3<>(transformation[4], transformation[5], transformation[6]), Vector3<>(transformation[8], transformation[9], transformation[10])), Vector3<>(transformation[12], transformation[13], transformation[14])); float invTrans[16]; OpenGLTools::convertTransformation(pose.invert(), invTrans); glMultMatrixf(invTrans); } // draw origin if(renderFlags & showCoordinateSystem) { Simulation::simulation->scene->defaultSurface->set(); glBegin(GL_LINES); glNormal3f (0,0,1); glColor3f(1, 0, 0); glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glColor3f(0, 1, 0); glVertex3f(0, 0, 0); glVertex3f(0, 1, 0); glColor3f(0, 0, 1); glVertex3f(0, 0, 0); glVertex3f(0, 0, 1); glEnd(); Simulation::simulation->scene->defaultSurface->unset(); } // draw object / scene appearance if(graphicalObject && surfaceShadeMode != noShading) { switch(surfaceShadeMode) { case flatShading: glPolygonMode(GL_FRONT, GL_FILL); glShadeModel(GL_FLAT); break; case wireframeShading: glPolygonMode(GL_FRONT, GL_LINE); glShadeModel(GL_FLAT); break; case smoothShading: glPolygonMode(GL_FRONT, GL_FILL); glShadeModel(GL_SMOOTH); break; default: ASSERT(false); break; } graphicalObject->drawAppearances(); // check matrix stack size #ifdef _DEBUG int stackDepth; glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &stackDepth); ASSERT(stackDepth == 1); #endif } // draw object / scene physics if(physicalObject && (physicsShadeMode != noShading || renderFlags & showSensors)) { Simulation::simulation->scene->defaultSurface->set(); unsigned int renderFlags = (this->renderFlags | showPhysics) & ~showControllerDrawings; switch(physicsShadeMode) { case noShading: glPolygonMode(GL_FRONT, GL_LINE); glShadeModel(GL_FLAT); renderFlags &= ~showPhysics; break; case flatShading: glPolygonMode(GL_FRONT, GL_FILL); glShadeModel(GL_FLAT); break; case wireframeShading: glPolygonMode(GL_FRONT, GL_LINE); glShadeModel(GL_FLAT); break; case smoothShading: glPolygonMode(GL_FRONT, GL_FILL); glShadeModel(GL_SMOOTH); break; default: ASSERT(false); break; } physicalObject->drawPhysics(renderFlags); Simulation::simulation->scene->defaultSurface->unset(); // check matrix stack size #ifdef _DEBUG int stackDepth; glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &stackDepth); ASSERT(stackDepth == 1); #endif } // draw drag plane if(dragging && dragSelection) { Simulation::simulation->scene->defaultSurface->set(); glPolygonMode(GL_FRONT, GL_FILL); glShadeModel(GL_FLAT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA); glPushMatrix(); if(dragType == dragRotate || dragType == dragNormalObject) glMultMatrixf(dragSelection->transformation); else glTranslatef(dragSelection->pose.translation.x, dragSelection->pose.translation.y, dragSelection->pose.translation.z); switch(dragPlane) { case xyPlane: break; // do nothing case xzPlane: glRotatef(90.f, 1.f, 0.f, 0.f); break; case yzPlane: glRotatef(90.f, 0.f, 1.f, 0.f); break; } GLUquadricObj* q = gluNewQuadric(); glColor4f(0.5f, 0.5f, 0.5f, 0.5f); glNormal3f(0,0,1); gluDisk(q, 0.003f, 0.5f, 30, 1); glRotatef(180.f, 1.f, 0.f, 0.f); gluDisk(q, 0.003f, 0.5f, 30, 1); gluDeleteQuadric(q); glPopMatrix(); glDisable(GL_BLEND); Simulation::simulation->scene->defaultSurface->unset(); } // draw controller drawings if(physicalObject && drawingsShadeMode != noShading) { Simulation::simulation->scene->defaultSurface->set(); switch(drawingsShadeMode) { case flatShading: glPolygonMode(GL_FRONT, GL_FILL); glShadeModel(GL_FLAT); break; case wireframeShading: glPolygonMode(GL_FRONT, GL_LINE); glShadeModel(GL_FLAT); break; case smoothShading: glPolygonMode(GL_FRONT, GL_FILL); glShadeModel(GL_SMOOTH); break; default: ASSERT(false); break; } if(renderFlags & (enableDrawingsTransparentOcclusion | enableDrawingsOcclusion)) { physicalObject->drawPhysics(showControllerDrawings); if(renderFlags & enableDrawingsTransparentOcclusion) { glAccum(GL_LOAD, 0.5f); glClear(GL_DEPTH_BUFFER_BIT); physicalObject->drawPhysics(showControllerDrawings); glAccum(GL_ACCUM, 0.5f); glAccum(GL_RETURN, 1.f); } } else { glClear(GL_DEPTH_BUFFER_BIT); physicalObject->drawPhysics(showControllerDrawings); } Simulation::simulation->scene->defaultSurface->unset(); // check matrix stack size #ifdef _DEBUG int stackDepth; glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &stackDepth); ASSERT(stackDepth == 1); #endif } }
//TODO: make bool and crash bool RenderEngine::Draw(glm::mat4 perspective, glm::mat4 camera) { GraphicalObject * currentGob = nullptr;// BufferManager::GetFirstGob(); int objectNum = 0; RenderInfo * gobRenderInfo = nullptr; //SetAttributes(); BufferGroup * bGroup = nullptr; //while(BufferManager::) while (BufferManager::GetBufferGroup(bGroup)) { if (bGroup == nullptr) { printf("RenderEngine::Draw(): bGroup is null\n"); return false; } int shaderInd = bGroup->GetShaderIndex(); //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- if (!ShaderManager::UseShader(shaderInd)) { printf("RenderEngine::Draw(): UseShader, shader [%d] does not exist\n", bGroup->GetShaderIndex()); return false; } //if (shaderInd == 2) //{ // TextureManager::BindImage(0); //} //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- GraphicalObject * bufferGroupGob = bGroup->GetFirstGob(); if (bufferGroupGob != nullptr) {//{ printf("RenderEngine::Draw(): bufferGroupGob is null\n"); return false; } RenderInfo * renderInfo = bufferGroupGob->GetRenderInfoPtr(); //Refactor //SetAttributes(bGroup); while (bGroup->GetBufferInfoGob(currentGob)) { renderInfo = currentGob->GetRenderInfoPtr(); glBindBuffer(GL_ARRAY_BUFFER, renderInfo->m_vertBufferID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, renderInfo->m_indBufferID); SetAttributes(&(renderInfo->m_vertexFormat), renderInfo->m_stride); //char * texInfo = TextureManager::GetData(0); while (currentGob != nullptr) { gobRenderInfo = currentGob->GetRenderInfoPtr(); if (currentGob->GetRenderInfoPtr()->m_enabled) { glm::mat4 screenMat = perspective * (camera * /*Set this to a parameter ->*/(currentGob->GetTranslateMatrix() * (currentGob->GetRotationMatrix() * currentGob->GetScaleMatrix()))); if (currentGob->m_drawCallback) { if (!currentGob->m_drawCallback(currentGob, screenMat)) return false; } else { if (shaderInd == 0) { SetUniformsShader0(currentGob, screenMat); } else if (shaderInd == 1) { if (!SetUniformsShader1(currentGob, screenMat)) return false; } else if (shaderInd == 2 || shaderInd == 3) { if (!SetUniformsShader2(currentGob, screenMat))return false; } else if (shaderInd == 4) { //glm::mat4 lightMat = perspective * (camera); if (!SetUniformsShader4(currentGob, screenMat)) return false; } else if (shaderInd == 5) { //glm::mat4 lightMat = perspective * (camera); if (!SetUniformsShader5(currentGob, screenMat)) return false; } } if (currentGob->GetRenderInfoPtr()->m_indexed) { DrawIndexedObject(currentGob); } else { DrawNonIndexedObject(currentGob); } } if (currentGob->m_drawCallback) { glDisable(GL_BLEND); } currentGob = currentGob->GetNextObjectPtr(); objectNum++; } } } } return true; }
LIBSBML_EXTERN void addGraphicalObjectAttributes(const GraphicalObject& object,XMLAttributes& att) { att.add("id",object.getId()); }
/** * Copy constructor. */ GraphicalObject::GraphicalObject(const GraphicalObject& source):SBase(source) { this->mId = source.mId; this->mBoundingBox=*source.getBoundingBox(); }
END_TEST START_TEST ( test_RenderExtension_gradient ) { RenderPkgNamespaces renderns; LayoutPkgNamespaces layoutns; SBMLDocument doc(3,1); doc.enablePackage(layoutns.getURI(), "layout", true); doc.enablePackage(renderns.getURI(), "render", true); Model* model = doc.createModel(); LayoutModelPlugin *lPlugin = (LayoutModelPlugin*)model->getPlugin("layout"); fail_unless(lPlugin != NULL); Layout* layout = lPlugin->createLayout(); Dimensions dim(&layoutns, 100,100 ); layout->setDimensions(&dim); GraphicalObject* additional = layout->createAdditionalGraphicalObject(); additional->setId("go1"); BoundingBox bb(&layoutns, "bb1", 10, 10, 90, 90); additional->setBoundingBox(&bb); RenderGraphicalObjectPlugin* goPlugin = (RenderGraphicalObjectPlugin*)additional->getPlugin("render"); fail_unless(goPlugin != NULL); goPlugin->setObjectRole("myRole"); RenderLayoutPlugin *rPlugin = (RenderLayoutPlugin*)layout->getPlugin("render"); fail_unless(rPlugin != NULL); LocalRenderInformation* local = rPlugin->createLocalRenderInformation(); ColorDefinition *black = local->createColorDefinition(); black->setId("black"); black->setColorValue("#000000"); ColorDefinition *grey = local->createColorDefinition(); grey->setId("grey"); grey->setColorValue("#F0F0F0"); LinearGradient* gradient = local->createLinearGradientDefinition(); gradient->setId("test"); gradient->setPoint1(RelAbsVector(), RelAbsVector()); gradient->setPoint2(RelAbsVector(0,100), RelAbsVector(0,100)); GradientStop *stop = gradient->createGradientStop(); stop->setOffset(RelAbsVector()); stop->setStopColor("white"); stop = gradient->createGradientStop(); stop->setOffset(RelAbsVector(0, 100)); stop->setStopColor("silver"); std::string smodel = writeSBMLToStdString(&doc); fail_unless( stop->getStopColor() == "silver" ); }