| turlisk (3) | |||||
|
Just a warning that this is for a class and is a lab for homework. I'm not expecting an answer but some help for going the right direction would be awesome. I have a class I've created called Vector3D it normally takes in a 3D vector. However we are now working with 4D vector's and I'm modifying the code to use array's of vectors to create a matrix and translate it. I can get the array to carry over, i can modify the array and set it to a new array after the translation. However when it returns the array it doesn't modify anything. I'm not sure why this happening. I have my main cpp file and the functions I'm using from my Vector3D class. main.cpp
And the vector3D.h file
Any help would be great on this. | |||||
|
|
|||||
| ne555 (2988) | |||
If you know the size of your vector allocate it statically. resultMatrix[i].translation(&matrix[i], tmpX, tmpY, tmpZ, tmpW, verticies); Don't catch return value. Expects to modify matrix.
Another comments: _ What is the purpose of resultMatrix in main? It's incredible big and filled with garbage. _ Be careful with dynamic allocation (avoid it). Check for memory leaks. _ Why do you use a member function (dotProduct) as it was a global? t[0].dotProduct(a[i]);_ Those setters and getters are 'stupid'. For what they do, you better make your members public. _ You don't use W in the translation, why ask for it? Let the client work with (x,y,z) and you perform the operations in the space (x,y,z,w) | |||
|
|
|||
| turlisk (3) | |
|
_ What is the purpose of resultMatrix in main? It's incredible big and filled with garbage. It was something i was trying so i would catch a result. it can be removed with little to no changes _ Be careful with dynamic allocation (avoid it). Check for memory leaks. dynamic allocation was something i've had some run in's with the teacher suggested using it. _ Why do you use a member function (dotProduct) as it was a global? t[0].dotProduct(a[i]); I'm not really sure on this. _ Those setters and getters are 'stupid'. For what they do, you better make your members public. Other functions in the class use those variables and modify the data (you're not seeing the full class, the forum won't allow me to post that class because it is to big. It's a 3D vector with all the math built in for modifying vectors.) For the assignment at hand those are fine. _ You don't use W in the translation, why ask for it? Let the client work with (x,y,z) and you perform the operations in the space (x,y,z,w) Again with the class we built we use W in other functions and will use it later in 3D rotations so i need to build in methods to get that value now. | |
|
|
|
| ne555 (2988) | |||||
So you want that resultMatrix has the translated points?
An easy way to fix that is to change the class responsible for doing the operation. A Matrix4D or Environment class could be useful. (check OpenGL: pushMatrix, rotate, translate, scale, etc.) | |||||
|
Last edited on
|
|||||