Hi, i am working on a videogame proyect. I am beginner in OpenFrameworks and i´d like to know how to import obj models, and where locate them. Hope for your answer…
noPixel
[quote author=“noPixel”]Hi, i am working on a videogame proyect. I am beginner in OpenFrameworks and i´d like to know how to import obj models, and where locate them. Hope for your answer…
noPixel[/quote]
have a look at the ofxObjLoader addon - example in /apps/addonsExamples/objLoaderExample .
i haven’t had much experience with it, except to say that it seems to load files exported by Blender and by Wings3d without any trouble.
Thanks!, now i can import obj. My new problem is to navigate a 3d structure and not to through the walls, i mean crash with different objects… any suggestion?
noPixel
[quote author=“noPixel”]Thanks!, now i can import obj. My new problem is to navigate a 3d structure and not to through the walls, i mean crash with different objects… any suggestion?
noPixel[/quote]
Collision-detection! This problem has been solved many times before, but I don’t know if there’s an of-integrated solution someone has already worked out. I remember hearing something recently about softbody 3d collisions, I think from Damian – you might try associating the camera with a non-drawn object used only for tracking collisions.
I’d recommend http://bulletphysics.com/
opensource 3d rigid body physics engine
even the ODE guys switched to using bullet coliision
I remember hearing something recently about softbody 3d collisions, I think from Damian – you might try associating the camera with a non-drawn object used only for tracking collisions.
hmm - collision detection would be the easiest way to do this if you don’t have any other way of describing the space. but, it might also be overkill, especially if you’re actually only working in two dimensions. in this case it is much better to use an image as your collision data, with white pixels that mean you are allowed to be at that 2d location, and black pixels that mean you are not.
you can even encode recovery information in the image. rather than plain black, use two of the three bytes (eg the red and green values, read as signed rather than unsigned chars) to encode a 2D vector that roughly points towards the nearest white area. then, if you land on a non-white pixel, do something like this:
int base_index = (current_y*width + current_x)*3;
while ( /* pixel_data[base_index] != white */ )
{
unsigned char r = pixel_data[base_index];
unsigned char g = pixel_data[base_index+1];
float vector_x = (float)((signed char)r);
float vector_y = (float)((signed char)g);
vector_x /= 127.0f;
vector_y /= 127.0f;
current_x += vector_x;
current_y += vector_y;
base_index = (current_y*width + current_x)*3;
}
of course, you’ll need to preprocess the data somehow to work out all these encoded vectors…
if you do need to go down a collision detection route, then, depending on how large your ‘map’ is you might need to look into hierarchical structures to describe the geometry. BSP-trees can be some kind of fun, and they can be used to describe both geometry and collision spaces. the Quake3 engine (which is now open source), for example, has BSP-trees at its core. BSP tree based engines used to be (and perhaps still are) called ‘portal-engines’.
Thanks for your advice, i am working on that.
To travel round a 3d structure i used the lib OCD from Processing, Now i need to do it in OF. Do anybody knows something similar to apply on OF?
noPixel