Jump to content
  • Advertisement

Brandon T

Member
  • Content Count

    6
  • Joined

  • Last visited

Everything posted by Brandon T

  1. I have an extremely weird problem. I'm using the function below to render text at a specified position in a window. It works on my ATI cards but does absolutely nothing on Nvidia & Intel cards and I have no clue why. [source lang="cpp"]void glPrint(int X, int Y, const char *Format, ...) { if (!FontsBuilt) BuildFonts(); if (Format == NULL) return; optr_glRasterPos2i(X, Y); char Text[256]; va_list ap; va_start(ap, Format); vsprintf(Text, Format, ap); va_end(ap); optr_glPushMatrix(); optr_glPushAttrib(GL_LIST_BIT); optr_glListBase(Base - 32); optr_glCallLists(strlen(Text), GL_UNSIGNED_BYTE, Text); optr_glPopAttrib(); optr_glPopMatrix(); }[/source] I'm using it like this: [source lang="cpp"]GL_EXTERN BOOL __stdcall GLHook_wglSwapBuffers(HDC hdc) { int i = 50; glPrintf(100, 100, "Testing %i \n", i); return (*optr_wglSwapBuffers) (hdc); }[/source] Any Idea what's wrong with it? If I use GDI's textout/drawtext, it works on nvidia cards but using call lists like above does not work. Any help is appreciated.
  2. =] I injected. Can you tell me if the below is good for drawing text? It works on my ATI cards but not on Intel/NVidia :S I have no clue why.. [source lang="cpp"] void glPrint(int X, int Y, const char *Format, ...) { if (!FontsBuilt) BuildFonts(); if (Format == NULL) return; optr_glRasterPos2i(X, Y); char Text[256]; va_list ap; va_start(ap, Format); vsprintf(Text, Format, ap); va_end(ap); optr_glPushAttrib(GL_LIST_BIT); optr_glListBase(Base - 32); optr_glCallLists(strlen(Text), GL_UNSIGNED_BYTE, Text); optr_glPopAttrib(); }[/source] I solved the VertexBuffer Injection. Now the only thing I have left is learning the camera matrix! ={
  3. I'ved just started OpenGL and decided I'd dive right into hooking games and seeing if I can edit them and how they work. That's how I learn. So I've created an OpenGL wrapper of all functions including the extended ARB ones. I've used gDebugger and GLintercept to help figure out what extendeds are called. I do not want to use glut. Anyway here's my questions: 1. Is there anyway for me to access the vertex buffers? I noticed gDebugger can somehow tell me exactly what the VBO's hold and I want to do this. 2. What are the 4 last rows in the modelview matrices for? I've read endless tutorials but not a single one tells me what it's for. The game I'm hooking uses matrices that look like this: [source lang="cpp"]GL_VIEWPORT: {4, 165, 512, 334} GL_MODELVIEW_MATRIX: {0.99975264 , 0.0091297952, -0.020280767, 0} {0 , 0.91186345 , 0.41049367 , 0} {0.022241013 , -0.41039214 , 0.9116379 , 0} {1819.2891 , -308.66016 , 5129.084 , 1} //These rows.. GL_PROJECTION_MATRIX: {1.40625, -0, 0, 0} {0, -2.1556885, 0, 0} {0, -0, 1.0273149, 1} {0, -0, -405.46298, 0} //And these ones.. GL_CURRENT_MATRIX_ARB: {0.99975264 , 0.0091297952, -0.020280767, 0} {0 , 0.91186345 , 0.41049367 , 0} {0.022241013 , -0.41039214 , 0.9116379 , 0} {1819.2891 , -308.66016 , 5129.084 , 1}[/source] AND gDebugger shows: [source lang="cpp"]glMultMatrixf([0.024158,-0.893824,0.447767,0.000000,0.000000,0.447898,0.894085,0.000000,-0.999708,-0.021599,0.010820,0.000000,25715.173828,26396.923828,-5469.418945,1.000000] ); [/source] 3. Finally, is there a way I can grab the camera position? I've noticed that GLIntercept can use freecam. How does it know what the current camera position & Look-At is inorder to let you move it? This is what I have so far (I'm not sure how efficient or good my code is, but it's a good start I think?): [source lang="cpp"]#include "RSHooks.hpp" GLdouble CalculateAngle(GLdouble Size, GLdouble Distance) { GLdouble Rad = 2.0 * atan2(Size / 2.0, Distance); return (180.0 * Rad) / 3.1415926535; } void PointOfView(GLdouble ObjectX, GLdouble ObjectY, GLdouble ObjectZ, GLdouble Roll, GLdouble Pitch, GLdouble Heading) { optr_glRotated(Roll, 0.0, 0.0, 1.0); optr_glRotated(Pitch, 0.0, 1.0, 0.0); optr_glRotated(Heading, 1.0, 0.0, 0.0); optr_glTranslated(-ObjectX, -ObjectY, -ObjectZ); } void PolarView(GLdouble Distance, GLdouble Twist, GLdouble Elevation, GLdouble Azimuth) { optr_glTranslated(0.0, 0.0, -Distance); optr_glRotated(-Twist, 0.0, 0.0, 1.0); optr_glRotated(-Elevation, 1.0, 0.0, 0.0); optr_glRotated(Azimuth, 0.0, 0.0, 1.0); } GLboolean WorldToScreen(GLfloat &X, GLfloat &Y, Vector3D World) { GLint ViewPort[4]; GLdouble Screen[3]; GLdouble ModelViewMatrix[16]; GLdouble ProjectionMatrix[16]; glGetIntegerv(GL_VIEWPORT, ViewPort); glGetDoublev(GL_MODELVIEW_MATRIX, ModelViewMatrix); glGetDoublev(GL_PROJECTION_MATRIX, ProjectionMatrix); if(gluProject(World.X, World.Y, World.Z, ModelViewMatrix, ProjectionMatrix, ViewPort, &Screen[0], &Screen[1], &Screen[2]) == GL_TRUE) { X = Screen[0]; Y = ViewPort[3] - Screen[1]; return GL_TRUE; } return GL_FALSE; } GLboolean WorldToScreen(GLfloat &X, GLfloat &Y, Vector3D World, GLdouble* ModelViewMatrix, GLdouble* ProjectionMatrix) { GLint ViewPort[4]; GLdouble Screen[3]; glGetIntegerv(GL_VIEWPORT, ViewPort); if(gluProject(World.X, World.Y, World.Z, ModelViewMatrix, ProjectionMatrix, ViewPort, &Screen[0], &Screen[1], &Screen[2]) == GL_TRUE) { X = Screen[0]; Y = ViewPort[3] - Screen[1]; return GL_TRUE; } return GL_FALSE; } GLboolean ScreenToWorld(GLfloat X, GLfloat Y, Vector3D &World) { GLfloat Z = 0; GLint ViewPort[4]; GLdouble Screen[3]; GLdouble ModelViewMatrix[16]; GLdouble ProjectionMatrix[16]; glGetIntegerv(GL_VIEWPORT, ViewPort); glGetDoublev(GL_MODELVIEW_MATRIX, ModelViewMatrix); glGetDoublev(GL_PROJECTION_MATRIX, ProjectionMatrix); optr_glReadPixels(X, ViewPort[3] - Y - 1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Z); if (gluUnProject(X, ViewPort[3] - Y - 1, Z, ModelViewMatrix, ProjectionMatrix, ViewPort, &Screen[0], &Screen[1], &Screen[3]) == GL_TRUE) { World.X = Screen[0]; World.Y = Screen[1]; World.Z = Screen[2]; return GL_TRUE; } return GL_FALSE; } GLboolean ScreenToWorld(GLfloat X, GLfloat Y, Vector3D &World, GLdouble* ModelViewMatrix, GLdouble* ProjectionMatrix) { GLfloat Z = 0; GLint ViewPort[4]; GLdouble Screen[3]; glGetIntegerv(GL_VIEWPORT, ViewPort); optr_glReadPixels(X, ViewPort[3] - Y - 1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Z); if (gluUnProject(X, ViewPort[3] - Y - 1, Z, ModelViewMatrix, ProjectionMatrix, ViewPort, &Screen[0], &Screen[1], &Screen[3]) == GL_TRUE) { World.X = Screen[0]; World.Y = Screen[1]; World.Z = Screen[2]; return GL_TRUE; } return GL_FALSE; } GL_EXPORT __stdcall void GLHook_glBindBufferARB(GLenum target, GLuint buffer) { BufferBound = true; CurrentBuffer.Type = target; CurrentBuffer.ID = buffer; (*optr_glBindBufferARB) (target, buffer); } GL_EXPORT __stdcall void GLHook_glBindTexture(GLenum target, GLuint texture) { if (LogCalls) glLogCalls("glBindTexture: %d, %d\n", target, texture); if (target == GL_TEXTURE_RECTANGLE) //GL_TEXTURE_2D { TextureFound = texture; PI.TID = texture; (*optr_glBindTexture) (target, texture); PI.ID = GLHook_PanelItemCheckSum(target, 32); return; } (*optr_glBindTexture) (target, texture); } GL_EXPORT __stdcall void GLHook_glBufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) { if (BufferBound && CurrentBuffer.Type == target && target == GL_ARRAY_BUFFER) { BufferBound = false; CurrentBuffer.Size = size; CurrentBuffer.Usage = usage; ListOfBuffers.push_back(CurrentBuffer); } (*optr_glBufferDataARB) (target, size, data, usage); } GL_EXPORT __stdcall void GLHook_glBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) { (*optr_glBufferSubDataARB) (target, offset, size, data); } GL_EXPORT __stdcall void GLHook_glCallList(GLuint list) { for (std::vector<FontChar>::iterator it = ListOfFonts.begin(); it != ListOfFonts.end(); ++it) { if (it->ID == list) { CurrentFontData.ID = it->ID; for (int I = 0; I < 4; I++) { CurrentFontData.Quad.VX = it->Quad.VX; CurrentFontData.Quad.VY = it->Quad.VY; CurrentFontData.Quad.TX = it->Quad.TX; CurrentFontData.Quad.TY = it->Quad.TY; } CurrentFontData.Symbol = (it->Symbol - 32); FontData.push_back(CurrentFontData); break; } } (*optr_glCallList) (list); } GL_EXPORT __stdcall void GLHook_glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) { if (!red && !green && !blue) { CurrentFontData.Shadow = GL_TRUE; CurrentFontData.Rendering = GL_FALSE; } else { CurrentFontData.Shadow = GL_FALSE; CurrentFontData.Rendering = GL_TRUE; } CurrentFontData.Colour = {red, green, blue, alpha}; (*optr_glColor4ub) (red, green, blue, alpha); } GL_EXPORT __stdcall void GLHook_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { if (LogCalls) glLogCalls("glDrawElements: %d, %i, %d, %i\n", mode, count, type, indices); if (ModelRendering) { Model* ModelPtr = &ListOfModels.back(); ModelPtr->ID = 0; ModelPtr->TriangleCount = count / 3; if (!ModelPtr->NullVertex) { const GLfloat* Pointer = static_cast<const GLfloat*>(ModelPtr->VertexPointer); //Can be used to iterate each vertex.. ModelPtr->X = *Pointer + ModelPtr->Stride; ModelPtr->Y = *Pointer + ModelPtr->Stride + sizeof(GLfloat); ModelPtr->Z = *Pointer + ModelPtr->Stride + (2 * sizeof(GLfloat)); } if ((ModelPtr->Stride == Stride) && Overlay) optr_glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else optr_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } else optr_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); (*optr_glDrawElements) (mode, count, type, indices); } GL_EXPORT __stdcall void GLHook_glEnd(void) { if (CompassFound) { CompassFound = false; CompassAngle.Compass.VertexCount = 0; } if (TextureFound) { if (PI.CoordCount == 4) { AreaFilter = {PI.TID, 550, 260, 740, 518}; CurrentItem.ID = PI.ID; CurrentItem.X = PI.SX[0]; CurrentItem.Y = PI.SY[0]; CurrentItem.TextureID = PI.TID; for (int I = 0; I < 4; I++) { CurrentItem.SX = PI.SX; } ListOfItems.push_back(CurrentItem); } PI.CoordCount = 0; TextureFound = false; } (*optr_glEnd) (); } GL_EXPORT __stdcall void GLHook_glEndList(void) { if (FontFound) { CurrentFont.VCount = 0; CurrentFont.TCount = 0; CurrentFont.LastFont = false; if (!ListOfFonts.size()) CurrentFont.Symbol = 32; else CurrentFont.Symbol = (!ListOfFonts.back().LastFont) ? ListOfFonts.back().Symbol + 1 : 32; if (++FontListCount >= 255) { CurrentFont.LastFont = true; FontListCount = 0; FontFound = false; } ListOfFonts.push_back(CurrentFont); } (*optr_glEndList) (); } GL_EXPORT __stdcall void GLHook_glGenBuffersARB(GLsizei n, GLuint *buffers) { (*optr_glGenBuffersARB) (n, buffers); } GL_EXPORT __stdcall GLuint GLHook_glGenLists(GLsizei range) { if (range == 256) { FontListCount = 0; FontFound = true; } return (*optr_glGenLists) (range); } GL_EXPORT __stdcall void GLHook_glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t) { if (target == GL_TEXTURE0 && (s == 51 || t == 51)) { CompassFound = true; CompassAngle.Compass.Found = true; } (*optr_glMultiTexCoord2fARB) (target, s, t); } GL_EXPORT __stdcall void GLHook_glNewList(GLuint list, GLenum mode) { if (FontFound) { CurrentFont.ID = list; } (*optr_glNewList) (list, mode); } GL_EXPORT __stdcall void GLHook_glPopMatrix(void) { if (ModelRendering) { GLfloat X = 0, Y = 0; Model* ModelPtr = &ListOfModels.back(); Vector3D World = Vector3D(ModelPtr->X, ModelPtr->Y, ModelPtr->Z); if (WorldToScreen(X, Y, World)) { ModelPtr->SX = X; ModelPtr->SY = Y; } } ModelRendering = false; (*optr_glPopMatrix) (); } GL_EXPORT __stdcall void GLHook_glTexCoord2f(GLfloat s, GLfloat t) { if (FontFound) { int I = ++CurrentFont.TCount; if (I < 5) { CurrentFont.Quad.TX[I - 1] = s; CurrentFont.Quad.TY[I - 1] = t; } } (*optr_glTexCoord2f) (s, t); } GL_EXPORT __stdcall void GLHook_glTranslatef(GLfloat x, GLfloat y, GLfloat z) { CurrentFontData.Translate[0] = x; CurrentFontData.Translate[1] = y; CurrentFontData.Translate[2] = z; (*optr_glTranslatef) (x, y, z); } GL_EXPORT __stdcall void GLHook_glVertex2f(GLfloat x, GLfloat y) { if (CompassFound) { int I = ++CompassAngle.Compass.VertexCount; if (I < 5) { CompassAngle.Compass.VX[I - 1] = x; CompassAngle.Compass.VY[I - 1] = y; } } (*optr_glVertex2f) (x, y); } GL_EXPORT __stdcall void GLHook_glVertex2i(GLint x, GLint y) { if (LogCalls) glLogCalls("glVertex2i: %i, %i\n", x, y); if (TextureFound) { int I = ++PI.CoordCount; if (I < 5) { PI.SX[I - 1] = x; PI.SY[I - 1] = y; } } if (FontFound) { int I = ++CurrentFont.VCount; if (I < 5) { CurrentFont.Quad.VX[I - 1] = x; CurrentFont.Quad.VY[I - 1] = y; } } (*optr_glVertex2i) (x, y); } GL_EXPORT __stdcall void GLHook_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { if (LogCalls) glLogCalls("glVertexPointer: %i, %d, %i, %i\n", size, type, stride, pointer); ModelRendering = true; CurrentModel.Stride = stride; CurrentModel.NullVertex = (pointer == NULL); CurrentModel.VertexPointer = pointer; //Store Our Pointer for later calculations. ListOfModels.push_back(CurrentModel); (*optr_glVertexPointer) (size, type, stride, pointer); } GL_EXPORT __stdcall PROC GLHook_wglGetProcAddress(LPCSTR lpszProc) { std::string FunctionCalled(lpszProc); if (FunctionCalled == "glBindBufferARB") { optr_glBindBufferARB = (ptr_glBindBufferARB) optr_wglGetProcAddress(lpszProc); return (FARPROC) GLHook_glBindBufferARB; } else if (FunctionCalled == "glBufferDataARB") { optr_glBufferDataARB = (ptr_glBufferDataARB) optr_wglGetProcAddress(lpszProc); return (FARPROC) GLHook_glBufferDataARB; } else if (FunctionCalled == "glBufferSubDataARB") { optr_glBufferSubDataARB = (ptr_glBufferSubDataARB) optr_wglGetProcAddress(lpszProc); return (FARPROC) GLHook_glBufferSubDataARB; } else if (FunctionCalled == "glMultiTexCoord2fARB") { optr_glMultiTexCoord2fARB = (ptr_glMultiTexCoord2fARB) optr_wglGetProcAddress(lpszProc); return (FARPROC) GLHook_glMultiTexCoord2fARB; } return (*optr_wglGetProcAddress) (lpszProc); } GL_EXPORT __stdcall BOOL GLHook_wglSwapBuffers(HDC hdc) { Commands(); if (LogCalls) glLogCalls("wglSwapBuffers"); if (Overlay) { glColor4f(0.0f, 1.0f, 1.0f, 1.0f); for (std::vector<PanelItem>::iterator it = ListOfItems.begin(); it != ListOfItems.end(); ++it) { if (it->X > AreaFilter.X1 && it->Y > AreaFilter.Y1 && it->X < AreaFilter.X2 && it->Y < AreaFilter.Y2) { glPrint(it->X, it->Y + 18, "%i", it->ID); } } for (std::vector<Model>::iterator it = ListOfModels.begin(); it != ListOfModels.end(); ++it) { if ((Overlay && (it->Stride == Stride)) || (Overlay && DrawAllStrides)) { glPrint(it->SX, it->SY + 224, "%i", it->ID); } } for (std::vector<FontInfo>::iterator it = FontData.begin(); it != FontData.end(); ++it) { if (it->Colour.R != 0 && it->Colour.G != 0 && it->Colour.B != 0) //Remove this later.. Just for testing. { glPrint(it->Translate[0] + it->Quad.VX[1], it->Translate[1] + it->Quad.VY[1], "%c", it->Symbol); } } if (CompassAngle.Compass.Found) { CompassAngle.Compass.RadianAngle = 0; CompassAngle.Compass.DegreeAngle = 0; if (CompassAngle.Compass.VX[3] - CompassAngle.Compass.VX[0]) { CompassAngle.Compass.RadianAngle = atan2f(CompassAngle.Compass.VY[3] - CompassAngle.Compass.VY[0], CompassAngle.Compass.VX[3] - CompassAngle.Compass.VX[0]); CompassAngle.Compass.RadianAngle += CompassAngle.Compass.RadianAngle < 1 ? (2 * 3.1415926535) : 0; //A bit buggy. Degress is more accurate. CompassAngle.Compass.DegreeAngle = (CompassAngle.Compass.RadianAngle * (180 / 3.1415926535)); } glPrint(518, 48, "Deg: %f", CompassAngle.Compass.DegreeAngle); glPrint(518, 58, "Rad: %f", CompassAngle.Compass.RadianAngle); } } FontData.clear(); ListOfItems.clear(); ListOfModels.clear(); CompassAngle.Compass.Found = false; return (*optr_wglSwapBuffers) (hdc); } [/source]
  4. No. I assume that you are manipulated a game by using those 2 applications? That is actually in my opinion the worst way to learn opengl. Start from the ground up because most of the things you are asking are completely random in order. Learn things step by step instead of just "what happens if I change this number". A book should help you to tell you what those numbers are and how to use them. [/quote] I'm using the two applications to get debugging information so I can use it to manipulate the game. I've learned the basics I think? That's how I was able to write the application above. I just have a hard time understanding the matrices and how to GET them from the game itself (Not GetFloatv(GLModelView_Matrix, &MV[0])). I meant like getting a camera position from an application that isn't mine. Same with VertexBuffers. I know how to do it if it was my own application (Just store it at the beginning and transform it whenever). What I do not know is how to do it for other applications. GLIntercept is able to move the game's camera around and I'm trying to achieve the same effect by hooking the game too. gDebugger is able to grab a VBO's data and display it like this (something I'm attempting to do but do not know where to start, I can grab textures.. Just not buffer data):
  5. Ahh well I just tried just now. I struggled badly. I cannot figure out how to get the view matrix. I created a class for both matrices and vectors.. it isn't complete yet but I got stuck trying to figure out what the view matrix is. Or what I should do to get it. I've tried logging glFrustrum but the game doesn't seem to use that at all. I've studied everything you told me and just finished reading up on the modelview matrix. It seems it is a combination of the view matrix and object matrix. Is there no way I can extract it? VECTOR3D: [source lang="cpp"]#include "Vector3D.hpp" Vector3D::~Vector3D() {} Vector3D::Vector3D() : X(0), Y(0), Z(0) {} Vector3D::Vector3D(double x, double y, double z) : X(x), Y(y), Z(z) {} Vector3D& Vector3D::operator ()(double x, double y, double z) { if (X != x && Y != y && Z != z) { X = x; Y = y; Z = z; } return *this; } bool Vector3D::operator == (const Vector3D& V) const { return ((X == V.X) && (Y == V.Y) && (Z == V.Z)); } bool Vector3D::operator != (const Vector3D& V) const { return ((X != V.X) && (Y != V.Y) && (Z != V.Z)); } Vector3D& Vector3D::operator = (const Vector3D& V) { if (this != &V) { X = V.X; Y = V.Y; Z = V.Z; } return *this; } Vector3D& Vector3D::operator += (const int& W) { if (W > 0) { X += W; Y += W; Z += W; } return *this; } Vector3D& Vector3D::operator += (const Vector3D& V) { X += V.X; Y += V.Y; Z += V.Z; return *this; } Vector3D& Vector3D::operator -= (const int& W) { X -= W; Y -= W; Z -= W; return *this; } Vector3D& Vector3D::operator -= (const Vector3D& V) { X -= V.X; Y -= V.Y; Z -= V.Z; return *this; } Vector3D& Vector3D::operator *= (const int& W) { X *= W; Y *= W; Z *= W; return *this; } double Vector3D::operator *= (const Vector3D& V) { return ((X * V.X) + (Y * V.Y) + (Z * V.Z)); } Vector3D& Vector3D::operator /= (const int& W) { if (W != 0) { X /= W; Y /= W; Z /= W; } return *this; } Vector3D& Vector3D::operator ^= (const Vector3D& V) { X = (Y * V.Z) - (Z * V.Y); Y = (Z * V.X) - (X * V.Z); Z = (X * V.Y) - (Y * V.X); return *this; } double Vector3D::Dot(const Vector3D& V) { return Vector3D(*this) *= V; } Vector3D& Vector3D::Cross(const Vector3D& V) { return Vector3D(*this) ^= V; } double Vector3D::Magnitude() const { return sqrtf((X * X) + (Y * Y) + (Z * Z)); } double Vector3D::AngleRad(const Vector3D& V) { double I = Magnitude(); double J = V.Magnitude(); return (I == 0.0 || J == 0.0) ? 0.0 : acosf(Dot(V) / (I * J)); } double Vector3D::AngleDeg(const Vector3D& V) { return (AngleRad(V) * (180 / 3.14159265)); //PI = 4 * atan(1); } Vector3D& Vector3D::Normalize() { double Size = this->Magnitude(); if (Size != 0) { X /= Size; Y /= Size; Z /= Size; } return *this; } Vector3D& Vector3D::operator + (const int& W) { return Vector3D(*this) += W; } Vector3D& Vector3D::operator + (const Vector3D& V) { return Vector3D(*this) += V; } Vector3D& Vector3D::operator - (const int& W) { return Vector3D(*this) -= W; } Vector3D& Vector3D::operator - (const Vector3D& V) { return Vector3D(*this) -= V; } Vector3D& Vector3D::operator * (const int& W) { return Vector3D(*this) *= W; } double Vector3D::operator * (const Vector3D& V) { return (*this *= V); } Vector3D& Vector3D::operator ^ (const Vector3D& V) { return Vector3D(*this) ^= V; } Vector3D& Vector3D::operator / (const int& W) { return Vector3D(*this) /= W; } [/source] Matrices: [source lang="cpp"]#include "Matrix.hpp" Matrix::~Matrix(){} Matrix::Matrix(uint32_t Rows, uint32_t Columns) : Data(0) { Data.resize(Rows); for (std::vector<std::vector<double>>::iterator it = Data.begin(); it != Data.end(); ++it) it->resize(Columns); } Matrix& Matrix::operator ()(uint32_t Rows, uint32_t Columns) { Data.resize(Rows); for (std::vector<std::vector<double>>::iterator it = Data.begin(); it != Data.end(); ++it) it->resize(Columns); return *this; } Matrix::Dimensional Matrix::operator [](size_t I) { return Dimensional(*this, I); } bool Matrix::operator == (const Matrix& M) const { if (M.Data.size() == Data.size()) { for (size_t I = 0; I < Data.size(); I++) { for (size_t J = 0; J < Data.size(); J++) { if (Data[J] != M.Data[J]) return false; } } } return true; } bool Matrix::operator != (const Matrix& M) const { return !(*this == M); } Matrix& Matrix::operator = (const Matrix& M) { Data = M.Data; return *this; } Matrix& Matrix::operator += (const Matrix& M) { if (Data.size() == M.Data.size()) { for (size_t I = 0; I < Data.size(); I++) { for (size_t J = 0; J < Data.size(); J++) { Data[J] += M.Data[J]; } } } return *this; } Matrix& Matrix::operator -= (const Matrix& M) { if (Data.size() == M.Data.size()) { for (size_t I = 0; I < Data.size(); I++) { for (size_t J = 0; J < Data.size(); J++) { Data[J] -= M.Data[J]; } } } return *this; } Matrix& Matrix::operator *= (const int& I) { for (std::vector<std::vector<double>>::iterator Rows = Data.begin(); Rows != Data.end(); ++Rows) { for (std::vector<double>::iterator Columns = Rows->begin(); Columns != Rows->end(); ++Columns) { *Columns *= I; } } return *this; } Matrix& Matrix::operator *= (const Matrix& M) { //Matrix Product = Matrix(Data.size(), M.Data[0].size()); if (Data.size() == M.Data[0].size()) { for (size_t I = 0; I < Data.size(); I++) { for (size_t J = 0; J < M.Data[0].size(); J++) { double SumElements = 0.0; for (size_t K = 0; K < Data.size(); K++) { SumElements += Data[K] * M.Data[K][J]; } Data[J] = SumElements; } } } return *this; } Matrix& Matrix::operator + (const Matrix& M) { return Matrix(*this) += M; } Matrix& Matrix::operator - (const Matrix& M) { return Matrix(*this) -= M; } Matrix& Matrix::operator * (const int& I) { return Matrix(*this) *= I; } Matrix& Matrix::operator * (const Matrix& M) { return Matrix(*this) *= M; } [/source]
  6. Ohhh I see. Wonder why they'd use Row Major :S. That being said, if I untranslate it somehow (maybe get the first matrix before the multiplication is done), would I get the camera position? What would it give me? I find it odd you mention row major because their default matrix is: [source lang="cpp"][1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1] [0] [0] [0] [0] [1][/source]
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!