Today: Moving Around! First note: We need to maintain a position for the player This is a reasonable use for a global variable Counter-argument: What about multiplayer? In that case, a global list of player locations or something One student did make a network multiplayer version of the engine last time! Simple position method with x, y, and z for the player We can now move the player back and forth in a cyclic manner... Controls: Discussion of typical FPS controls Cross-platform Why not just use cin or getchar or whatever? Blocking: We'd have to do it in a separate thread We want button holding to work normal We could check each key, but that would be inefficient glfwSetKeyCallback glfwGetCursorPos and glfwSetCursorPos What does "forward" mean anyway? Besides position, we need to know what direction we're facing! heading Also, are we looking up or down? elevation Up and down are special, because we're not scuba diving or in space Calculating a lookat point: We'll make a unit circle around us Remember the unit circle? sin and cosine, and law of sines Alternative explanation: Polar to rectangular coordinates atan2 vs. regular atan Extending this into a unit sphere: Basically, we'll do the same thing for elevation Scale x and y by the distance along the ground Maximum elevation: Straight up is about enough Don't let the player flip their head upside down It's super confusing when that happens Jumping! It might be nice if we had a floor, but it's not essential Keep track of up/down velocity For now, I'll leave double jumping For now, physics and rendering can hang out together in the main loop We'll want to separate these, so that framerate and movement will be independent It'll also allow us to engage two CPU cores If we get all that working, I'll be surprised Strange things happen... So let's use instanced rendering to make a bunch of our loaded model With different colors even (based on gl_InstanceID) Lab: Sort of depends where we end up! Dual object loader: Load two objects instead of one. Mostly duplication Counter-rotation: Draw two of the same object, but rotate them in different directions A platform: if over platform, floor height is higher Have to draw the platform too