# Daid

Member

10

4 Neutral

• Rank
Member

• Interests
Programming

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

1. ## Spaceship controls -> autopilot

My quaternion code is here: https://github.com/daid/SeriousProton2/blob/master/include/sp2/math/quaternion.h Vector3 is also there. Note that my "toAxisAngle()" function multiplies the axis (which is a normalized vector) with the angle (which is the amount of rotation) which is why it can only return a Vector3 instead of returning a Vector3 and a scalar (double) for a proper axis+angle. My X+ is "forwards" and "Z+" is up. Not sure how much that matters. Simplified code is then: Vector3d target_position = ???; Quaterniond target_rotation = Quaterniond::fromVectorToVector(Vector3d(1, 0, 0), target_position); Vector3d rotation_required = getRotation3D().diff(target_rotation).toAxisAngle(); double roll = rotation_required.x; double pitch = rotation_required.y; double yaw = rotation_required.z; I limit the roll/pitch/yaw each update, and recalculate the "rotation_required" each update. Due to some damping and acceleration I get a bit of overshoot. But that's due to other things my code is doing as well, I think the math here is sound otherwise.
2. ## Spaceship controls -> autopilot

Funny. I solved this yesterday. First, you need a target rotation as quadernion. Then you can calculate the diff quaternion between your current rotation and target rotation. Finally you can decompose that diff into a axis+angle. Which you can use for pitch/yaw/roll On my phone right now, can post some code later. Pm me if i forget.
3. ## Keyboard abstraction

Oh, and I checked your code, you seem to use "GetAsyncKeyState" for windows at least, I guess something along the same lines in linux. I've had players manage to press&release a key between 2 frame calls with that kind of setup. So I would recommend against it for things like quick arcade like games. As people get pretty annoyed when they press the jump key and nothing happens.
4. ## Keyboard abstraction

Well, depending on your goal, your solution is fine. SFML uses the same kind of API: https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Keyboard.php But SDL2 has a much more complex keyboard API: https://wiki.libsdl.org/CategoryKeyboard I have found some issues with the "simple" SFML and your proposed way. Which is most likely also why the SDL2 API is much more complex. In general, there are 3 different types of keyboard input: Pressing a specific physical key on the keyboard for an action (Use WASD keys for movement, independed of keyboard layout) Pressing a specific named key on the keyboard for an action (Press "A" to continue, where A is located depends on keyboard layout config) Typing text, coverting key presses into specific text entry actions. Pressing shift gives nothing, while shift+A is an upper case A. Generally this is more event based. For my home grown game engine, I've build an abstraction called "KeyBinding", which solves a few different things as well, like: Multiple keys bound to the same action Checking if the key was pressed/released this frame/update cycle Assigning joysticks axis to keybinding as well Saving/loading keybindings to a file https://github.com/daid/SeriousProton2/blob/master/include/sp2/io/keybinding.h So consider what level of abstraction you are providing, and what your end goal is. Also consider whether you want keys to be pressed if your application has focus or not. Big surprised if you alt-tab to a browser and the game keeps reading your input.
5. ## Self managed object, bad practice in C++?

I use the pattern of "self management" quite often. However, as you noticed yourself you need to ensure things like a keyframe being only assigned to a single track. So you would need to put the whole management in the keyframe them, both adding and removing. (IMHO, it doesn't make sense for keyframe on a time track objects) For my home-grown game engine, I've made this into a general solution. Where you can have sort of "smart pointers" to objects that get set to NULL when you delete the object. Or lists of these objects where the entry in the list gets removed when you delete the object. https://github.com/daid/SeriousProton2/blob/master/include/sp2/pointer.h My primary example of why this is useful is when you have objects in a game, for example a lot of enemies, and all those enemies have a target. And that target can be deleted. Now, knowing as a targeted object that you can be targeted to clean up those specific pointers is quite error prone. Next to that, I make a lot of use of the std::shared_ptr<> which is extremely useful if you just want the object to be destroyed once nobody references it any more. But it the end, for keyframes, I would manage them for a full 100% from the track.
6. ## Did I really remake Minecraft?

Those are the exceptions, not the general rule. As an investment, game development is pretty high risk. And for the casual observer, your screenshots look exactly like minecraft. As investors have to shift to a lot of proposals, they need to be impressed quickly. Not be reminded of something that exists already. And there is the risk that you used copyrighted materials, which is the most likely reason for the rejection. For the non-casual observer, I see things that look like a copy-cat of minecraft, and some enhancements on the concept. But nothing that screams to me.
7. ## Depth Range

That happens indeed, it happens by the projection matrix. The projection matrix transforms 3D positions into 2D screen position from -1 to 1, and a depth position from 0 to 1 See: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#the-projection-matrix
8. ## Designing Good C++ Game Middleware

So you have your own implementation of worker threads, which is exactly the point. As you now might have multiple thread pools with workers, and that can have more threads active at once then you would want, hurting performance. Immagine having a few of those libraries that think it's fine have their own internal threadpool, and you have a bunch of threadpools and no control left. I would recommend having the option to provide a custom threadpool/job-queue and provide a default implementation as well for people that don't want to hook it into anything else.
9. ## Designing Good C++ Game Middleware

Note that SFML is an open source library, and they have this issue ;-) I do have to say that your article is kinda limited to "the exact scope of your project". Even if it hits quite a few valid points. Also, about const, adding "const" can be important for other reasons then just API. It also impacts performance (as a result from a const function can be re-used by the compiler in certain cases). And occasionally what you are allowed to do (if you deal with rvalue temporaries) And also, there is no guarantee that a const does not modify an object, I've seen something along these lines: class A { public: Matrix4 getTransformationMatrix() const { if (matrix_outdated) (const_cast<A*>(this))->updateTransformationMatrix(); return transformation_matrix; } } Where a local cache is updated in a const function. It's const in the fact that it returns the same value every time, but it's not const in that it doesn't modify internal state and thus not thread safe for reading. I would never do this, but I've seen it.
10. ## Designing Good C++ Game Middleware

The core reason I've seen for this is because C++ doesn't have a stable ABI between different compilers. And then you get this mess: https://www.sfml-dev.org/download/sfml/2.5.1/ if you want to provide binaries. With with a C API, the ABI is the same for all compilers, and some other languages can hook directly in it (like python with ctypes)