Jump to content

  • Log In with Google      Sign In   
  • Create Account

BlueSpud

Member Since 17 Jul 2013
Offline Last Active Yesterday, 03:57 PM

Topics I've Started

Getting Bounding Box For Sphere on Screen

13 December 2014 - 05:35 PM

Hey,

So I want to do a bit of optimization on my deferred renderer, in that currently I render all the lights as full screen quads, which wastes a lot of time on unnecessary pixels. Right now, all I have is point lights, so basically lights are represented with a position and a radius. I want to compute the bounding box for the sphere so that I can either render quads where the fragment shader is going to be preformed or tile-based shading, all though I'm not sure if tile based shading needs this kind of computation. Right now I've used an approximation algorithm to get the radius and the center on screen and then I can construct the bounding box by that. It goes something like this:

float rad = glm::atan(lightRad, screenSpacePos.z);
            rad = rad*(glm::max(ENGINE_WIDTH, ENGINE_HEIGHT) / glm::radians(RENDERENGINE_FOV));

It kinda works, but, like I said, its only an approximation, and when the camera is rotated, things that it covers becomes uncovered, so I need a more accurate representation. My thought was to construct a bounding box of the sphere in world space and translate it to clip space, get the min and max of all the points and construct a bounding box that way. Is there any way to do this more optimally? Or is this going to be one of the best ways to make sure that this is fairly accurate, as well as include other shapes ultimately (because bounding boxes can be calculated for those too). 

 

Thanks.


Using SDL, OpenGL and Qt Together

07 December 2014 - 11:56 AM

For a while I've been using SDL to write my 3D engine,and have recently been implementing an editor that can export an optimized format for the type of engine Im building. Right now the editor is fairly simple, objects can just be moved around and their textures and models can be changed. As of right now, I'm using SDL with OpenGL to render everything, but I want to use Qt for the GUI part of the editor, that way it looks native on every platform. I've got it working great so far, I'm running a QApplication inside of the SDL application, so it basically just opens 2 windows, one that uses SDL and OpenGL, and the other using Qt. Doing a bit of research, I've found that you can manually update a QApplication, which totally removes any threading problems, and everything works. Just in case you're having a hard time visualizing this, heres a picture:

prbjc.jpg

What my goal is to merge these windows into one, because on smaller screens (like my laptop's) it makes it really hard to keep track of all the different windows that I would eventually have. I know theres a way to render to Qt with OpenGL, but can this be integrated with SDL? Am I going to need to move away from using an SDL window and use a QT one if the editor is enabled? Just to clarify, when the engine isn't in editor mode, it won't use and Qt, just SDL, so optimally I wouldn't need to do this.

Thanks.


Equivalent Rotation in Bullet in OpenGL

26 November 2014 - 04:59 PM

Hello,

So I've been working on integrating bullet into my engine. My rendering engine uses glRotate to rotate the geometry, which works fine. Only thing is, when something is rotated, because the rigid body is linked to the geometry, it needs to rotate in the same way. I know how glRotate works, but I have no idea how bullet handles its rotations, as far as if its in radians, etc.

 

Heres what I did for my translations, and I'm pretty sure you can use setRotation() to do rotations, but I'm not exactly sure how. Does anyone have any ideas? They would be much appreciated.

position = newPos;
        
        //we need to update the rigidbody, if we have one
        if (parent->hasComponent(CCollisionI))
            {
                CCollision* c = (CCollision*)parent->getComponent(CCollisionI);
                btMotionState* m = c->rigidBody->getMotionState();
                delete m;
                
                btTransform t;
                t.setIdentity();
                t.setOrigin(btVector3(newPos.x,newPos.y,newPos.z));
                
                btMotionState* motionStatePlane = new btDefaultMotionState(t);
                c->rigidBody->setMotionState(motionStatePlane);
                
            }


VBOs Crash When Using Textures

10 August 2014 - 08:21 AM

Hey,

So I've tried to implement VBOs to see if they would be beneficial over display lists. I wanted to start out simple, so drawing a textured quad on the screen. Drawing a non-textured quad is fine. However as soon I try to put in texture coordinates, crash. I have absolutely no idea whats wrong. When I bind 0 to texture and shader, everything is fine, but the quad is white, as you would expect. The exact same code works just fine with display lists. Here is my code:

//create a vertex buffer object for the particles to use
        glGenBuffers(1, &VBO);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        
        //create the data, this is really sloppy
        float QuadVertextData[] = {0,0,0,1,0,0,1,1,0,0,1,0};
        float QuadTextureData[] = {0,1,1,1,1,0,0,0};
        
        glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*3, &QuadVertextData, GL_STATIC_DRAW);
        
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        
        //generate another buffer for the texcoords
        glGenBuffers(1, &VBOT);
        glBindBuffer(GL_ARRAY_BUFFER, VBOT);
        glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*2, &QuadTextureData, GL_STATIC_DRAW);
        
        glBindBuffer(GL_ARRAY_BUFFER, 0);

render:

        glUseProgram(shader);
        
        glBindTexture(GL_TEXTURE_2D, texture);
        
        for (int i = 0; i < Quads.size(); i++)
        {
            Quads[i]->render(shader, cam);
        }

//the quad render
glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glVertexPointer(3, GL_FLOAT, 0, 0);
        
        glBindBuffer(GL_ARRAY_BUFFER, VBOT);
        glTexCoordPointer(2, GL_FLOAT, 0, 0);
        
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    
        glDrawArrays(GL_QUADS, 0, 4);
        
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);

 I really have no idea whats wrong with this. From everything I've looked at, this should absolutely fine. Id love some help or advice, anything. Thanks.


Inertia Causing Extremely odd effects.

06 August 2014 - 01:03 PM

Hey,
So I downloaded bullet today because I've heard nothing but good things about it. Unfortunately, after reading a quick tutorial, something went terribly wrong XD. So I created plane to serve as the ground and then added a sphere above it and let it fall onto the plane. It hits the ground like I'd expect and then just starts infinitely accelerating towards the negative x and keeping a constant z and y. Here is my code:

//
//  physics.cpp
//  Spud Engine
//
//  Created by Logan on 8/6/14.
//  Copyright (c) 2014 Logan. All rights reserved.
//

#include "physics.h"


physicsWorld::physicsWorld()
    {
        //create all the world components
        bulletConfiguration = new btDefaultCollisionConfiguration();
        bulletDispatcher = new btCollisionDispatcher(bulletConfiguration);
        bulletBroadPhaseInterface = new btDbvtBroadphase();
        bulletSolver = new btSequentialImpulseConstraintSolver();
        
        //create the world
        bulletWorld = new btDiscreteDynamicsWorld(bulletDispatcher,bulletBroadPhaseInterface,bulletSolver,bulletConfiguration);
        bulletWorld->setGravity(btVector3(0,-10,0));
        
        //here are some temp gemoetries
        btTransform t;
        t.setIdentity();
        t.setOrigin(btVector3(0,0,0));
        
        btStaticPlaneShape* plane = new btStaticPlaneShape(btVector3(0,1,0),0.0);
        btMotionState* motionStatePlane = new btDefaultMotionState(t);
        btRigidBody::btRigidBodyConstructionInfo info(0.0,motionStatePlane,plane);
        btRigidBody* planeBody = new btRigidBody(info);
        
        
        rigidBodies.push_back(planeBody);
        bulletWorld->addRigidBody(planeBody);
        
        addRigidSpehere(1, glm::vec3(0,3,0));
        
        
    }

physicsWorld::~physicsWorld()
    {
        //delete all the rigid bodies
        for (int i = 0; i <  rigidBodies.size(); i ++)
        {
            delete rigidBodies[i];
        }

        
        //delete everything
        delete bulletWorld;
        delete bulletSolver;
        delete bulletBroadPhaseInterface;
        delete bulletDispatcher;
        delete bulletConfiguration;
        
    }

void physicsWorld::update(double time)
    {
        bulletWorld->stepSimulation(time);
    }

btRigidBody* physicsWorld::addRigidSpehere(float rad, glm::vec3 position)
    {
        btTransform t;
        t.setIdentity();
        t.setOrigin(btVector3(position.x,position.y,position.z));
        
        btSphereShape* sphere = new btSphereShape(rad);
        
        //calculate inertia
        btVector3 inertia(0.0,0.0,0.0);
        sphere->calculateLocalInertia(1.0, inertia);
        
        btMotionState* motionState = new btDefaultMotionState(t);
        btRigidBody::btRigidBodyConstructionInfo info(1.0,motionState,sphere,inertia);
        btRigidBody* sphereBody = new btRigidBody(info);
        
        rigidBodies.push_back(sphereBody);
        bulletWorld->addRigidBody(sphereBody);
        
        return sphereBody;
    }

And Im updating it with:

 SceneRenderer.currentScene->PhysicsWorld->update(1.0/60.0);

Also, both printing out and rendering are demonstrating that problem. Here is the code for that bit:

//temp to test out physics
        btTransform t;
        btVector3 origin;
        float mat[16];
        PhysicsWorld->rigidBodies[1]->getMotionState()->getWorldTransform(t);
        t.getOpenGLMatrix(mat);
        origin = t.getOrigin();
        
        std::cout << origin.x() << " " << origin.y() << " " << origin.z() << std::endl;
        
        RenderEngine.translateToCameraSpace(cam);
        glMultMatrixf(mat);
        PhysicsSpehere->render(program);

I just started messing around with this, so if anyone can help, I would really appreciate it. Thanks.

 

EDIT: after a bit more messing around as well as implementing a few other things, it seems that there is a problem with the inertia. Is there something Im doing wrong there?


PARTNERS