• Advertisement

michaweyel

Member
  • Content count

    124
  • Joined

  • Last visited

Community Reputation

128 Neutral

About michaweyel

  • Rank
    Member
  1. Well, technically, I think you could take your first non-pointer member struct's memory address along with its size and memcopy it over to the location of the second one every frame. Using pointers is your only other option though, because non-pointer...well, they don't point to an address in memory, they 'are' the address in memory if you will, and hence cannot be made to point to something else instead. But it seems to me as if you should think about redesigning that whole linking thing. In your test programm at least, you are asking for memory leaks. For instance, the memory initially allocated for p by object two will be lost after the call to link(). Any reason why you are using malloc and free instead of new and delete for your point_t members?
  2. Hi all, for learning purposes, i am trying to create my own view and projection matrices using my own vector and matrix classes. I am working on a very basic test programm that simply draws 2 triangles. This seems fine as long as I only transform the vertices using the combined world and view matrix, but as soon as I muplitply my projection matrix on top of that, the triangles disapear. Here's some code. CMatrix4x4<float> matWorld(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,//static_cast<float>(frameCounter)/500.0f, 0.0f, 0.0f, 0.0f, 1.0f); CVector4<float> pos(0.0f, 0.0f, -0.0f, 1.0f); CVector4<float> lookAt(0.0f, 0.0f, -1.0f, 1.0f); CVector4<float> up(0.0f, 1.0f, 0.0f, 1.0f); CMatrix4x4<float> matView = CMatrix4x4<float>::createViewMatrix(pos, lookAt, up); CMatrix4x4<float> matProj = CMatrix4x4<float>::createProjectionMatrix(1.0f, 10.0f, -1.0f, 1.0f, -0.75f, 0.75f); CMatrix4x4<float> mat = multiply(matWorld, matView); mat = multiply(mat, matProj); unsigned int matWVPLoc = glGetUniformLocation(m_glProgram, "worldViewProjectionMatrix"); glUniformMatrix4fv(matWVPLoc, 1, false, &mat); glUseProgram(m_glProgram); glBindVertexArray(m_vaoID[0]); glDrawArrays(GL_TRIANGLES, 0, 3); glBindVertexArray(m_vaoID[1]); glDrawArrays(GL_TRIANGLES, 0, 3); glBindVertexArray(0); SwapBuffers(pDC); and this is my Matrix class template <typename T> class CMatrix4x4 { public: CMatrix4x4(T aa, T ba, T ca, T da, T ab, T bb, T cb, T db, T ac, T bc, T cc, T dc, T ad, T bd, T cd, T dd); CMatrix4x4() {}; virtual ~CMatrix4x4(void) { }; T* operator&() { return m_data; }; T& operator[](int index) { return m_data[index]; }; const T& operator[](int index) const { return m_data[index]; }; static CMatrix4x4<T> multiply(const CMatrix4x4<T> &lhs, const CMatrix4x4<T> &rhs); static CMatrix4x4<T> createViewMatrix(const CVector4<T> &pos, const CVector4<T> &lookAt, const CVector4<T> &up); static CMatrix4x4<T> createProjectionMatrix(const T nearClip, const T farClip, const T left, const T right, const T bottom, const T top); protected: T m_data[16]; }; template <typename T> CMatrix4x4<T>::CMatrix4x4(T aa, T ab, T ac, T ad, T ba, T bb, T bc, T bd, T ca, T cb, T cc, T cd, T da, T db, T dc, T dd) { m_data[0] = aa; m_data[1] = ba; m_data[2] = ca; m_data[3] = da; m_data[4] = ab; m_data[5] = bb; m_data[6] = cb; m_data[7] = db; m_data[8] = ac; m_data[9] = bc; m_data[10] = cc; m_data[11] = dc; m_data[12] = ad; m_data[13] = bd; m_data[14] = cd; m_data[15] = dd; }; template <typename T> CMatrix4x4<T> CMatrix4x4<T>::createViewMatrix(const CVector4<T> &vecPos, const CVector4<T> &vecLookAt, const CVector4<T> &vecUp) { CMatrix4x4<T> ret; CVector4<T> vecDir = vecLookAt - vecPos; CVector4<T> vecRight = vecDir.cross(vecUp); vecRight.normalize(); ret[0] = vecRight[0]; ret[1] = vecRight[1]; ret[2] = vecRight[2]; ret[3] = 0.0; ret[4] = vecUp[0]; ret[5] = vecUp[1]; ret[6] = vecUp[2]; ret[7] = 0.0; ret[8] = vecDir[0]; ret[9] = vecDir[1]; ret[10] = vecDir[2]; ret[11] = 0.0; ret[12] = vecPos[0]; ret[13] = vecPos[1]; ret[14] = vecPos[2]; ret[15] = vecPos[3]; return ret; }; template <typename T> CMatrix4x4<T> CMatrix4x4<T>::createProjectionMatrix(const T nearClip, const T farClip, const T left, const T right, const T bottom, const T top) { CMatrix4x4<T> ret; if(right == -left && top == -bottom) { ret[0] = nearClip / right; ret[1] = 0.0; ret[2] = 0.0; ret[3] = 0.0; ret[4] = 0.0; ret[5] = nearClip / top; ret[6] = 0.0; ret[7] = 0.0; ret[8] = 0.0; ret[9] = 0.0; ret[10] = (-1.0f * (farClip + nearClip)) / (farClip - nearClip); ret[11] = (-2.0f * farClip * nearClip) / (farClip - nearClip); ret[12] = 0.0; ret[13] = 0.0; ret[14] = -1.0; ret[15] = 0.0; } return ret; }; template <typename T> CMatrix4x4<T> multiply(const CMatrix4x4<T> &lhs, const CMatrix4x4<T> &rhs) { CMatrix4x4<T> ret; ret[0] = lhs[0] * rhs[0] + lhs[1] * rhs[4] + lhs[2] * rhs[8] + lhs[3] * rhs[12]; ret[1] = lhs[0] * rhs[1] + lhs[1] * rhs[5] + lhs[2] * rhs[9] + lhs[3] * rhs[13]; ret[2] = lhs[0] * rhs[2] + lhs[1] * rhs[6] + lhs[2] * rhs[10] + lhs[3] * rhs[14]; ret[3] = lhs[0] * rhs[3] + lhs[1] * rhs[7] + lhs[2] * rhs[11] + lhs[3] * rhs[15]; ret[4] = lhs[4] * rhs[0] + lhs[5] * rhs[4] + lhs[6] * rhs[8] + lhs[7] * rhs[12]; ret[5] = lhs[4] * rhs[1] + lhs[5] * rhs[5] + lhs[6] * rhs[9] + lhs[7] * rhs[13]; ret[6] = lhs[4] * rhs[2] + lhs[5] * rhs[6] + lhs[6] * rhs[10] + lhs[7] * rhs[14]; ret[7] = lhs[4] * rhs[3] + lhs[5] * rhs[7] + lhs[6] * rhs[11] + lhs[7] * rhs[15]; ret[8] = lhs[8] * rhs[0] + lhs[9] * rhs[4] + lhs[10] * rhs[8] + lhs[11] * rhs[12]; ret[9] = lhs[8] * rhs[1] + lhs[9] * rhs[5] + lhs[10] * rhs[9] + lhs[11] * rhs[13]; ret[10] = lhs[8] * rhs[2] + lhs[9] * rhs[6] + lhs[10] * rhs[10] + lhs[11] * rhs[14]; ret[11] = lhs[8] * rhs[3] + lhs[9] * rhs[7] + lhs[10] * rhs[11] + lhs[11] * rhs[15]; ret[12] = lhs[12] * rhs[0] + lhs[13] * rhs[4] + lhs[14] * rhs[8] + lhs[15] * rhs[12]; ret[13] = lhs[12] * rhs[1] + lhs[13] * rhs[5] + lhs[14] * rhs[9] + lhs[15] * rhs[13]; ret[14] = lhs[12] * rhs[2] + lhs[13] * rhs[6] + lhs[14] * rhs[10] + lhs[15] * rhs[14]; ret[15] = lhs[12] * rhs[3] + lhs[13] * rhs[7] + lhs[14] * rhs[11] + lhs[15] * rhs[15]; return ret; }; Can anyone spot any obvious errors? In my shader, I just multiply the incoming vertex position by the combined worldviewprojection matrix. Thanks, -Michael
  3. Turning on Unicode in DevC++

    Don't know the anwser to your question, but do you have any particular reasons for why you are using DevC++? [url="http://clicktobegin.net/programming/why-you-shouldnt-use-dev-c/"]Check this out[/url] for why you shouldn't. Microsoft Visual C++ Express, IMHO the best free IDE for Windows out there right now can simply be downloaded from an MSDN website. And since you are on Windows anyway, why not use it?
  4. Static function error

    What this is basically telling you is that the linker couldn't find the implementation of the constructor of your VariableLabel class. Did you also comment out everything in you .cpp file? Also, why did you comment everything out in the first place?
  5. Copying arrays by assignment (C++)

    WEll, yes, it would free the memory that both map and temp_map point to. Nevertheless, like phresnel said, the memory that you accquired with map = new GLubyte[size]; would still be lost since *nothing* points to it anymore, so there is no way of deleting it.
  6. A problem about vector?

    Thats because if you define first and last inside the for statement, the compiler can only 'see' them inside the for loop. When your programm goes out of scope (i.e. leaves the loop), first and last don't exist any more (try searching for "scope c++" on the web for more information.
  7. DirectX 9.0c SDK

    It includes DX9 as well as 10 and 11
  8. DX11 [DX11] How do you intersect meshes?

    Haven't done it myself yet, but since the D3DXMESH interface has been dropped in D3D11, you'll probaly have to implement your own ray-mesh-inttersection test. Try googleing for "ray triangle intersection". And then for larger meshes, you will probably gain a lot of performance by dividing your mesh into chunks of a couple (to hundreds) of triangles each (look for binary space partitioning, see here, for instance: http://en.wikipedia.org/wiki/Binary_space_partitioning), enclose these chunks with a simple approximation (Bounding Box or Sphere) and test your ray against these approximations first. By doing so you can save a lot of ray-tri-tests by discarding whole chunks when their approximation is not hit by the ray.
  9. Setting up Lesson 1

    Nope. In the row "Additional Library Directories", you specify the directories where the linker is to look for .lib files. The files themselves (so OpenGl32.lib, Glu.lib, GLaux.lib) you need to add to "Additional dependencies" under Linker->Input in the project properties
  10. Setting up Lesson 1

    Right-click the project in the solution-explorer (this is by default (iirc) the the window on the far right). Go to Properties->Linker->General and enter the directories under which you have your opengl libs in "Additional linker directories". Then go to Linker->Input and enter the lib filenames (including the ".lib" extension) in "Additional dependencies". (I am working with the german version of VS 2005, but I am pretty sure its the same in 2008 and I hope my translations are right :) )
  11. Before we can help you, you need to provide some more information: Which engine are you using to create, draw, move your character? What language are you programming/scripting in (C++ is not a scripting language). What system/OS are you on? How do you process the keyboard input?
  12. Basic Reference Question

    Why don't you just compile it at see for yourself? (But yes, your code will do what you expect (if I am right about what you expect it to do ;) )
  13. c++: passing class pointers into constructors

    hmm, my guess is its trying to create a temporary object using the default copy sontructor, which expects (reference to) another Wrapper object as a parameter and not a *Cfg. Could be wrong though, maybe someone can knows why exactly it is that you can't call constructors from constructors in C++?
  14. Most compilers will give you a warning, depending on the warning level you set. Mine did :) (Microsoft VC++ 2008)
  15. C++ best practices (specific examples)

    1. First solution lets you pass NULL, second one does not, because a reference is just another name for an already existing object, so doStuffWithTable1 has to check, if a valid instance has been passed, while doStuffWithTable2 can safely assume the paramter is valid 2. Yep, I'm pretty sure this will work, but why don't you try it out yourself?
  • Advertisement