void Renderer::ImportObjFileCallback(string param) { Object3D* obj = new Object3D(param); obj->glTranslate(ofGetWindowWidth()*0.5, ofGetWindowHeight()*0.5, 0); this->sceneStructure->AddElement(obj); }
/** * Method is used to group object components. * @param object is source object. * @param vertices is other object vertices. * @pram indices is other object indices. * @param faceStatus1 is face status. * @param faceStatus2 is face status. */ void GeoModifier::groupObjectComponents(Object3D& object, VertexSet& vertices, IntSet& indices, int faceStatus1, int faceStatus2) { //for each face.. for(int i = 0; i < object.getNumFaces(); ++i) { Face& face = *(object.getFace(i)); if(face.getStatus()==faceStatus1 || face.getStatus()==faceStatus2) { VertexPointerSet faceVerts; faceVerts.add(face.v1); faceVerts.add(face.v2); faceVerts.add(face.v3); for(int j=0;j<faceVerts.length();j++) { if(vertices.contains(faceVerts[j])) indices.push_back(vertices.indexOf(faceVerts[j])); else { indices.push_back(vertices.length()); vertices.AddVertex(*faceVerts[j]); } } } } }
void addSineCosine() { mat4 Model = translate(mat4(1.0f), vec3(0.0f, -10.0f, 0.0f)); vec2 x[] = { vec2(-20.0f, -20.0f), vec2(-20.0f, 20.0f), vec2(20.0f, 20.0f), vec2(-20.0f, -20.0f), vec2(20.0f, 20.0f), vec2(20.0f, -20.0f) }; Mesh *mesh = new Mesh(); FunctionGraph graph(new SineCosine()); graph.generateGraph(x, 7, -1000.0f, mesh); graph.generateGraph(x+3, 7, -1000.0f, mesh); mesh->setOrientation(GL_CCW); mesh->applyIndexing(); mesh->makeUpUVData(); const Material mat(vec4(1.0f, 0.2f, 0.2f, 1.0f), vec4(0.1f, 0.1f, 0.1f, 1.0f), vec4(0.7f, 0.7f, 0.7f, 1.0f), 128.0f); Object3D *obj = new Object3D(mesh, mat); obj->setModelMatrix(Model); junk.push_back(obj); Engine::addToDisplayList(junk.back()); //Engine::addToDisplayList(new NormalDrawer(*mesh, Model)); }
void GraphicsCore::UpdateObjectValues(Object3D object) { vec3 up(0.0f, 1.0f, 0.0f); mat4 Projection = glm::perspective(fov, float(windowWidth) / (float)windowHeight, 0.1f, 200.f); mat4 Model = glm::translate(object.GetWorldPos()); mat4 viewMatrix = mCam.GetRotationMatrix() * glm::lookAt(mEye, mTarget, up); mat4 ModelView = viewMatrix * Model; mat4 MVP = Projection * ModelView; mat3 normalMatrix = glm::transpose(glm::inverse(mat3(ModelView))); uint shaderProgHandle = object.GetShaderID(); uint location = glGetUniformLocation(shaderProgHandle, "NormalMatrix"); //gets the UniformLocation from shader.vertex if( location >= 0 ){ glUniformMatrix3fv(location, 1, GL_FALSE, &normalMatrix[0][0]); } location = glGetUniformLocation(shaderProgHandle, "ProjectionMatrix"); //gets the UniformLocation from shader.vertex if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &Projection[0][0]); } location = glGetUniformLocation(shaderProgHandle, "ViewMatrix"); //gets the UniformLocation from shader.vertex if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &viewMatrix[0][0]); } location = glGetUniformLocation(shaderProgHandle, "ModelViewMatrix"); //gets the UniformLocation from shader.vertex if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &ModelView[0][0]); } location = glGetUniformLocation(shaderProgHandle, "MVP"); //gets the UniformLocation from shader.vertex if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &MVP[0][0]); } }
void BulletExample::keyPressEvent(KeyEvent& event) { /* Movement */ if(event.key() == KeyEvent::Key::Down) { _cameraObject->rotateX(5.0_degf); } else if(event.key() == KeyEvent::Key::Up) { _cameraObject->rotateX(-5.0_degf); } else if(event.key() == KeyEvent::Key::Left) { _cameraRig->rotateY(-5.0_degf); } else if(event.key() == KeyEvent::Key::Right) { _cameraRig->rotateY(5.0_degf); /* Toggling draw modes */ } else if(event.key() == KeyEvent::Key::D) { if(_drawCubes && _drawDebug) { _drawDebug = false; } else if(_drawCubes && !_drawDebug) { _drawCubes = false; _drawDebug = true; } else if(!_drawCubes && _drawDebug) { _drawCubes = true; _drawDebug = true; } /* What to shoot */ } else if(event.key() == KeyEvent::Key::S) { _shootBox ^= true; } else return; event.setAccepted(); }
void BulletExample::mousePressEvent(MouseEvent& event) { /* Shoot an object on click */ if(event.button() == MouseEvent::Button::Left) { const Vector2 clickPoint = Vector2::yScale(-1.0f)*(Vector2{event.position()}/Vector2{GL::defaultFramebuffer.viewport().size()} - Vector2{0.5f})* _camera->projectionSize(); const Vector3 direction = (_cameraObject->absoluteTransformation().rotationScaling()*Vector3{clickPoint, -1.0f}).normalized(); auto* object = new RigidBody{ &_scene, _shootBox ? 1.0f : 5.0f, _shootBox ? static_cast<btCollisionShape*>(&_bBoxShape) : &_bSphereShape, _bWorld}; object->translate(_cameraObject->absoluteTransformation().translation()); /* Has to be done explicitly after the translate() above, as Magnum -> Bullet updates are implicitly done only for kinematic bodies */ object->syncPose(); /* Create either a box or a sphere */ new ColoredDrawable{*object, _shader, _shootBox ? _box : _sphere, _shootBox ? 0x880000_rgbf : 0x220000_rgbf, Matrix4::scaling(Vector3{_shootBox ? 0.5f : 0.25f}), _drawables}; /* Give it an initial velocity */ object->rigidBody().setLinearVelocity(btVector3{direction*25.f}); event.setAccepted(); } }
void DualQuaternionTransformationTest::resetTransformation() { Object3D o; o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); o.resetTransformation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); }
void SceneTest::transformation() { Scene3D scene; Object3D* scenePointer = &scene; scenePointer->setTransformation(Matrix4::translation({1.0f, 1.0f, 1.0f})); CORRADE_COMPARE(scene.transformation(), Matrix4()); }
void RigidMatrixTransformation3DTest::resetTransformation() { Object3D o; o.setTransformation(Matrix4::rotationX(Deg(17.0f))); CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); o.resetTransformation(); CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); }
virtual void visit(Object3D &theNode) { if(theNode.enabled() || !visit_only_enabled()) { m_transform_stack.push(m_transform_stack.top() * theNode.transform()); for (Object3DPtr &child : theNode.children()){child->accept(*this);} m_transform_stack.pop(); } }
Vector3 CSGUnionIntersection::normal() { Vector3 local = iheap.intersection()->normal(); Object3D* oc = static_cast<Object3D*>( iheap.object() ); oc->transformNormalOut(local); return local; }
void SceneTest::parent() { Scene3D scene; /* Scene parent cannot be changed */ Object3D* scenePointer = &scene; Object3D object; scenePointer->setParent(&object); CORRADE_VERIFY(scene.parent() == nullptr); CORRADE_VERIFY(scene.children().isEmpty()); CORRADE_VERIFY(object.children().isEmpty()); }
void Accelerator::init(const vector<Object3D*>& geometry, const vector<const Plane*>& scene_planes) { for(unsigned int i = 0; i < geometry.size(); ++i) { Object3D* obj = geometry[i]; unsigned int no_of_prims = primitives.size(); primitives.resize(no_of_prims + obj->get_no_of_primitives()); for(unsigned int j = 0; j < obj->get_no_of_primitives(); ++j) primitives[j + no_of_prims] = new AccObj(obj, j); } planes = scene_planes; }
Object3D::Object3D(const Object3D& obj) : QObject(obj.parent()), m_center(obj.center()), m_translation(obj.translation()), m_rotations(obj.rotations()), m_interactiveQuartenion(obj.interactiveQuartenion()), m_slices(obj.slices()), m_stacks(obj.stacks()), m_texture(obj.texture()), m_inputType(obj.inputType()) { }
void DrawObject3DAmbient ( std::string name, vec2 centre, float scale, float angle, float bank ) { Object3D* obj = GetObject3D(name); EnableTexturing(); DisableBlending(); obj->BindTextures(); //glUniform3f(UniformLocation("Ambient"), ambient.red(), ambient.green(), ambient.blue()); SetShader("3DBase"); glUniform1f(UniformLocation("specularScale"), obj->SpecularScale()); glUniform1f(UniformLocation("shininess"), obj->Shininess()); Matrices::SetViewMatrix(matrix2x3::Translate(centre)); obj->Draw(scale, angle, bank); }
Intersection* CSGIntersect::intersectLocalLimitedTime(const Ray &shoot, DBL tmax) const { assert(isclosed); stat.eval(); CSGIntersectIntersection* i = 0; // fill Array with initial values for(unsigned int j=0; j<objects->listsize; j++) { Object3D* current = static_cast<Object3D*>(objects->list[j]); double t; if ( (t=current->intersectBounding(shoot,tmax))!=INTERSECTION_TIME_EPSILON ) { if (t > INTERSECTION_TIME_EPSILON) { // boundingbox hit if (i == 0) i = new CSGIntersectIntersection(this,shoot,tmax); i->put(0,t,current); continue; } } else { // there is no boundingbox or we are inside Intersection* ci = current->intersectLimitedTime(shoot,tmax); if (ci) { if (i == 0) i = new CSGIntersectIntersection(this,shoot,tmax); i->put(ci,ci->currentTime(),current); continue; } } // no intersection with that object, test if we are inside Vector3 testpoint = Vector3::add( shoot.getOrigin(), shoot.getDirection() ); if (static_cast<const Object3D*>(current)->isInsideAtBounded(testpoint)==false) {delete(i); return 0;} } if (i) { // build up structure if (i->init() == false) {delete(i); return 0;} stat.success(); } return i; }
//temporary function void GraphicsCore::UpdateLightValues(Object3D object) { //lightinfos vec3 ambient = vec3(0.4, 0.4, 0.4); //material vec3 ambientRefl = vec3(1.0f, 1.0f, 1.0f); vec3 diffuseRefl = vec3(0.9f, 0.9f, 0.9f); vec3 specularRefl = vec3(0.4f, 0.4f, 0.4f); float shininess = 2.0; uint shaderProgHandle = object.GetShaderID(); uint location = glGetUniformLocation(shaderProgHandle, "Light.La"); //gets the UniformLocation from shader.vertex glUniform3fv(location, 1, &ambient[0]); //------------------- location = glGetUniformLocation(shaderProgHandle, "Material.Ka"); //gets the UniformLocation from shader.vertex glUniform3fv(location, 1, &ambientRefl[0]); location = glGetUniformLocation(shaderProgHandle, "Material.Kd"); //gets the UniformLocation from shader.vertex glUniform3fv(location, 1, &diffuseRefl[0]); location = glGetUniformLocation(shaderProgHandle, "Material.Ks"); //gets the UniformLocation from shader.vertex glUniform3fv(location, 1, &specularRefl[0]); location = glGetUniformLocation(shaderProgHandle, "Material.Shininess"); //gets the UniformLocation from shader.vertex glUniform1fv(location, 1, &shininess); }
void newGame () { music.stop(); music.openFromFile("./dati/audio/Morricone.ogg"); music.play(); main_camera.setLocRot(locRot(0,0,0,0,0,0)); int j; t=reset_time(t); for(j=0; j<18; j++){ m[j]=reset_motion(m[j]); } livello=1; // for the score score = 0; gun0.bullet_number = BULLET_NUMBER; first = TRUE; return; }
void init(void) { // initialize vector arrays Vector3D::arr = new float[3]; Vector4D::arr = new float[4]; Camera::viewMatrix = new float[16]; /*************CAMERA****************/ // initializam camera principala camera = new Camera(); camera->type=CameraTypeFPS; camera->SetPosition(Vector3D(0,5,15)); camera->SetForwardVector(Vector3D(0,0,-1)); camera->SetUpVector(Vector3D(0,1,0)); camera->SetRightVector(Vector3D(1,0,0)); // pozitionare camera camera->Render(); /*************OBIECTE****************/ objects = new Object3D*[MAX_OBJECT_COUNT]; Object3D *newObject; //TODO: Creaza obiecte // creaza si seteaza obiectul newObject = new Plane(10); newObject->setColor(Vector3D(0,0.2,0)); newObject->setLevelOfDetail(1); newObject->setSelectable(true); objects[objectCount++]=newObject; /*************SISTEME PARTICULE****************/ textura=LoadTextureBMP("snow.bmp",TEXTURA_FILTRARE_TRILINEAR_ANISOTROPIC); textura1=LoadTextureBMP("spark.bmp",TEXTURA_FILTRARE_TRILINEAR_ANISOTROPIC); pcamera=new MyParticleCamera(camera); pcamera->notifyCameraChange(); manager=new ParticleManager(); generateTest(currentTest); /*************INITIALIZARE SCENA****************/ glClearColor(0.0, 0.0, 0.0, 0.0); // stergem tot glEnable(GL_DEPTH_TEST); // activam verificarea distantei fata de camera (a adancimii) glShadeModel(GL_SMOOTH); // shading model: mod de desenare SMOOTH //glEnable(GL_LIGHTING); // activam iluminarea glEnable(GL_NORMALIZE); // activam normalizarea normalelor //glLightModelfv(GL_LIGHT_MODEL_AMBIENT,(Vector4D(0.1,0.1,0.1,1)).Array()); // lumina ambientala glEnable(GL_ALPHA_TEST); // activam testarea parametrului alfa, pentru a permite transparenta }
void DualQuaternionTransformationTest::rotate() { { Object3D o; o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); o.rotateX(Deg(17.0f)) .rotateY(Deg(25.0f)) .rotateZ(Deg(-23.0f)) .rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* Matrix4::rotationZ(Deg(-23.0f))* Matrix4::rotationY(Deg(25.0f))* Matrix4::rotationX(Deg(17.0f))* Matrix4::translation({1.0f, -0.3f, 2.3f})); } { Object3D o; o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); o.rotateXLocal(Deg(17.0f)) .rotateYLocal(Deg(25.0f)) .rotateZLocal(Deg(-23.0f)) .rotateLocal(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})* Matrix4::rotationX(Deg(17.0f))* Matrix4::rotationY(Deg(25.0f))* Matrix4::rotationZ(Deg(-23.0f))* Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); } }
Intersection* CSGUnion::intersectLocalLimitedTime(const Ray &shoot, DBL tmax) const { assert(isclosed); stat.eval(); CSGUnionIntersection* i = 0; // fill Array with initial values for(unsigned int j=0; j<objects->listsize; j++) { Object3D* current = static_cast<Object3D*>(objects->list[j]); double t; if ( (t=current->intersectBounding(shoot,tmax))!=INTERSECTION_TIME_EPSILON ) { if (t > INTERSECTION_TIME_EPSILON) { // boundingbox hit if (i == 0) i = new CSGUnionIntersection(this,shoot,tmax); i->put(0,t,current); } } else { // there is no boundingbox or we are inside Intersection* ci = current->intersectLimitedTime(shoot,tmax); if (ci) { if (i == 0) i = new CSGUnionIntersection(this,shoot,tmax); i->put(ci,ci->currentTime(),current); } } } if (i) { // build up structure if (i->init() == false) {delete(i); return 0;} stat.success(); } return i; }
void MotionBlurExample::drawEvent() { GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth); camera->draw(drawables); swapBuffers(); cameraObject->rotateX(Deg(0.5f)); spheres[0]->rotateZ(Deg(-1.0f)); spheres[1]->rotateZ(Deg(0.5f)); spheres[2]->rotateZ(Deg(-0.25f)); redraw(); }
//non-accelerate castShadowRay bool RayTracer::castShadowRay(Vec3f point, Vec3f lightDir, float distanceToLight) const { Group *group = s->getGroup(); int numOfPrim = group->getNumber(); Object3D* instance; Ray r(lightDir,point); Material* material =NULL; Hit hit(distanceToLight,material,Vec3f(1,1,1)); for(int i=0; i<numOfPrim; i++) { instance = group->getObject(i); if(instance->intersect(r,hit,0) == 1) //设置tmin为EPSILON { return 1; } } //没有相交 return 0; }
void handleMouseKeypress(int key, int state, int x, int y) { switch (key) { case GLUT_LEFT_BUTTON: if (state == 0 && pause==FALSE){ if (gun0.bullet_number > 0) { gun0.bullet_number--; pistola.pushAnimation(animation(locRot(0,0,0,10,0,-10),100,std::chrono::system_clock::now())); pistola.pushAnimation(animation(locRot(0,0,0,-10,0,10),100,std::chrono::system_clock::now()+std::chrono::milliseconds(100))); collisionCurse(); } else { sound.setBuffer(sound_youreempty); sound.play(); } } break; } }
bool Grid::intersectWithOverlapObject(const Ray & r, Hit & h, float tmin) const { MarchInfo mi; bool re = initializeRayMarch ( mi, r, tmin ); if ( re == false ) { return false; } int index_i, index_j, index_k; while ( IsCellValid(mi) ) { RayTracing_Stats::IncrementNumGridCellsTraversed(); index_i = mi.get_i(); index_j = mi.get_j(); index_k = mi.get_k(); Object3DVector & obj_array = cells[num_y * num_z * index_i + num_z * index_j + index_k].objs; int num_objs = obj_array.getNumOfObjects(); if ( num_objs > 0 ) { bool flag = false; for (int i = 0; i < num_objs; ++i) { Object3D * obj = obj_array.getObject(i); if (obj->intersect(r, h, tmin) == true) flag = true; } if ( flag ) return true; } mi.nextCell(); } return false; }
bool OpenGLRenderer::renderBoundingVolumes(Object3D &object, Camera &camera, RenderTarget &renderTarget, bool showSphere, bool showAABB, bool showOOBB) { if (showSphere) { if (renderBoundingSphere(object.getBoundingSphere(), object.getPosition(), glm::vec3(1.0f, 0.0f, 0.0f), camera, renderTarget) == false) { return false; } } if (showAABB) { if (renderBoundingBox(object.getAABB(), glm::mat4(1.0f), glm::vec3(0.0f, 1.0f, 0.0f), camera, renderTarget) == false) { return false; } } if (showOOBB) { if (renderBoundingBox(object.getOOBB(), object.getModelMatrix(), glm::vec3(0.0f, 0.0f, 1.0f), camera, renderTarget) == false) { return false; } } return true; }
void MotionBlurExample::drawEvent() { defaultFramebuffer.clear(DefaultFramebuffer::Clear::Color|DefaultFramebuffer::Clear::Depth); camera->draw(drawables); swapBuffers(); cameraObject->rotateX(1.0_degf); spheres[0]->rotateZ(-2.0_degf); spheres[1]->rotateZ(1.0_degf); spheres[2]->rotateZ(-0.5_degf); Utility::sleep(40); redraw(); }
void GraphicsCore::UpdateBillboardObjectValues(Object3D object) { vec3 up(0.0f, 1.0f, 0.0f); mat4 Projection = glm::perspective(fov, float(windowWidth) / (float)windowHeight, 0.1f, 200.f); mat4 Model = glm::translate(object.GetWorldPos()); mat4 viewMatrix = mCam.GetRotationMatrix() * glm::lookAt(mEye, mTarget, up); mat4 ModelView = viewMatrix * Model; float Size = object.GetSize();; uint shaderProgHandle = object.GetShaderID(); uint location = glGetUniformLocation(shaderProgHandle, "ProjectionMatrix"); //gets the UniformLocation from shader.vertex if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &Projection[0][0]); } location = glGetUniformLocation(shaderProgHandle, "ModelViewMatrix"); //gets the UniformLocation from shader.vertex if( location >= 0 ){ glUniformMatrix4fv(location, 1, GL_FALSE, &ModelView[0][0]); } location = glGetUniformLocation(shaderProgHandle, "Size"); //gets the UniformLocation from shader.vertex glUniform1fv(location, 1, &Size); }
Object3D::Object3D(const Object3D &object, const CopyOp ©op): QObject(), Switch(object, copyop), _frameMatrix(object._frameMatrix), _transformationMatrix(object._transformationMatrix), _center(object._center), _origCenter(object._origCenter), _hasMaterial(object._hasMaterial), _isEditable(object._isEditable), _isPickable(object._isPickable), _isAPhantom(object._isAPhantom), _isAShadowCaster(object._isAShadowCaster), _isAShadowReceiver(object._isAShadowReceiver), _transparencyValue(object._transparencyValue), _sgList(object._sgList) { _selNode = dynamic_cast<MatrixTransform*>(this->getChild(0)); _originalNode = _selNode->getChild(0); updateNodeMask(); _objectStateSet = _selNode->getOrCreateStateSet(); setName(object.getName()); }
void BulletExample::drawEvent() { GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth); /* Housekeeping: remove any objects which are far away from the origin */ for(Object3D* obj = _scene.children().first(); obj; ) { Object3D* next = obj->nextSibling(); if(obj->transformation().translation().dot() > 100*100) delete obj; obj = next; } /* Step bullet simulation */ _bWorld.stepSimulation(_timeline.previousFrameDuration(), 5); /* Draw the cubes */ if(_drawCubes) _camera->draw(_drawables); /* Debug draw. If drawing on top of cubes, avoid flickering by setting depth function to <= instead of just <. */ if(_drawDebug) { if(_drawCubes) GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::LessOrEqual); _debugDraw.setTransformationProjectionMatrix( _camera->projectionMatrix()*_camera->cameraMatrix()); _bWorld.debugDrawWorld(); if(_drawCubes) GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::Less); } swapBuffers(); _timeline.nextFrame(); redraw(); }