Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About papa

  • Rank
  1. Hi I exported some objects from a mesh file in which Z axis is the up vector not Y axis as in DirectX or OpenGL. Now when I render these objects in DirectX these object's orientation isnt correct obviously because the up vector in DX is Y axis not Z. You have to basically turn your head to the right by 90deg to view it :) Now every object in the scene has its position in 3D and rotation in angles (radians) xyz. (Vec3D pos, Vec3D rot) I thought I can simply swap Y value with Z value and it will be ok. But its not. Well for vector positions it works ok but swapping angles Y with Z doesnt work. I thought its ok.. how can I swap these angles? Please note I know I caould simply use rotation matrix to rotate teh entire scene but I dont want that. I want to do it the way I started doing.
  2. it is possible to transform a point by a matrix like this but I am not sure what I should do then. D3DXVECTOR3 X = D3DXVECTOR3(1,0,0); D3DXVECTOR3 Y = D3DXVECTOR3(0,1,0); D3DXVECTOR3 Z = D3DXVECTOR3(0,0,1); D3DXVec3TransformCoord(&X, &X, &rot); // trnasform 3D point by rotation matrix D3DXVec3TransformCoord(&Y, &Y, &rot); // trnasform 3D point by rotation matrix D3DXVec3TransformCoord(&Z, &Z, &rot); // trnasform 3D point by rotation matrix at this statge I think I rotated each axis by "rot" matrix. but still I dont know how to combine those three 3D vectors into 1 3D vector (xyz) with correct euler angles.
  3. Hi. I have an orientation quaternion from which I extracted the rotation matrix and now I need to get rotation in XYZ euler angles. Is there any way to do it using dx9 math lib? or any other simple way? The code I wrote is: void GetRotation( D3DXVECTOR3 *angles_out, D3DXQUATERNION *qrot ) { D3DXQuaternionNormalize(qrot, qrot); D3DXMATRIX rot; D3DXMatrixIdentity(&rot); // Get rotation matrix from this quat D3DXMatrixRotationQuaternion( &rot, qrot); // Here finally I need to extract euler angles from "rot" matrix and put it // into 3D vector(xyz) "angles_out". } Any ideas how to do this?
  4. Ok. Thank you all for help. Now I know why :)
  5. ok. snk_kid but Mr "Agony" :) (see his code above) doesnt use any assigment operators just a copy contructor. It seems to work. Do I need also an assigment operator? or using his code is ok?
  6. ok thanks guys. Really clever :) So I won't have to delete the contents of std::vector once it goes out of scope. This way all will be delete whenever it needs to yes? cool...
  7. smart_idiot hehe nice name. I am not sure how to use your code in my code. Why would I need a copy contructor. As far Ias I know its useful for this; A a; B b(a); I am not sure how else I could apply to my main program
  8. Yes of course youre right. Its basically same thing. I just need to deallocate it in the end. yes now it doesnt crash. Thank you. vector<A*>cont; for(int i=0; i<2; i++) { A *a = new A; a->p = new int(555); cont.push_back(a); } for(int i=0; i<cont.size(); i++) delete cont;
  9. Ok usual question. How can I overcome this problem? I dont really wanna remove stuff from a destructor as I use this class quite often and in most cases I need this delete stuf in the destructor. Any suggestions?
  10. Hi I have this simple A class sample where *p represents some additional information I wish (sometimes) to store in an object of class A. If I wish to store some info I allocate p otherwise I keep it NULL. Now I finally store this a object in std::vector. And whenever this object a has allocated p the program crashes. I know why. Its because the "a" goes out of scope of for() loop which calls a's destructor which deletes p but I thought it will be first stored in vector container then it will be destroyed so I thought its valid. NOTE: I have to store copy of A objects into std::vector as it is now. class A { public: A(){n=0; p=NULL;} ~A(){if(p)delete p; p=NULL; } int *p; int n; }; void main() { vector<A>cont; for(int i=0; i<2; i++) { A a; // New object of type A every loop a.n = i; if( extraInfo ) a.p = new int; // allocate pointer if needed else a = NULL; cont.push_back(a); } // this is where it crashes. a is being destroyed here. // I think container doest like that it is destroyed! } I thought that std::vector would store every time a copy of "a" in the container so when a is destroyed it wouldnt affect it in any way the copy stored in "cont" that I need for later use. How can I fix this?
  11. ok then so what do you do in order to store exactly same number into your data structure as in the text file. I am not using any doubles. All my program is based on floats. Well thats how I contructed my Vector class. Could someone please tell me how to fix this? I dont really wanna start playing with shifting stuff as some of them need that and some dont. There must be a simple way to do that. come on. Maybve if I read them as doubles and cast to floats? or its even easier solution?
  12. Hi. I am reading the following data from a text file: "0.000000, -0.000028, 0.912098" this way: if (sscanf(szLine, "%f, %f, %f", &pos.x, &pos.y, &pos.z ) == 3) and what is stored is: x = 0.000000 y = -2.8000000-e005 z= 0.91209799 So. Y is completely wrong and Z slightly wrong it should be 0.912098 in the end rather than 0.91209799. Why is that? It definetely something wrong with the floating point precission but how can I fix this?
  13. oupsss. I think I gave you wrong example. see my corrected example. class A { public: A(){} ~A(){} int particles; }; class B { public: B(){ objects=NULL; } ~B(){ if(objects)delete [] objects; } A *objects; }; void main() { B *b = NULL; b = new B[2]; for(int i=0; i<2; i++) { b.objects = new A[4]; } delete [] b; // Is it enough? } } So this will delete b array (size=2) and its internal objects array (size=4) for each b. There wont be definetely any memory leaks?
  14. Hi I am always confused how to delete dynamically alloc array holding a list of pointers each slot. Consider this example class A { public: A(){ particles=NULL;} ~A(){ if(particles) delete [] particles; } int *particles; }; class B { public: B(){ objects=NULL; } ~B(){ if(objects)delete [] objects; } A *objects; }; void main() { B *b = NULL; b = new B[2]; for(int i=0; i<2; i++) { b.objects = new A[4]; } delete [] b; // Is it enough? } The above delete [] b should call B's destructor and delete entire array holding 2 A objects. When each object A is deleted it should call its own constructor a delete its own array of particles (size 4) Is it right? or I need to loop through b and delete first its elements then delete b? Please let me know. thanks. [Edited by - papa on September 27, 2004 11:46:29 AM]
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!