Sorting Object Pointers in C++

January 13th, 2009 No comments

Today I was working on my computer animation project using C++, Boost, STL, and OpenGL. I ran into a few hitches related to pointers and the STL (Standard Template Library) and I decided to blog about it.

Problem: You can’t override the default operator<  for the pointer type, so you have to make a class/structure that defines an operator() function, which is the function pointer. Any attempt to create a operator< (const Frame *lhs, const Frame *rhs) will be ignored. You might find yourself wondering why objects are being sorted by memory address (pointer address), rather than your defined method. Here’s an excerpt from my code. (Thanks to CopySourceAsHTML)

// Frame.h

/** A compare class used for Frame pointers.*/

class FrameComparer {

public:

bool operator() ( const Frame *lhs, const Frame *rhs) {

return (*lhs).getTime() < (*rhs).getTime();

}

};

//FrameViewer.cpp

/** Adds frames to be viewed at a later time */

void FrameViewer::addFrames(std::vector<Frame *> frames) {

// Append the new frames to current frames

_frames.insert(_frames.end(), frames.begin(), frames.end());

// Sort

std::sort(_frames.begin(), _frames.end(), FrameComparer());

}

Summary:

I had a STL vector full of pointer objects, but the only way I was comparing was by pointer address until I created the FrameComparer class. With the class and an compare object defined I’m able to override the sort methods comparison behavior. This way will correctly sort the Frame objects by time value, rather than pointer address.

References:

Function pointers

Categories: Animation Project Tags: , , , ,

XNA 3.0 Content Pipeline

January 1st, 2009 2 comments

I spent all day researching the XNA Content Pipeline in XNA 3.0. The MSDN documentation is a little sparse/dense on how things work together; so I pulled together some resources that I found helpful when trying to understand it.

There’s 4 main components in the Content Pipeline: Importers, Processors, Writers, and Readers. Read the 2nd point to understand how they work together or go through the tutorial in my 1st point to get your hands dirty. The 3rd point is another tutorial to help you understand creating a new game asset from start to finish.

Read more…

Categories: XNA Tags:

Gears of War 2 != 9/10

December 22nd, 2008 No comments

I recently acquired Gears of War 2 as an early Christmas present and had the opportunity to play it in cooperative mode with my roommate. It didn’t quite live up to my expectations and it failed to fix some of the game play mechanics that I hated from the first Gears of War (GOW) game. I’m not sure how it was given a 9/10 on Gamespot.com’s website, but I certainly do not agree with them. Here’s my breakdown on the single player/coop experience.

Read more…

Categories: Video Games Tags: ,

Macbook Pro + Windows + Dual Monitors = Painful

September 14th, 2008 12 comments

I didn’t think it would be so hard to just get my taskbar and icons on a second monitor using Windows on my Macbook Pro. It doesn’t seem like a whole lot of people run Windows on the Mac, so there isn’t a whole lot of resources if you get stuck. It takes a lot of digging to find the real answers. Turns out the display drivers from NVIDIA/Apple for Windows don’t support making an external monitor as a primary monitor. It only gives the option of making the laptop display primary. This limitation is very painful and kept me up for hours/days searching for registry hacks, hacked drivers, and more. Here’s what I found that didn’t work and what did: Read more…

PAX 10

September 3rd, 2008 No comments

Wow. I just got back from the PAX 10 competition sponsored by Penny Arcade (penny-arcade.com). It’s a competition for the top 10 games developed by independent game developers.

I worked on Impulse with a group of students from RIT and my brother. It’s a physics based game around movement. You use magnetism and impulse forces to get around the level. It was a 10 week project, so it’s still missing some of the game elements to make it into a full game, but it’s a great prototype.

We’re now working on it to get it to a point where it will be able to be distributed.

For the game I worked on the particle effects to give the player a sense of what’s happening and to make it look pretty. I’m looking to revamp the system now that I have time to design and structure it for more complex, yet pretty effects. I’m also working on a level editor to make level creation a whole lot less painful.

Categories: News Tags: , ,

End of the Year and Summer

May 11th, 2008 No comments

It’s week 10 at RIT; only one more week of class and then finals! I’m excited because once I finish up here I’ll be heading home and then out to California to work for Apple!

Categories: Uncategorized Tags:

Life Changing Event

January 24th, 2008 2 comments

My life has changed thanks to Joe.

Suddenly my tab key is more useful on my Macbook. I can now tab through my dialog option buttons. There’s an obscure setting in the System Preferences > Keyboard and Mouse > Keyboard Shortcuts > Full Keyboard Access (set to All Controls). Or you can press ctrl-F7.

This makes so many things much easier to do with out having to constantly use the mouse to move to a button and click.

Love it!

Categories: Computer Science, Life at RIT, Mac Tags:

A Goal, Yet So Much More.

December 1st, 2007 3 comments

What would you do if you had a goal that you could almost reach, but not quite. It’s something that sits in front of you like a carrot on a stick. What steps would you take to reach it and how committed are you till the end?

Read more…

Categories: Life at RIT Tags:

Form. Not Weight.

November 25th, 2007 No comments

So it might surprise you that I enjoy going to the gym to lift weights. It’s a little “hobby” of mine ever since playing JV Lacrosse in high school. I’m not sure what clicked, but ever since lacrosse I’ve never been the same with my physical fitness. I really enjoyed pushing myself to the limit.

Now I don’t consider myself a complete expert, but I really hate it when I see people doing things with weights that they shouldn’t be doing. So many times I see people using more weight than they can handle and it just bothers me. I want to tell them they’re doing it wrong, but there’s just so many people and I don’t want to rub them the wrong way.

Read more…

Categories: Fitness Tags:

Cell Phones are a Disappointment

November 20th, 2007 2 comments

Cell phones continue to disappoint me. I’ve had my Verizon Wireless cell phone for the past two years. It’s been alright and I was excited to upgrade to something smaller, slimmer, and faster, yet I found myself wanting more. Why do I get so little out of the phone and the phone service?

A few weeks ago I received my new phone the KRZR after doing a bit of research and reading some positive reviews. It looked nice and it was much slimmer than my Motorola E815, but it lacked so many of the features that I had expected. Maybe my term features isn’t the best way to describe it. My biggest disappointment is the user interface and the way I interact with the phone; I consider the interface to be the single most important feature to any phone.

Read more…

Categories: Cell Phones Tags: