I didn’t find myself with much free time this week, but I managed to make some progress on this shader business. After hearing our homework questions now have a minimum XP value, it felt like a huge weight was lifted off my shoulders, and I could finally get a goods night sleep. Up to this point, I was scrambling to make some progress on my base code, but just simply couldn’t find the time. I was overwhelmed with work from other classes that had set due dates, and thus took priority. Every night, as I lay in bed I couldn’t help but ponder how far behind I was, and how how hard it would be to catch up. I had a plan, but it wasn’t exactly a good one. I would read up Nvidia’s Cg tutorial online, and jump straight to the hard questions. Theoretically, the plan would work, but skipping over easy and medium questions would mean I would have an no prior experience to simple concepts and struggle with the hard ones. I can’t begin to express how relieved I was to see @syberspaz twitter post. With this good news, and a slightly less crammed week I got to work on my base code.
After some research on 3d model loaders out there, I settled on using Assimp. Assimp stands for open asset import library and is a very popular library simply due to the fact that it supports a wide array of 3D model file types out there. It it very user friendly, and no modifications are required in terms of code to switch between file types. All that needs to be changed is the file path and Assimp takes care of the rest. So I downloaded Assimp and incorporated it into my project. After a few hours of re-organizing the library into its own class, debugging and cleaning up I was now able to load almost any 3D model of my choice.
The next step was to implement a camera system. Using OpenGL’s translate functions to simply translate the scenery by a constant number seemed like a practical way of creating a moving camera that uses the WASD keys, so that’s where I started. Next, I moved onto adding mouse rotations and here’s where everything started going south. The WASD keys did not know about the rotations, and thus after rotating with the mouse they would continue to move along their original axis. After some research and Google searches, I came across some useful code that takes mouse rotations into account when moving linearly across the X and Z axis. Take a look below:
bool* keyStates = new bool[256];
if(keyStates[‘w’] == false)
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad)*3);
zpos -= float(cos(yrotrad)*3);
ypos -= float(sin(xrotrad)*3);
std::cout << “true”;
}
if(keyStates[‘s’] == false)
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos -= float(sin(yrotrad)*3);
zpos += float(cos(yrotrad)*3) ;
ypos += float(sin(xrotrad)*3);
}
if(keyStates[‘d’] == false)
{
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos += float(cos(yrotrad)) * 3;
zpos += float(sin(yrotrad)) * 3;
}
if(keyStates[‘a’] == false)
{
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos -= float(cos(yrotrad)) * 3;
zpos -= float(sin(yrotrad)) * 3;
}
This snippet of code, was a lifesaver as it did exactly what I was looking for and provided me with an FPS style camera. Finally, my base code is complete. Now time to move onto the actual questions Wish me luck.
Until the magical force of the internet unites us once again – Sohale Z.