Moving Phantom Objects Around OpenSim With llMoveToTarget

As part of a uni AI subject I’ve been playing around with implementing some basic path finding in OpenSim. Part of that involved moving objects around a region using the llMoveToTarget function. After some frustration, I’ve discovered that phantom objects do not appear to respond to this function (i.e. you can’t move them using this function). I’m not entirely sure what a phantom object is exactly, so this might be bleedingly obvious to others. Also, this may be incorrect as I haven’t really investigated it thoroughly. Anyways, if you’re trying to move something in OpenSim (or maybe Second Life) using llMoveToTarget and it doesn’t work, it might be worthwhile checking if the object is phantom.

On a personal note, I’m quite busy with uni at the moment, as well as courting (pun intended) my newfound sweetheart – squash (the sport, not the food). So don’t expect any major posts any time soon. If I do anything original with OpenSim (i.e. not implementing my lecturer’s code) I’ll hopefully get around to posting it here for you all to play with.

Sharing GLUT Code Between Windows and Mac OS X

If you’ve seen my last post, you’re aware that I’ve been playing with OpenGL and GLUT for a uni subject. As I like to straddle the OS fence and use a mixture of Windows Vista x64, Windows XP and Mac OS X 10.5, I like to have platform independent solutions to problems. The latest little issue I’ve come across regarding GLUT apps is that GLUT on the Mac has a different include. To include GLUT in a project for the mac, you must use the following:

#include <GLUT/glut.h>

and not:

#include <GL/glut.h>

In order to cut code that will compile successfully on either platform we can use optional includes with the #ifdef, #else and #endif preprocessor directives. Props to “kainjow” for providing this information in his/her forum post. Here’s how:

#ifdef __APPLE__
#include <GLUT/glut.h>
#include <GL/glut.h>

All this does is say “if we’re running on an Apple machine, include GLUT/glut.h, otherwise include GL/glut.h. Now to actually learn OpenGL/GLUT…

Installing freeglut on Vista x64

I’ve recently had to install freeglut as part of a uni subject and ran across an issue due to the fact that I’m running Vista x64 and wanted to dynamically link freeglut against anything I develop during the semester. First of all, building freeglut (version 2.4.0) was problem free. I simply opened freeglut.dsw (in the root directory of the freeglut download) in Visual Studio 2005 (VS2005), agreed to convert the project files to a newer format, and then built the solution. An additional step I took, which may be completely unnecessary, was to change the build type from Debug to Release. Both build types built fine, but I used the release versions as I doubt I will be debugging freeglut. Also note that I compiled this as the default 32-bit, not 64-bit, as I’m building 32-bit GLUT apps for compatibility.

Once this was done, I followed the info in README.win32 (in the freeglut directory) and copied the files to the relevant directories. The specific directories I used for a Vista x64 system with VS2005 were as follows:

  • copy freeglut.h, freeglut_ext.h, freeglut_std.h, and glut.h from freeglut-2.4.0\include\GL to C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\Include\gl.
  • copy freeglut.lib from freeglut-2.4.0\Release to C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\Lib. Note that the correct destination should already contain opengl32.lib, glu32.lib, and glaux.lib
  • Now here’s the part that caused me problems: copy freeglut.dll to C:\Windows\SysWOW64 and NOT C:\Windows\System32 as you might expect, given that it’s a 32-bit library being used in 32-bit projects

Once the files are in place, you should be ready to use freeglut in your apps. To do so, simply include freeglut as follows:

#include "GL/glut.h"

As you can see, we’re referencing glut.h and not freeglut.h. My guess is that this is done to maintain platform independence if your code was being built by a different incarnation of GLUT. For example I used this method to build and run the test app provided by my lecturer (unchanged), who uses the original GLUT.

***UPDATE 2009-02-27 ***
I copied the files I built on my Vista x64 machine to a 32-bit install of XP SP3 on my laptop and GLUT worked fine. The only difference to the above instructions (obviously aside from not building freeglut again) is to copy freeglut.dll to C:\Windows\System32. I’ve also put together a zip package of my build for anybody who wants to avoid building themselves.

TetroGL – OpenGL/C++ tutorial

I’m currently planning on a career in games programming and was looking for some beginners’ tutorials in OpenGL using C++ and found a goodun over at code project.  It’s a 3 part tutorial, and as I’m writing this the first two parts have been posted, complete with code and Visual Studio project files.  As a relative beginner with C++ and a complete beginner with OpenGL I’ve found this fairly easy to follow.  The code is pretty well commented, and the tutorial itself explains things clearly and doesn’t take too much for granted aside from a basic knowledge of programming/C++.

A trap for young players, there was a slight error in the code from the first part that caused the program to not shut down and stay in memory after the window had closed.  Nobody else seemed to have this problem, and it could have just been me being difficult and using Vista.  Nonetheless, if the code for part 1 hasn’t been updated, the fix is in the comments below part 1.  Basically the main application loop did not clear the message queue with each iteration, only taking the first message.  From what I’ve read on the issue this means that the WM_QUIT message sent from PostQuitMessage() is never received.  This is because PostQuitMessage(0) sets a flag on the message queue which tells it to return a WM_QUIT message if the queue is empty.  Obviously if the queue is never cleared, this message is never returned when the queue is queried for the next message.

If you have any problems with this, feel free to contact me.  Happy coding!

When a Leap Year Isn’t a Leap Year

Have you ever had one of those moments when you realise that something you held as a fundamental law of the universe doesn’t work the way you thought it did?  Well I have, today in fact, while writing a batch script that needed to be aware of leap years.  Multiple choice question (I promise it’s relevant), which of the following is a leap year: a) 1700 b)1900 c)both ‘a’ and ‘b’ d)none of the above.  Correct answer: d).  That’s right, it turns out that being evenly divisible by 4 isn’t enough to qualify as a leap year.

So, now that I’ve dropped that bombshell, who wants to know how to pick a leap year every time without embarassing yourself?  Those of you with your hands raised can lower them and simply keep reading, because I’ll fill you in now.  In plain English, a leap year occurs when the year is evenly divisible by 400, OR if the year is evenly divisible by 4 but NOT 100.  Put another way, a leap year occurs every four years as you’d expect, except for the beginning of a new century, where a leap year only occurs if that year is evenly divisible by 400 (e.g. 1600, 2000 etc.).  A nice way to show this process is with the aid of a spiffy flow chart referenced in the article I found today.

For those of you who might need to code this, the wiki article on leap years has pseudocode and C-style code examples of the algorithm.  Furthermore, for those of you who might need to check leap years in a batch script, here’s a simple batch script to do so.  In its current form, the script is called with the year you’re checking as the first and only argument, printing an answer in plain english before finishing.

@echo off

SET _year=%1
SET _bLeapYear=is not

::Check if the year is evenly divisible by 400
SET /a _modYear=%_year% / 400
SET /a _modYear=%_modYear% * 400
If %_modYear%==%_year% SET _bLeapYear=is
If %_modYear%==%_year% GOTO END

::Check if the year is evenly divisible by 4
SET /a _modYear=%_year% / 4
SET /a _modYear=%_modYear% * 4
If NOT %_modYear%==%_year% GOTO END

::Check if the year is evenly divisible by 100
SET /a _modYear=%_year% / 100
SET /a _modYear=%_modYear% * 100
If NOT %_modYear%==%_year% SET _bLeapYear=is

echo %_year% %_bLeapYear% a leap year

As you might have noticed, I’m substituting the modulus operation found in most algorithms (including the ones on the wiki article) with a division followed by a multiplication.  This is simply because batch scripts don’t have a modulus operator.  For the mathematically curious, this works because we’re using integer arithmetic.  For example, in a batch script, 2003 ÷ 4 = 500.  As you can see, there is no remainder in the result.  Furthermore, there is no rounding.  This means that a ÷ b * b will only equal a when a is evenly divisible by b, or, a mod b = 0.

And there you have it, more than you probably wanted to know about leap years.