🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Week 3:

Published October 12, 2014
Advertisement
Hey all,
I was still unpleasantly sick for most of the week (this is like the flu from hell). But, managed to still get quite a bit done, mostly in the bug-fixing-realm.
I fixed many of the things that had been bugging me, though were not huge updates.

First and foremost, I changed the raycasting to "see through" trees, players and objects and correctly click the tile that you want. Previously, my raycasting function used the pixeldepth openGL function, which, when used with glm::unproject() can return the world coordinates of the pixel. However, when selecting players, this isn't ideal for a number of reasons. I'm using billboarded characters with partly transparent images. If you click anywhere near the character, (meaning to click on the tile behind the player, for instance), it would return the incorrect value as the pixeldepth would return the location of the character image.

This meant learning some math (damn it, math!). As a bit of a back story, when I was in college, I tested into Calculus II, skipping trigonometry, calculus I, and algebra. However, to be honest, this had more to do with my standardized test taking abilities, and little to do with my math skills. I had no idea what a cosine was. Needless to say, I drowned in the class (even with a math tutor for a roommate). When I was younger, I always learned how to solve the "problems" of mathematical equations, without really understanding what I was doing. I could extrapolate the correct answer, and learned the methods for doing so, but (probably mostly my fault, but perhaps partly my teacher's fault) I never really learned or understood the applications of what I was doing. They were just fun little numbers games, but it led to me pretty much forgetting the majority of it over the course of time.

Anyhow, apologies for the little story here, but it may help explain my troubles for the week tongue.png So, learning how to solve this raycasting problem meant learning how to calculate the point at which a line intersects a plane. For some of you, I imagine this is trivial, but for me, every tutorial I found assumes I'm caught up to the current level of math required to solve this (which makes sense). So, I more or less had to start a tutorial, and when I got lost, start another tutorial explaining the lower level math (which often required another tutorial explaining that math tongue.png). I know I really ought to just spend a few months learning/relearning the math I'll need for game development, but part of me figures I'll eventually learn it all, if I keep at it as I am. It'll be far more frustrating, and I'm likely to code slower (as I keep having to spend a week teaching myself more math), but I tend to be stubborn, so this is probably the route I'll take tongue.png

Anyhow, the new and improved raycasting function. I'm fairly certain I understand what I'm doing though it's probably not all that elegant, but it works:glm::vec3 XRayCast(glm::vec2 mousePos, glm::mat4 &viewmatrix, glm::mat4 &projmatrix, sf::Vector2f screendimensions, sf::Window &window){ //beware! this function does not account for zero values//// //but it isn't necessary for this function as the camera is at a fixed angle toward the plane, keep in mind if you adjust later//// //variables for raycasting glm::vec3 unprojS;//ray start point glm::vec3 unprojF;//ray end point glm::vec3 pointInPlane(0,-500,0);//point where plane begins glm::vec3 planeNormal(0,1,0);//plane normal (up vector) float t;//variable to solve glm::vec3 intersection;//intersecting point float distanceToOrigin;//used to calculate the end point distanceToOrigin = glm::dot(pointInPlane, planeNormal); //start and end points of ray unprojS = glm::unProject(glm::vec3(mousePos.x, screendimensions.y -mousePos.y, 0), (viewmatrix), projmatrix, glm::vec4(0,0,screendimensions.x, screendimensions.y)); unprojF = glm::unProject(glm::vec3(mousePos.x, screendimensions.y -mousePos.y, 1), (viewmatrix), projmatrix, glm::vec4(0,0,screendimensions.x, screendimensions.y)); //calculate direction glm::vec3 direction = unprojS - unprojF; //calculate intersecting point: t = (distanceToOrigin - glm::dot(unprojS, planeNormal))/glm::dot(direction, planeNormal); intersection = unprojS + t * direction; return intersection;}
With that sorted out, I spent what was left of the week with other minor, if pleasant changes.
-remade mountains to fit to tiles
-made mountains unpassable by players
-made water Minion
-set land minions to not be able to cross water normally
-set water minions to not cross land
-made characters clickable to enable their turn (if it's your side turn and they're your players). This one felt nice to do.
-fixed saving/loading files to account for minions and their respective side
-made trees not spawn in mountains in terrain generation
-made tabbing function to switch between enabled player (ala many RTS games) so you can tab through your available entities when it's your turn.
-tons of little bug fixes

I spent the last couple of days dealing with a segmentation fault. If I added certain things (std::vector of anything, for example, or certain class instances) to my EntityManager class header, it would segfault on startup. In my limited experience, this is usually due to an incorrect pointer somewhere, though I've eschewed pointers for this game (thus far. I'm not entirely opposed to using them, they've just not been necessary yet) and am passing everything by reference where possible, so I was pretty stumped on this. Prior to recent changes, I passed in all the object info for characters (normals vertices, shaders, etc) by reference to the class, but thought it would be cleaner to create them in the class manager, rather than in main. Reverting to the older system seems to get rid of the segfault, but now I'm passing in references to a half dozen parameters for every function in EntityManager(). I tried valgrind and gdb and for the life of me could not pinpoint where I was going wrong.

Anyhow, I don't have a specific list of things to do next week, but I'm fairly certain it's not going to be anything heavily based in math tongue.png
I'll hopefully focus on game mechanics and the UI.

As always, you can browse the code here or download it here.
Here's some screenshots of the new mountains and water demons (the latter are pretty silly looking tongue.png)
Previous Entry Week 2
Next Entry Week 4
3 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Week 4

1911 views

Week 3:

2096 views

Week 2

2398 views
Advertisement