Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
heeen
May 14, 2005

CAT NEVER STOPS
Would anyone be interested in sharing resources like textures and models? I just made a 4096 concrete texture and a 2048 metal floor texture.

Adbot
ADBOT LOVES YOU

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
https://opengameart.org is probably a good place to put things like that.

Morpheus
Apr 18, 2008

My favourite little monsters
So I've been doing some random collision detection stuff, testing out 2D collision on rotatable objects with a rectangular bounding box, squares, circles, all that stuff. And it got me thinking about how one would do something else: I'm kind of curious how to do collision detection with something that doesn't rotate around a central pivot. Like a door. Lets say you had a door that could open and close, but you wanted the player to collide with it even if it was open. What would you do for that?

What I am thinking of, with my limited experience, is simply having the Door return a different bounding box depending on if it's opened of not. If it's closed, then return a rectangle near the 'bottom' of the door. Otherwise, return a rectangle to the 'side' of the door if it's opened. Does this make any sense? This does allow the player to walk through the door as it's animating, but that shouldn't be too much of a problem unless it's sloooow.

Hughlander
May 11, 2005

Morpheus posted:

So I've been doing some random collision detection stuff, testing out 2D collision on rotatable objects with a rectangular bounding box, squares, circles, all that stuff. And it got me thinking about how one would do something else: I'm kind of curious how to do collision detection with something that doesn't rotate around a central pivot. Like a door. Lets say you had a door that could open and close, but you wanted the player to collide with it even if it was open. What would you do for that?

What I am thinking of, with my limited experience, is simply having the Door return a different bounding box depending on if it's opened of not. If it's closed, then return a rectangle near the 'bottom' of the door. Otherwise, return a rectangle to the 'side' of the door if it's opened. Does this make any sense? This does allow the player to walk through the door as it's animating, but that shouldn't be too much of a problem unless it's sloooow.

A quick and dirty way of handling it is to do multiple passes. Have a single bounding box that encompasses both open and closed states. If it collides with that then investigate further into what state is the door in (It could be transitioning states) and what would the size of the box be for that state.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Why not just use OBBs?

Morpheus
Apr 18, 2008

My favourite little monsters

Avenging Dentist posted:

Why not just use OBBs?

No reason, per se. All of my bounding boxes have rotation applied to them, the only reason I don't do it in this case is because there's nothing set up to rotate around a point that isn't the center of the bounding box. I could, I guess, set up the door to change it's RotationPoint (or whatever) to be its hinge, and then when it enters the 'opening' state, rotate it every tick until it's open (ie rotated at 90 degrees or so), then say it's at its Open state.

Hmm. I guess I'll see if that works.

Rav
Nov 5, 2000

Morpheus posted:

So I've been doing some random collision detection stuff, testing out 2D collision on rotatable objects with a rectangular bounding box, squares, circles, all that stuff. And it got me thinking about how one would do something else: I'm kind of curious how to do collision detection with something that doesn't rotate around a central pivot. Like a door. Lets say you had a door that could open and close, but you wanted the player to collide with it even if it was open. What would you do for that?

What I am thinking of, with my limited experience, is simply having the Door return a different bounding box depending on if it's opened of not. If it's closed, then return a rectangle near the 'bottom' of the door. Otherwise, return a rectangle to the 'side' of the door if it's opened. Does this make any sense? This does allow the player to walk through the door as it's animating, but that shouldn't be too much of a problem unless it's sloooow.

You must be doing some sort of coordinate transform to move the door from it's closed to open state. A solution would be to take the inverse transform matrix of the door and multiply whatever the door is colliding against by it. Then do a normal cube check as if the door were sitting in the middle of 0,0,0 (or wherever it's modeled from).

Staggy
Mar 20, 2008

Said little bitch, you can't fuck with me if you wanted to
These expensive
These is red bottoms
These is bloody shoes


I'm making a small pac-man clone in C++, using SFML. Right now the map is grid based, loading all of the background images from a single file and then creating a sprite for each at the start. These are then drawn every frame. The thing is, with a 28 by 31 grid - and nothing else whatsoever - I'm getting about 10 FPS. Now I know that I don't need super high frame-rates for pacman, and I've heard of the evils of premature optimization, but this still makes me feel like the way I'm approaching it is fundamentally flawed.

Some ideas that I've had are:
- Only updating the screen every other frame
- Drawing the map to a surface at the start, and then just drawing this surface each time (would drawing one big thing be quicker than drawing lots of little things?)
- Storing the pointers to the sprites in a format other than:
code:
std::map < int , std::map < int , sf::Sprite* > > SpriteGrid;
Unfortunately for all the times I've started stuff this is about the furthest I've ever gotten, and I'm not even sure what to google to point me in the right direction.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Staggy posted:

Storing the pointers to the sprites in a format other than:
code:
std::map < int , std::map < int , sf::Sprite* > > SpriteGrid;

Please don't tell me those ints are the coordinates because that would be silly. Assuming the ints are the tile coordinates - i.e. ([0-28), [0-31)) - you probably aren't dealing with "sparse" data. In fact, all the coordinates might have a sprite in them (or more if you count the player/ghosts/pellets). You should just use a simple 2D array for this. 28*31*4 bytes = 3.4 KB so you're really not spending much memory anyway, and it'll be faster.

That said, I can just about guarantee that this isn't your problem. You really need to get a profiler and check where you're spending the most time because otherwise you're just jumping at shadows.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Yeah, assuming your tiles aren't dynamically scaling down from 1024x768 every frame or something weird like that, nothing you've listed is suspicious.

Mustach fucked around with this message at 19:46 on Apr 8, 2010

Staggy
Mar 20, 2008

Said little bitch, you can't fuck with me if you wanted to
These expensive
These is red bottoms
These is bloody shoes


Avenging Dentist posted:

Please don't tell me those ints are the coordinates because that would be silly. Assuming the ints are the tile coordinates - i.e. ([0-28), [0-31)) - you probably aren't dealing with "sparse" data. In fact, all the coordinates might have a sprite in them (or more if you count the player/ghosts/pellets). You should just use a simple 2D array for this. 28*31*4 bytes = 3.4 KB so you're really not spending much memory anyway, and it'll be faster.

That said, I can just about guarantee that this isn't your problem. You really need to get a profiler and check where you're spending the most time because otherwise you're just jumping at shadows.

Yeah, you pretty much hit the nail on the head. They were the coordinates, and I see what you mean about using std::map for this. And when I changed this there was no difference - right again.

I'll have a look at a profiler, thanks.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
Your code can't be that complex, if all you are doing is drawing a sprites. My guess is you've made a mistake somewhere that we could catch just by eyeballing it. A profiler at this stage is probably a little overkill. Maybe toss it up on pastebin or something and I'd be happy to take a look.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Pfhreak posted:

Your code can't be that complex, if all you are doing is drawing a sprites. My guess is you've made a mistake somewhere that we could catch just by eyeballing it. A profiler at this stage is probably a little overkill. Maybe toss it up on pastebin or something and I'd be happy to take a look.

How is a profiler overkill? You run with a profiler enabled and it spits out a graph and then you look at it. Boy that sure is complicated. (Granted, you'll have to find something if you're programming on Windows, but I know people have linked Windows C++ profilers before.)

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
VS doesn't come with a profiler?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Otto Skorzeny posted:

VS doesn't come with a profiler?

There's this but it doesn't come with VS and I haven't actually tried it: http://msdn.microsoft.com/en-us/performance/default.aspx

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Avenging Dentist posted:

How is a profiler overkill? You run with a profiler enabled and it spits out a graph and then you look at it. Boy that sure is complicated. (Granted, you'll have to find something if you're programming on Windows, but I know people have linked Windows C++ profilers before.)

Because he'll have to go find one, hook it up, configure it, make sure it works, then dig through a graph that's likely WAY more granular than he needs (or spits out a bunch of info about the libraries he's using) when the problem is most likely he's reloading the image from the hard disk every frame or something.

I fail to see how suggesting he go out and get a tool, yet providing no information on where such a tool might be found except for a link that leads to a whole bunch of 'Content has been removed' pages helps. Or were you suggesting he download the Windows SDK? Because I think that's the very definition of overkill.

I suppose he could write his own quick profiler in a static class. (I have the code around here somewhere to do this using SFML...) But once again, it's probably just some novice mistake any one of us could point out with our eyes on the code.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Otto Skorzeny posted:

VS doesn't come with a profiler?
It only comes with the Premium and Ultimate editions for some goofy reason.

edit: What Dentist linked to is good, but only runs on Vista+, if that's a problem for you. Here's a decent overview, since the MSDN pages are busted.

Mustach fucked around with this message at 21:40 on Apr 8, 2010

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Pfhreak posted:

Because he'll have to go find one, hook it up, configure it, make sure it works, then dig through a graph that's likely WAY more granular than he needs (or spits out a bunch of info about the libraries he's using) when the problem is most likely he's reloading the image from the hard disk every frame or something.

Yeah, god forbid someone learn how to do something useful that will serve them well in the future instead of letting you show off.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Mustach posted:

It only comes with the Premium and Ultimate editions for some goofy reason.

edit: What Dentist linked to is good, but only runs on Vista+, if that's a problem for you. Here's a decent overview, since the MSDN pages are busted.

I'm on Win7 and have VS Ult anyways (MSDN), but I generally do coding work on *nix, thus my lack of familiarity with VS's capabilities. Good to know regardless.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Avenging Dentist posted:

Yeah, god forbid someone learn how to do something useful that will serve them well in the future instead of letting you show off.

You're adorable. :allears:

Of course, it'd be nice if VS just included this functionality in the first place.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Man it must be great living in your world where mediocrity is something to aspire to

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Staggy posted:

I'm making a small pac-man clone in C++, using SFML. Right now the map is grid based, loading all of the background images from a single file and then creating a sprite for each at the start. These are then drawn every frame. The thing is, with a 28 by 31 grid - and nothing else whatsoever - I'm getting about 10 FPS.
Check your draw code to see if you are defining new stuff on the graphics card during every frame draw - for example creating a new texture object and sending it your sprite sheet, redefining your HLSL effect every frame, or changing render modes over and over, etc.

I've choked my semi-decent graphics card down to 10 fps before on a 3D scene containing 100 verticies. The problem ended up being that I was creating the HLSL effect file within the draw loop and once I moved it to a more appropriate spot the framerate locked right back to 60 fps.

LightReaper
May 3, 2007

Edited out, problem solved.

LightReaper fucked around with this message at 16:04 on Apr 19, 2010

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
I don't think this:

code:
// Get the Center of the Box 
Vector3 center = box.Max - box.Min;
Is the center of the box. Shouldn't it be (box.Max + box.Min) / 2?

HappyHippo fucked around with this message at 04:39 on Apr 12, 2010

LightReaper
May 3, 2007

HappyHippo posted:

I don't think this:

code:
// Get the Center of the Box 
Vector3 center = box.Max - box.Min;
Is the center of the box. Shouldn't it be (box.Max + box.Min) / 2?
Oh nice catch, I updated it but that's a minor issue compared to the bigger problem of my min and max values for the box being wrong :(

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
Is the BB appearing somewhere significant? Like at the origin, for example?

Screeb
Dec 28, 2004

status: jiggled
You're not even using the center variable in UpdateBoundingBox. You use position instead.

Anyway, your problem is probably something to do with transforms. Like, the model vertex coordinates need to be transformed into world coordinates or something.

LightReaper
May 3, 2007

Edited out, problem solved.

LightReaper fucked around with this message at 16:05 on Apr 19, 2010

Screeb
Dec 28, 2004

status: jiggled

LightReaper posted:

Thanks for that, amended it to this which I think is right but it's prob best I run it by you to ensure I don't make another dumb mistake:

// Get the Center of the Box
Vector3 centerofObject = (box.Max + box.Min) / 2;

// Get the Offset from the position (center of model)
Vector3 offset = centerofObject - position;

Actually, yeah, this is still wrong :v: That is, if you're still adding offset to the bounding box like you do in the original code. It should be

Vector3 offset = position - centerofObject;

Alternatively, you could subtract offset from the box after that. Just think about it in the 1D case: Imagine centerofObject is 5 and position is 3. offset, as you have it, would then be 5 - 3 = 2. Then you do (effectively) centerofObject += 2, which results in 7, whereas it should be 3.


quote:

As for the model vertex coordinates, the code to create the bounding box isn't my own so I'm not really sure how to transform it into world co-ordinates... I took a stab in the dark with these changes to the renderer, marked the added code:

(snip)

But that had no effect (didn't think it would), if you are saying it's a problem with the transforms then why would my collision code only being detecting the collision in the tiny bounding box it's being rendered as? My understanding is that transforming into the world matrix is done at the render stage. I'd be delighted to be proven wrong as at least I have an idea of where the problem is.

Here's the code for the collision checking, there's more to it than that (code to push the sphere outside of the box) but I culled it so here's what's relevant:

code:
Vector3 testCenter = player.boundingSphere.Center;
            Vector3.Min(ref testCenter, ref testPlatform.BoundingBox.Max, out testCenter);
            Vector3.Max(ref testCenter, ref testPlatform.BoundingBox.Min, out testCenter);
            float lengthsq = (player.boundingSphere.Center - testCenter).LengthSquared();
            testPlatform.Collision = (lengthsq < player.boundingSphere.Radius * player.boundingSphere.Radius);
if (testPlatform.Collision) Console.Writeline("Collision");

Sorry, I wasn't very clear. What I was referring to was that in some model formats, like fbx, the vertices aren't necessarily stored at their final, true position. They may be at some "default" or other position, but then have a transformation specified for the object. The vertices you get programmatically then, will be those "default" positions. You may need to subsequently extract the transforms from the file and apply them to the vertices to get their true positions. An example might be where you create a sphere in an editor, then scale it to make it bigger. It could be that only the "original" sphere's coordinates are saved in the file as the vertices, but have along with them, a transformation that describes the fact that the sphere is bigger.

Screeb fucked around with this message at 09:42 on Apr 12, 2010

LightReaper
May 3, 2007

Edited out, problem solved.

LightReaper fucked around with this message at 16:05 on Apr 19, 2010

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
I'm a beginner to OpenGL, and I'm having a lot of trouble getting images loaded into memory to use as textures. Right now I'm trying to get the following code from the OpenGL SuperBible to work correctly:
code:
typedef struct
{
    GLbyte	identsize;              // Size of ID field that follows header (0)
    GLbyte	colorMapType;           // 0 = None, 1 = paletted
    GLbyte	imageType;              // 0 = none, 1 = indexed, 2 = rgb, 3 = gr
    unsigned short	colorMapStart;          // First colour map entry
    unsigned short	colorMapLength;         // Number of colors
    unsigned char 	colorMapBits;   // bits per palette entry
    unsigned short	xstart;                 // image x origin
    unsigned short	ystart;                 // image y origin
    unsigned short	width;                  // width in pixels
    unsigned short	height;                 // height in pixels
    GLbyte	bits;                   // bits per pixel (8 16, 24, 32)
    GLbyte	descriptor;             // image descriptor
} TGAHEADER;

GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint *iHeight, GLint *iComponents, GLenum *eFormat)
	{
    FILE *pFile;			// File pointer
    TGAHEADER tgaHeader;		// TGA file header
    unsigned long lImageSize;		// Size in bytes of image
    short sDepth;			// Pixel depth;
    GLbyte	*pBits = NULL;          // Pointer to bits
    
    // Default/Failed values
    *iWidth = 0;
    *iHeight = 0;
    *eFormat = GL_BGR_EXT;
    *iComponents = GL_RGB8;
    
    // Attempt to open the fil
    pFile = fopen(szFileName, "rb");
    if(pFile == NULL)
        return NULL;
	
    // Read in header (binary)
    fread(&tgaHeader, 18/* sizeof(TGAHEADER)*/, 1, pFile);
    // Get width, height, and depth of texture
    *iWidth = tgaHeader.width;
    *iHeight = tgaHeader.height;
    sDepth = tgaHeader.bits / 8;
    
    // Put some validity checks here. Very simply, I only understand
    // or care about 8, 24, or 32 bit targa's.
    if(tgaHeader.bits != 8 && tgaHeader.bits != 24 && tgaHeader.bits != 32)
        return NULL;
	
    // Calculate size of image buffer
    lImageSize = tgaHeader.width * tgaHeader.height * sDepth;
    
    // Allocate memory and check for success
    pBits = (GLbyte*)malloc(lImageSize * sizeof(GLbyte));
    if(pBits == NULL)
        return NULL;
    
    // Read in the bits
    // Check for read error. This should catch RLE or other 
    // weird formats that I don't want to recognize
    if(fread(pBits, lImageSize, 1, pFile) != 1)
		{
        free(pBits);
        return NULL;
		}
    
    // Set OpenGL format expected
    switch(sDepth)
		{
        case 3:     // Most likely case
            *eFormat = GL_BGR_EXT;
            *iComponents = GL_RGB8;
            break;
        case 4:
            *eFormat = GL_BGRA_EXT;
            *iComponents = GL_RGBA8;
            break;
        case 1:
            *eFormat = GL_LUMINANCE;
            *iComponents = GL_LUMINANCE8;
            break;
		};
	
    
    // Done with File
    fclose(pFile);
	
    // Return pointer to image data
    return pBits;
	}
The GLbyte array I try to fill with the result of this function keeps coming back null, so I added a few cout lines to his code to look where the problem is, and it seems it's returning NULL at the point where it checks the header to see if it's a certain type of TGA format (8,24, or 32 bit), and I guess it doesn't like the format of the file I'm using. The funny thing is, the file I'm trying to copy into memory is a TGA picture that came with the SuperBible code, and it's one that he uses the gltLoadTGA function with in an example :psyduck: I also tried another TGA file that I converted from BMP (without RLE compression) and that didn't work either.

Could anyone tell me if it's the code that's the problem, or if it looks fine, is there a good program I can use to save specific kinds of TGA? (GIMP won't let you specify header info as far as I can tell) Barring that, does someone know of a good tutorial for loading images into memory that has code they know for a fact works? I've tried using a few other methods I found using Google search (for TGA and for BMP formats) and they're all poorly explained tutorials with incomplete code, or they give code that has no explanation and gives 1001 errors when trying to compile with Visual Studio.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Spare yourself a shitload of pain and use FreeImage as your image loader.

chglcu
May 17, 2007

I'm so bored with the USA.
That looks like it might be a problem with the byte alignment of the struct. A padding byte will be inserted by the compiler after imageType and colorMapBits to keep the struct aligned on 16-bit boundaries. If you're using Visual C++, you could try the following to use 1 byte alignment for the struct:

code:
#pragma pack(push, 1)
typedef struct
{
    GLbyte	identsize;              // Size of ID field that follows header (0)
    GLbyte	colorMapType;           // 0 = None, 1 = paletted
    GLbyte	imageType;              // 0 = none, 1 = indexed, 2 = rgb, 3 = gr
    unsigned short	colorMapStart;          // First colour map entry
    unsigned short	colorMapLength;         // Number of colors
    unsigned char 	colorMapBits;   // bits per palette entry
    unsigned short	xstart;                 // image x origin
    unsigned short	ystart;                 // image y origin
    unsigned short	width;                  // width in pixels
    unsigned short	height;                 // height in pixels
    GLbyte	bits;                   // bits per pixel (8 16, 24, 32)
    GLbyte	descriptor;             // image descriptor
} TGAHEADER;
#pragma pack(pop)
I'm not familiar with how to control struct alignment with other compilers off the top of my head.

Some more info, in case your curious (you should be): http://en.wikipedia.org/wiki/Data_structure_alignment

chglcu fucked around with this message at 03:25 on Apr 13, 2010

Screeb
Dec 28, 2004

status: jiggled

LightReaper posted:

I understand what you mean here but if that is the case, why can I correctly get bounding spheres from these models?

Here's how I'm generating a bounding sphere:

http://pastebin.com/UU4Z8uf7
I use this pipeline process from the creator's club website to find the vertices and attach them to the model's data.

http://pastebin.com/FiTtBBDv
I then create a bounding sphere using this method.

As far as I can tell for the vertice processor pipeline process, which I use to create my bounding spheres, the only thing that kind of looks like what you're suggesting is this:

code:
if (mesh != null)
            {
                // Look up the absolute transform of the mesh.
                Matrix absoluteTransform = mesh.AbsoluteTransform; <---------
 
                // Loop over all the pieces of geometry in the mesh.
                foreach (GeometryContent geometry in mesh.Geometry)
                {
                    // Loop over all the indices in this piece of geometry.
                    // Every group of three indices represents one triangle.
                    foreach (int index in geometry.Indices)
                    {
                        // Look up the position of this vertex.
                        Vector3 vertex = geometry.Vertices.Positions[index];
 
                        // Transform from local into world space.
                        vertex = Vector3.Transform(vertex, absoluteTransform); <---
 
                        // Store this vertex.
                        vertices.Add(vertex);
                    }
                }
So I tried doing something similar for the box processor by adding a custom pipeline extension to handle the creation of bounding boxes, after some googling I found this (http://www.harding.edu/dsteil/xna/notes/Making%20Bounding%20Boxes%20For%20Models.htm) which predictably didn't work and had the same problem, so I made these changes based on my vertices processor, marked by arrows:

http://pastebin.com/pMKn0qGs

But still no dice, this is getting depressing :(

Edit: Edited to make some corrections as I copy pasted to pastebin incorrectly and to get my point across better, could really use someone to give it a second look... Dissertation due in a week's time and my engine won't be as solid if I have to use BoundingSpheres for everything.

Hmm, well the only thing I can think of right now is in http://pastebin.com/pMKn0qGs, you only look at the node's children for the bounding box, and never the node itself. Also, I think the transforms should be applied to each MeshContent child, not just the parent (each has one of its own).

LightReaper
May 3, 2007

Edited out, problem solved.

LightReaper fucked around with this message at 16:05 on Apr 19, 2010

Screeb
Dec 28, 2004

status: jiggled
The error you get is because the line should be

center = boundingBox.Min + (boundingBox.Max - boundingBox.Min) * 0.5f;

(note case). BoundingBox is the type, boundingBox is the variable.


I've dug up some old code which may be of use:

code:
private void FindVertices(NodeContent node)
        {
            MeshContent mesh = node as MeshContent;

            if (mesh != null)
            {
                List<Vector3> vertexList = new List<Vector3>();
                Matrix absoluteTransform = mesh.AbsoluteTransform;

                foreach (GeometryContent geometry in mesh.Geometry)
                {
                    foreach (int index in geometry.Indices)
                    {
                        Vector3 vertex = geometry.Vertices.Positions[index];

                        vertex = Vector3.Transform(vertex, absoluteTransform);

                        if (!vertexList.Contains(vertex))
                            vertexList.Add(vertex);
                    }
                }

                // TODO: Here is where you set the min/max values as in your code, by looping through vertexList
            }

            foreach (NodeContent child in node.Children)
            {
                FindVertices(child);
            }
        }
Call this function from the Process function and add the resulting bounding box you construct to the tag data like you did before. Eg

In the Process function of your BoxProcessor:
code:
FindVertices(input); // <-- sets min and max (don't forget to do that)
modelContent.Tag = new BoundingBox(min, max);
You don't need the transforms in Process like you do now, because they've been moved to FindVertices();

LightReaper
May 3, 2007

I already am using the vertices processor for a similar function, so I modified it to suit these needs like so http://pastebin.com/FpaUC1nY

Then getting the relevant info:
Dictionary<string, object> tagData = (Dictionary<string, object>)testPlatform.Model.Tag;
testPlatform.BoundingBox = (BoundingBox)tagData["BoundingBox"];

But now I'm getting this for my Max and Min values for the boundingbox after inserting a breakpoint after I update said bounding box

Max: {X:-3.402823E+38 Y:-3.402823E+38 Z:-3.402823E+38}
Min: {X:3.402823E+38 Y:3.402823E+38 Z:3.402823E+38}

Which strikes me as being wrong in a whole new way (yes, the bounding box doesn't even render at that size). I assume I've done something wrong in the modification of my verticesprocessor.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
Ok I tried FreeImage and it seems like it worked pretty well for getting the image, but now I'm having trouble setting it as a texture with OpenGL.
code:

GLbyte *imageData;
FIBITMAP *fibmp_asteroid;
GLsizei astBmpWidth, astBmpHeight;

fibmp_asteroid = FreeImage_Load(FIF_BMP, "C:\\tga\\asteroid.bmp"); 
imageData = (GLbyte *)FreeImage_GetBits(fibmp_asteroid);
astBmpWidth = (GLsizei)FreeImage_GetWidth(fibmp_asteroid);
astBmpHeight = (GLsizei)FreeImage_GetHeight(fibmp_asteroid);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, astBmpWidth, astBmpHeight, 0,
     GL_RGB, GL_UNSIGNED_BYTE, imageData);
Everything works fine until the last line; adding that gives me a memory access violation error. Any ideas what I'm doing wrong?

Paniolo
Oct 9, 2007

Heads will roll.

Stavros posted:

Everything works fine until the last line; adding that gives me a memory access violation error. Any ideas what I'm doing wrong?

I'm not familiar with the library you're using, but it's probably one of two things: either one of the FreeImage_ functions is returning a null pointer (you aren't checking return values! Bad!) or glTexImage2D is trying to read past the end of the data you're providing it which typically means you're specifying the wrong format.

Adbot
ADBOT LOVES YOU

Screeb
Dec 28, 2004

status: jiggled

LightReaper posted:

I already am using the vertices processor for a similar function, so I modified it to suit these needs like so http://pastebin.com/FpaUC1nY

Then getting the relevant info:
Dictionary<string, object> tagData = (Dictionary<string, object>)testPlatform.Model.Tag;
testPlatform.BoundingBox = (BoundingBox)tagData["BoundingBox"];

But now I'm getting this for my Max and Min values for the boundingbox after inserting a breakpoint after I update said bounding box

Max: {X:-3.402823E+38 Y:-3.402823E+38 Z:-3.402823E+38}
Min: {X:3.402823E+38 Y:3.402823E+38 Z:3.402823E+38}

Which strikes me as being wrong in a whole new way (yes, the bounding box doesn't even render at that size). I assume I've done something wrong in the modification of my verticesprocessor.

Yeah, you've made a mistake.

You've put the vertices into your vertices collection (vertices.Add(vertex);) but then test against vertexList to construct the bounding box. vertexList has nothing in it, cause like I said, you're putting it into vertices instead. Since you're using that vertices collection elsewhere, just replace all references to vertexList with vertices.

Like so:

code:
void FindVertices(NodeContent node)
        {
            // Is this node a mesh?
            MeshContent mesh = node as MeshContent;


            if (mesh != null)
            {
                // Look up the absolute transform of the mesh.
                Matrix absoluteTransform = mesh.AbsoluteTransform;

                // Loop over all the pieces of geometry in the mesh.
                foreach (GeometryContent geometry in mesh.Geometry)
                {
                    // Loop over all the indices in this piece of geometry.
                    // Every group of three indices represents one triangle.
                    foreach (int index in geometry.Indices)
                    {
                        // Look up the position of this vertex.
                        Vector3 vertex = geometry.Vertices.Positions[index];

                        // Transform from local into world space.
                        vertex = Vector3.Transform(vertex, absoluteTransform);

                        // Store this vertex.
                        if (!vertices.Contains(vertex))
                            vertices.Add(vertex);
                    }
                }
                foreach (Vector3 vertex in vertices)
                {
                    if (vertex.X < minX)
                        minX = vertex.X;
                    if (vertex.Y < minY)
                        minY = vertex.Y;
                    if (vertex.Z < minZ)
                        minZ = vertex.Z;
                    if (vertex.X > maxX)
                        maxX = vertex.X;
                    if (vertex.Y > maxY)
                        maxY = vertex.Y;
                    if (vertex.Z > maxZ)
                        maxZ = vertex.Z;
                }
               min = new Vector3(minX, minY, minZ);
               max = new Vector3(maxX, maxY, maxZ);
            }

            // Recursively scan over the children of this node.
            foreach (NodeContent child in node.Children)
            {
                FindVertices(child);
            }
        }
Edit: Also, although it doesn't really matter, you shouldn't be making new min and max vectors in FindVertices each time, since they only need to be set once at the end, since you're keeping track of minX, minY etc already (ie do min = new Vector3(... etc in Process after you call FindVertices). Just a performance thing, but it's minor, so you won't notice any difference - so for now, it's probably best you don't mess with it.

Screeb fucked around with this message at 09:46 on Apr 13, 2010

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply