Пример #1
0
void CubeDrawable::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) {
    _shader.setDiffuseColor(_color)
        .setSpecularColor(Color3(1.0f))
        .setShininess(20)
        .setLightPosition(camera.cameraMatrix().transformPoint({3.0f, 3.0f, 3.0f}))
        .setTransformationMatrix(transformationMatrix)
        .setNormalMatrix(transformationMatrix.rotationScaling())
        .setProjectionMatrix(camera.projectionMatrix());

    _mesh.draw(_shader);
}
Пример #2
0
void Reflector::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) {
    _shader->setTransformationMatrix(transformationMatrix)
        .setNormalMatrix(transformationMatrix.rotationScaling())
        .setProjectionMatrix(camera.projectionMatrix())
        .setReflectivity(2.0f)
        .setDiffuseColor(Color3(0.3f))
        .setCameraMatrix(static_cast<Object3D&>(camera.object()).absoluteTransformation().rotationScaling())
        .setTexture(*_texture)
        .setTarnishTexture(*_tarnishTexture);

    _sphere->draw(*_shader);
}
Пример #3
0
 void draw(const Matrix4& transformation, SceneGraph::Camera3D& camera) override {
     _shader.setDiffuseColor(_color)
         .setTransformationMatrix(transformation*_primitiveTransformation)
         .setProjectionMatrix(camera.projectionMatrix())
         .setNormalMatrix(transformation.rotationScaling());
     _mesh.draw(_shader);
 }
Пример #4
0
void CubeMapExample::drawEvent() {
    defaultFramebuffer.clear(FramebufferClear::Depth);
    defaultFramebuffer.invalidate({DefaultFramebuffer::InvalidationAttachment::Color});

    camera->draw(drawables);
    swapBuffers();
}
Пример #5
0
void Icosphere::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) {
    shader->setDiffuseColor(color)
        .setSpecularColor(Color3(1.0f))
        .setShininess(20)
        .setLightPosition({3.0f, -3.0f, 3.0f})
        .setTransformationMatrix(transformationMatrix)
        .setNormalMatrix(transformationMatrix.rotationScaling())
        .setProjectionMatrix(camera.projectionMatrix());

    mesh->draw(*shader);
}
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();
}
Пример #7
0
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();
}
Пример #8
0
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();
    }
}
Пример #9
0
void CubeMapExample::viewportEvent(const Vector2i& size) {
    defaultFramebuffer.setViewport({{}, size});
    camera->setViewport(size);
}
Пример #10
0
void CubeMapExample::viewportEvent(ViewportEvent& event) {
    GL::defaultFramebuffer.setViewport({{}, event.framebufferSize()});
    _camera->setViewport(event.windowSize());
}
Пример #11
0
void CubeMap::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) {
    _shader->setTransformationProjectionMatrix(camera.projectionMatrix()*transformationMatrix)
        .setTexture(*_texture);

    _cube->draw(*_shader);
}
void ShadowReceiverDrawable::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera) {
    _shader->setTransformationProjectionMatrix(camera.projectionMatrix()*transformationMatrix);
    _shader->setModelMatrix(object().transformationMatrix());

    _mesh->draw(*_shader);
}