Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


sjaakiejj

Member Since 11 Apr 2007
Offline Last Active Apr 14 2012 07:54 PM

Topics I've Started

[ODE] Access Violation at dCollide when using TriMeshes

01 April 2012 - 03:01 PM

Hey guys,

I've been scratching my head at this for a while now, and Google hasn't been my friend for this particular issue. This is my first time using ODE after somebody recommended it to me, and it seems to be a fairly nice and straightforward library to use. However, I'm having some trouble with the use of TriMeshes. Since I want to have terrain collision detection, I decided to use ODE's built-in TriMesh to represent the terrain. Of course, I start off with a simple 2-triangle square representing my "Terrain". I do that with the following code:

void PhysicsManager::createTriMeshBB(Model* model)
{       
const int vCount = 4;
float vertices[vCount * 3] = {
            0,0,0,
            20*30,0,0,
            20*30,0,20*30,
            0,0,20*30
    };
    dTriIndex indices[6] = {
            0,1,2,
            0,2,3
    };

dTriMeshDataID dataID;
dGeomID geomID;

dataID = dGeomTriMeshDataCreate();
dGeomTriMeshDataBuildSingle(dataID, vertices, sizeof(float)*3, vCount, indices, 6, sizeof(dTriIndex)*3);
//dGeomTriMeshDataBuildSimple(dataID, vertices, 4, tmpCreateIndices(), 6);

geomID = dCreateTriMesh(mSpace, dataID, 0, 0, 0);

dGeomSetPosition(geomID,0,0,0);
dGeomSetBody(geomID, 0);

model->setGeometryID(geomID);
}

After having done this, I specify a callback function - say "tmpCallback" as below:

void PhysicsManager::tmpCallback(void * d, dGeomID id1, dGeomID id2)
{


int i;

// Get the dynamics bodies 
  dBodyID b1 = dGeomGetBody(id1);
dBodyID b2 = dGeomGetBody(id2);

std::cout << "Callback" << std::endl;
// Holds the contact joints - Need to read up on this
dContact contact[32];
dContactGeom ptr;

    for (i = 0; i < 32; i++)
    {
        contact[i].surface.mode = dContactBounce;
        contact[i].surface.mu = dInfinity;
        contact[i].surface.mu2 = 0;
        contact[i].surface.bounce = 0.01;
        contact[i].surface.bounce_vel = 0.5;
        contact[i].surface.soft_cfm = 0.01;
}
int numc = dCollide(id1, id2, 1, &contact[0].geom, sizeof(dContact));
if (numc > 0)
    {
        for (i = 0; i < numc; i++)
        {
dJointID c = dJointCreateContact(PhysicsManager::get()->getWorld(), PhysicsManager::get()->getContactGroup(), contact + i);
            dJointAttach(c, b1, b2);
        }
    }
}

This callback function works perfectly when doing plane to sphere collision detection. When the TriMesh is involved however, the program crashes at "dCollide(id1,id2, 1, &contact[0].geom, sizeof(dContact))", throwing an unhandled Access Violation from inside the standard libraries. I'm at a loss at what's causing the problem, and I've tried everything I could think of to solve it.

If you want to slap me in the face and tell me I shouldn't be using ODE, that's fine as well - please do give your own recommendations however :)

Thanks in advance

GLSL Displacement Mapping

01 March 2012 - 01:17 PM

Hi,

I've been trying to perform Displacement Mapping on the GPU using GLSL. The catch is that I'm using a dynamically refined quad-tree to display the terrain that I'm trying to 'displace', and the quads misalign at their borders (They align in the xz plane, just not in the y direction), as you can see in the image I attached.

I'm currently using the following Vertex Shader code:


uniform sampler2D Texture;

void main()
{
  gl_TexCoord[0] = gl_MultiTexCoord0;
  vec4 position = vec4(gl_Vertex);  

  vec4 tex = texture2D(Texture, gl_TexCoord[0].st);
  pos.y = tex.x * 10.0;
  gl_Position = gl_ModelViewProjectionMatrix * position;
}

Each quad has its own sub-texture associated with it, which I clip up on the CPU. (rendering it using the fragment shader gives the right results). The problem, for as far as I can tell, is that the value in "tex" is interpolated somehow (which, given my inexperience with shaders, is probably my use of texture2D in this context). I have however ensured that the pixels on the edges of the textures are identical to their neighbours on the texture patch next to it.

Thanks in advance for your time and help.

Vertex buffer Objects: Strange glBufferData behaviour

06 February 2012 - 11:39 AM

Hi guys,

I've been working on modifying my application to use Vertex Buffer Objects, but I encountered a strange problem that I have been stuck with for days (which is probably related to the way I implemented it).

VBOs are rendered only if I actually pass the buffer data, using glBufferData, in the display function, just before calling glDrawArrays. If I pass the data to glBufferData beforehand (in the init functions) and simply remember the VBO reference, it seems that the data is somehow forgotten.

The relevant pieces of code can be found below. The object is rendered if I #define RENDER_BUFFER, and otherwise it's not. I checked for glErrors on every OpenGL call, but none were present.



void Init(){

#ifndef RENDER_BUFFER

  glGenBuffers(1, &mVboObject);

  glBindBuffer(GL_ARRAY_BUFFER, mVboObject);

  glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * mNumFaces * 3 , mVertices.get(), GL_STATIC_DRAW);

#else

  glGenBuffers(1, &mVboObject);

#endif

}


void Render(){

  /*

   * Draw the object

   */



  glEnableClientState(GL_VERTEX_ARRAY);





#ifdef RENDER_BUFFER

  //This renders perfectly

  glBindBuffer(GL_ARRAY_BUFFER, mVboObject);

  glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * mNumFaces * 3 , mVertices.get(), GL_STATIC_DRAW);



#else

  //This doesn't render at all

  glBindBuffer(GL_ARRAY_BUFFER, mVboObject);



#endif



  glVertexPointer(3,GL_FLOAT,sizeof(Vertex),0);



  glPushMatrix();

	glScaled(20,20,20);

	glDrawArrays(GL_TRIANGLES, 0, mNumFaces*3);

  glPopMatrix();



  glDisableClientState(GL_VERTEX_ARRAY);



  glBindBuffer(GL_ARRAY_BUFFER, 0);

}


Thanks in advance for your time, and hopefully help.

Events, EventManagement and EventListeners - Suggestions?

08 August 2011 - 04:39 AM

Hi,

I've been wondering about this for around a week now, and I'm still not quite sure how to solve it. I come up with different ideas every once in a while, but none of them seem to be "The Best" way of doing it, and some have downright ugly disadvantages.

So here's my question. I've got an Event Management System that allows EventListeners to register with the EventManager, and that allows any class in the system to dispatch an Event. These events can be of an arbitrary number of different types, including but not limited to Movement Events (by both the Player and AI), State Change Events, Game Exit Events and Interaction Events. All of these events need their own specific body, for instance, a Movement Event might need a source (The object that does the moving) and a direction vector. A State Change Event needs to know about the next state. Game Exit Event doesn't need any information, and an Interaction event needs a source and a destination object.

This diversity forms a problem for me, as the first structure I thought of was having an abstract class "Event" and an abstract class "EventListener". EventListener has a method called "Notify" and "handleEvents", and any class that needs to be an event listener can simply inherit those methods. Any Event will just be a subclass of the "Event" class. Having simply one notify method would mean that Casting has to be used, as far as I can see, and I want to avoid that.

A solution to casting I thought of is to have many different "Notify" methods, one for each event. Each of these would have an implementation in the EventListener interface (though the implementation would be to just do nothing with the event), and inheriting classes would simply override the one they're interested in. This would leave the interface rather bloated, with a lot of code, and not a lot of flexibility.

Other options I came across were void pointers, which again imply casting; Further abstracting the Event objects, making a more defined structure and being able to split the events at a higher level, but this would make notification more complicated due to code duplication.

I'd love to hear how you guys approach this problem, as I'm running out of ideas. I'm not looking for a "Quick Hack" as you might've already figured out, as I want the fundamental design to be solid and high quality for this project.

Feedback on my Design

26 July 2011 - 09:12 AM

Hi,


In the past, every time I made a working game-demo it was more or less by a procedural way. This allowed me to build the basics rather quickly, but I always reached a point on which I was unable to continue without a major overhaul of the code, because of things I hadn't thought of, and poor, inflexible design.

To improve that I've been trying to create a fundamentally good design for building a game. I looked at different philosophies, such as Components and Object Oriented design, and whilst Component does seem like a powerful choice, there are still some things that confuse me about it. Instead, I chose to opt for an object oriented design, and the attached image file is what I came up with. Considering that my background is a more classical Computer Science world, understanding where some of the game code goes often confuses me.

As you can see, there's a few comments on there in which I ask questions, or propose assumptions. I've left most of the methods and all the variables out, as it would simply clutter the view even more. I'd like to get some feedback on this, to improve the overall design, and to figure out the sensible places to put some code. Also, feel free to tell me if I've missed something, and ask any questions for clarification.

Thanks in advance, I look forward to hearing your suggestions!

Ps. If there's any books you could recommend for reading, I'd be happy to hear them.


PARTNERS