• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ryt

Naming conventions for math statements

7 posts in this topic

How do you write variables for math names ?

For vectors for example I sometimes append v like vLocalPosition. But for some common vectors I use names like pos, dir, dist. Also for coords I sometimes use forward, up, right.

For matrices I append m in front or try to use a single uppercase letter like M.

 

How do you write names for transformations and rotations ?

Names like transformAirplane or rotationCar seem a little cumbersome.

0

Share this post


Link to post
Share on other sites

Naming variables depends greatly on who the intended audience is. If you're coding only for yourself, with it being unlikely that others will be viewing and trying to understand your code, name the variable something that will reduce the chance that you'll make an error in your code when you use the variable.

 

That being said, as Alvaro mentions, get in the habit of naming variables appropriately. Long variable names can improve the readability of your code (even to yourself). I understand longer names are a bit of a pain to keep repeating, but many code editors (e.g., Visual Studio) have an auto-completion feature. You need only type the first few letters before the choices narrow greatly. In addition to keeping spellings correct, that auto-completion is scope-based. I.e., if you start to type a variable name that isn't in the current scope of your code, it won't appear in the auto-complete dropdown. You'll have an indication that the variable you want to use will not be found during compilation.

 

In addition to naming variables appropriately, be liberal with comments. I wrote code as part of my job in a previous life and the guidelines included comments comprising no less than half of the total lines in a source file! For esoteric code, the guideline was TWO lines of comments for each line of code. There are times when you will be forever grateful to yourself for describing what the following code is intended to do.

0

Share this post


Link to post
Share on other sites

Documentation of interfaces (how to use some class, perhaps even with examples) is great. But, other than that, I am not a big fan of comments. In some sense, a comment is an admission of defeat: "I didn't manage to make the code clear enough, so here's an explanation".

 

[EDIT: I see how this can quickly become a religious war on all aspects of coding standards, even though it started with a very narrow focus. So perhaps we should not keep going...]

Edited by Álvaro
2

Share this post


Link to post
Share on other sites

Matrices should be named for how they are used e.g. world_to_screen etc. Other abbreviations should be well understood e.g ori (orientation), rot (rotation), trans (translation), etc. Orthogonal matrices should have Right (or Left), Top, Face accessors too.

0

Share this post


Link to post
Share on other sites

I like to distinguish between game code and low level code. In game code I also use longer names like e.g. a descriptive player_position over just 'p'. For my low level collision or physics routines I prefer short names as I derived them on paper. I usually check in theses paper with the code and add a reference in the code. Then those can be used for debugging. E.g. a function to compute the intersection between a ray and a triangle would look like this:

 

float IntersectRayTriangle( Vector A, Vector B, Vector C, Vector P, Vector Q ). 

 

If you need functions that take a triangle or ray structure you just overload the function and delegate to the leaf code function. Personally I found this very convenient to work, but YMMV.

 

As the point came up here I personally recommend against using a special point class. I have to use this lately a lot inside the Maya SDK and find this more confusing than helpful. E.g. you get the translation from a transformation matrix as vector and pass this as position (a point) for e.g. a manipulator you have to convert between types for this. Also the overloading of a multiplication operator between vectors and points which ignores the translation in the first place is very error prone. In this case I prefer explicit functions of the form TransformVector( Matrix m, Vector v ) and TransformPoint( Matrix m, Vector p ). This is my personal preference and it worked well for me, but again YMMV.

 

In general I find most most libraries that are available as open source these days way over-engineered for such a simple problem like a math library. E.g. using templates and extra point classes and what not else. 

Edited by Dirk Gregorius
1

Share this post


Link to post
Share on other sites

As the point came up here I personally recommend against using a special point class. I have to use this lately a lot inside the Maya SDK and find this more confusing than helpful. E.g. you get the translation from a transformation matrix as vector and pass this as position (a point) for e.g. a manipulator you have to convert between types for this. Also the overloading of a multiplication operator between vectors and points which ignores the translation in the first place is very error prone. In this case I prefer explicit functions of the form TransformVector( Matrix m, Vector v ) and TransformPoint( Matrix m, Vector p ). This is my personal preference and it worked well for me, but again YMMV.

 

Really? I found it quite convenient, and the point-vector transformation problem was a non-issue since you are supposed to know what you are doing with your vectors and points (translating a vector is never meaningful, adding two points together either, etc...). The fourth column of a 3x4 (or 4x4) matrix is mathematically a vector, which defines a translation when applied to a point, resulting in another point. To obtain the point corresponding to the origin translated by that vector, you add it to the origin, which is a well-defined conversion, not a ToPoint() kind of deal, even though programmatically it is probably equivalent. No wonder you're having issues if your framework isn't even self-consistent!

 

The alternative of having everything as vectors is of course viable, but at the same time you lose expressiveness because you cannot clearly distinguish between whether a vector is actually a point, except through metadata such as comments and variable names. Though for low-level library code it would probably make sense since that kind of code tends to have this information built into the function contracts and tends to operate blindly on tuples rather than carry out a physically meaningful calculation.

 

Just my opinion, of course, as you said YMMV.

2

Share this post


Link to post
Share on other sites

I like to distinguish between game code and low level code. In game code I also use longer names like e.g. a descriptive player_position over just 'p'. For my low level collision or physics routines I prefer short names as I derived them on paper. I usually check in theses paper with the code and add a reference in the code. Then those can be used for debugging. E.g. a function to compute the intersection between a ray and a triangle would look like this:

 

float IntersectRayTriangle( Vector A, Vector B, Vector C, Vector P, Vector Q ). 

 

I prefer it when the function definition makes better since off the start without having to read a separate document, and then the function can rename the variables in the code (the compiler will clean it up anyway)  So instead of what you have:

float IntersectRayTriangle( Vector rayOrigin, Vector rayDir, Vector triPt0, Vector triPt1, Vector triPt2 )

That way when someone is using your math library and intellisense\VisualAssist\SourceInsight pops up they can easily deduce what the variables are.  And in your code, you can still use the shortened A, B, Cs.

2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0