• 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

4x4 to 3x3+vec3 matrix conversion world/view/proj

4 posts in this topic

I heard that an OpenGL projection matrix needs all 4x4 cells to store the values. An API I am using has 3x3 + vec3 representation of the projection matrix. I am just wondering how I am able to convert my 4x4 matrix to the API's format and back. This API is fully closed source so I have no idea what is going on in the background. I managed to convert the world matrix correctly but having no luck with the view/proj matrices as they produce incorrect visual results.

This is what I have so far:

CIwFMat ConvertToMarmaladeFormat(Matrix4& Mat)
CIwFMat M;
M.m[0][0] = Mat[0][0];
M.m[0][1] = Mat[0][1];
M.m[0][2] = Mat[0][2];
M.m[1][0] = Mat[1][0];
M.m[1][1] = Mat[1][1];
M.m[1][2] = Mat[1][2];
M.m[2][0] = Mat[2][0];
M.m[2][1] = Mat[2][1];
M.m[2][2] = Mat[2][2];
M.t = CIwFVec3(Mat[3][0], Mat[3][1], Mat[3][2]);
return M;

Matrix4 ConvertFromMarmaladeFormat(CIwFMat& M)
Matrix4 Mat;
Mat[0][0] = M.m[0][0];
Mat[0][1] = M.m[0][1];
Mat[0][2] = M.m[0][2];
Mat[1][0] = M.m[1][0];
Mat[1][1] = M.m[1][1];
Mat[1][2] = M.m[1][2];
Mat[2][0] = M.m[2][0];
Mat[2][1] = M.m[2][1];
Mat[2][2] = M.m[2][2];
Mat[3][0] = M.t.x;
Mat[3][1] = M.t.y;
Mat[3][2] = M.t.z;
return Mat;

class Matrix4
friend Vector4 operator*(const Vector4 &lhs, const Matrix4 &rhs);
friend Vector3 operator*(const Vector3 &lhs, const Matrix4 &rhs);
friend Matrix4 operator*(float scalar, const Matrix4 &rhs);
static const Matrix4 IDENTITY;
static Matrix4 createFromAxes(const Vector3 &x, const Vector3 &y, const Vector3 &z);
static Matrix4 createFromAxesTransposed(const Vector3 &x, const Vector3 &y, const Vector3 &z);
static Matrix4 createFromHeadPitchRoll(float headDegrees, float pitchDegrees, float rollDegrees);
static Matrix4 createMirror(const Vector3 &planeNormal, const Vector3 &pointOnPlane);
static Matrix4 createOrient(const Vector3 &from, const Vector3 &to);
static Matrix4 createRotate(const Vector3 &axis, float degrees);
static Matrix4 createScale(float sx, float sy, float sz);
static Matrix4 createTranslate(float tx, float ty, float tz);
Matrix4() {}
Matrix4(float m11, float m12, float m13, float m14,
float m21, float m22, float m23, float m24,
float m31, float m32, float m33, float m34,
float m41, float m42, float m43, float m44);
~Matrix4() {}
float *operator[](int row);
const float *operator[](int row) const;
bool operator==(const Matrix4 &rhs) const;
bool operator!=(const Matrix4 &rhs) const;
Matrix4 &operator+=(const Matrix4 &rhs);
Matrix4 &operator-=(const Matrix4 &rhs);
Matrix4 &operator*=(const Matrix4 &rhs);
Matrix4 &operator*=(float scalar);
Matrix4 &operator/=(float scalar);
Matrix4 operator+(const Matrix4 &rhs) const;
Matrix4 operator-(const Matrix4 &rhs) const;
Matrix4 operator*(const Matrix4 &rhs) const;
Matrix4 operator*(float scalar) const;
Matrix4 operator/(float scalar) const;
float determinant() const;
void fromAxes(const Vector3 &x, const Vector3 &y, const Vector3 &z);
void fromAxesTransposed(const Vector3 &x, const Vector3 &y, const Vector3 &z);
void fromHeadPitchRoll(float headDegrees, float pitchDegrees, float rollDegrees);
void identity();
Matrix4 inverse() const;
void orient(const Vector3 &from, const Vector3 &to);
void rotate(const Vector3 &axis, float degrees);
void scale(float sx, float sy, float sz);
void toAxes(Vector3 &x, Vector3 &y, Vector3 &z) const;
void toAxesTransposed(Vector3 &x, Vector3 &y, Vector3 &z) const;
void toHeadPitchRoll(float &headDegrees, float &pitchDegrees, float &rollDegrees) const;
void translate(float tx, float ty, float tz);
Matrix4 transpose() const;
float mtx[4][4];

class CIwFMat
* 3x3 rotation matrix.
float m[3][3];
* Trans vector.
CIwFVec3 t;

Share this post

Link to post
Share on other sites
OpenGL uses 4x4 matrices for affine transformations, which are forced to have a last column (or row, depending on convention) identically (0 0 0 1). The last row indicates the translation and the remaining 3x3 matrix represents an endomorphism of the vector space. If the words I am using don't make sense, don't worry about it: I just mean that it makes sense to represent that as a 3x3 matrix and a vector. But projection matrices are different, and you may have to find out from the documentation of the API exactly what they use, and then construct the matrix appropriately.

Share this post

Link to post
Share on other sites
Thanks for the information. There is nothing in the documentation specific to projection matrices and there is no 4x4 class in that API at all. Is there any suggestion you can give me to try and match my matrices given my situation? I have been stuck on this problem for about a week and ran out of ideas. Edited by wildboar

Share this post

Link to post
Share on other sites
There are many combinations with a 3x3 matrix and vec3 that will yield a projection matrix, so I'm just guessing here.
It's a long shot, but why won't you give it a try. You initialize your matrix to identity before putting stuff into it. Still do that, but also put zero into [3][3] and put -1 into [2][3] (if -1 doesn't work, try 1). Edited by max343

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