# Chire

Member

14

122 Neutral

• Rank
Member
1. ## [SOLVED] Map 1D Array to 2D Triangular matrix

ok friends i got the expression mathematical 100%. this will help you optimize a lot of memory usage when matrix calculations only operate on the triángular part, like in my case. i will go step by step. 1) view A as the representation of lower triangular part (totally equivalent) A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] A[5][5] = 0...-...-...-...- 1...2...-...-...- 3...4...5...-...- 6...7...8...9...- 10..11..12..13.14 2) now: given c = 0..14, we know that there will be a sumatory of n, n times until c is reached. Sumatory(i) when i =0..n can be written as n(n+1)/2 and this is equal c. c=n(n+1)/2 which is the same as n^2 + n - 2c = 0. 3) then, what you need to program is this n Value n = (-b + sqrt(b^2 - 4a*2c))/2a ==> simplier n = (-1+sqrt(1 + 4*2c))/2 4)finally calculate i and j i = truncate(n). j = c - i*(i+1)/2 :) [Edited by - Chire on March 20, 2010 5:03:58 PM]
2. ## [SOLVED] Map 1D Array to 2D Triangular matrix

Quote:Original post by Emergent Hmmm.... The obvious brute-force way would be to start with x, and then subtract off n, then n-1, then n-2, etc, until you can't subtract off any more; the number of subtractions is 'i;' 'j' is 'i' plus whatever is left. It'd be nice to turn this into a mod/divide though, but this isn't jumping out at me... The other direction -- "given i,j, return x" -- is easy enough though; you get a quadratic form... yea, brute force works good for small sizes. there must be an expression to calculate "i", lets hope. i will post any advance i get. and any help is welcome,
3. ## [SOLVED] Map 1D Array to 2D Triangular matrix

hello, im running with a little problem on an algorithm lets say i have this array of size N(N+1)/2, where N is the size of the 2D matrix that represents it, in this case N=5: A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]. i need to map it to a 2D triangular matrix: A[5][5] = 0..1..2...3...4 -..5..6...7...8 -..-..9...10..11 -..-..-...12..13 -..-..-....-..14 so, what im trying to do is an algorithm that receives as parameter a given index x= 0..14, and returns i,j of the matrix. for example. function(0) returns i=0, j=0. function(7) returns i=1, j=3. function(11) return i=2, j=4. function(14) returns i=4, j=4. i have came up with different algorithms, one worked for 3x3 Matrixes, but i cannot figure out the generic ecuation for any square triangle matrix. any help is welcome, meanwhile i will keep trying. EDIT: From my análisis, the key is to calculate "i", since j can be calculated very easy after that. [Edited by - Chire on March 20, 2010 6:05:51 PM]
4. ## Bump Mapping -- need some orientation

hello, im learning the famous technique known as bump mapping. for personal needs, i want to apply this to a sphere. but i have only found tutorials applied for quads and a torus. does anyone have some sample code? (meanwhile ill try to edit one of the tutorials i've found...) thanks and i hope i get some help!
5. ## Uncontroled high FPS for Opengl Project on other machines

i understood what you guys mean. i will work on that very good ideas. thanks!
6. ## OpenGL Uncontroled high FPS for Opengl Project on other machines

Hello, im having some dificulties porting some projects to other machines, the framerate goes extremely fast like 280 and its unplayable, when in the original pc the framrate was locked on 60fps, is there a way of making the aplication run at normal speed on every machine? thanks in advance
7. ## Class A uses Class B, and B uses A (in separate Files) problem

that is another option you are right. ill keep the object pointer until i realize i wont need the other functions/atributes at all. auoheoeahoauehauoehao!
8. ## Class A uses Class B, and B uses A (in separate Files) problem

Quote:Original post by LordShade I get what you're using it for. Ask yourself, why should a projectile need to know what it is fired from? In the real world, a 9mm fired from any pistol or submachine gun just knows that when it's primer is triggered, it ignites the powder and launches the round at some arbitrary velocity. The gun itself determines it's vector and spin. So really, the round shouldn't know anything about the weapon it is fired from. The weapon should just set the vector and modify speed if necessary. Pre-caching projectile classes will speed up your performance as you mentioned. I'm not saying that it is wrong to have classes linking to each other as mentioned, all I'm saying is that more often than not, there is a better solution. Happy coding. yes, but you know that linking the projectile to the weapon, you can make wonderful creations like boomerang style bullets, rockets that orbit around you changing dinamically, energy rails that connect you and the target at every moment, well lots of intelligent projectiles and of course the classical bullets that you mention dont get affected by this structure.
9. ## Class A uses Class B, and B uses A (in separate Files) problem

Quote:Original post by LordShade If this situation occurs, it usually marks the time to re-examine your class structure. Ask yourself why some functionality needs to be in B when A needs to use it? Why not put it in A anyways? Happy coding! yes, you are right about that im re-examining the need of the object A atribute from class B in my case one class is CProjectile (this would be class A) that has a pointer to the CWeapon(this would be class B) that belongs to, so when doing the motion, collision and physics algorithms will be easier to deal cause i can grab all existing projectiles and recalculate them in relation to the weapon it was fired from. up to this point, most of you should agree with the logic. now comes the optional part, which i still dont know if i would need it for future: until now CWeapon class had an array of objects CProjectile, a gun has projectiles so at first one should think that a weapon should have that array. (update: like as SnprBoB86 said, to navigate from a to b and from b to a.) but after thinking twice maybe is better to just not have any array and have a global one, i would loose B to A but still have A to B. i will see whats better over these days. thanks
10. ## Class A uses Class B, and B uses A (in separate Files) problem

now is working! the problem was the same you said, so i fixed it and now i dondt have undefined classes. thanks!
11. ## Class A uses Class B, and B uses A (in separate Files) problem

hi, im having some problem wih my classes, class A has a pointer type B. class B has an object to of type A, //FILE A.h Class A{ public: B* pb; }; //FILE B.h Class B{ public: A objecta; }; they are in different files, i've tried adding class B; before defining class A but i didnt work, because they are in separate files.
12. ## bmp texture load + new nvidia driver = wtf

hi, my problem is very simple. i upgraded today to the latest nvidia driver available on www.nvidia.com but i have a problem... the nehe, and morrowland tutorials,(for example the texture tutorials ( tuts number 06 and 07 )) just dont work, i see weird colors instead of the correct texture. i dont post image because is as simple as that.? with the previus driver all worked perfectly. I have a geforce fx5900 128mb pd: i also lost control over my framerate, it goes up to 250fps. anyone know how to solve that texture problem???
13. ## problem with window coords--- world coords

problem solved with google my mistake was that i was obtaining the matrix data in a wrong part of the drawing function, and also is recommended to use this method in orthogonal projection.
14. ## OpenGL problem with window coords--- world coords

hi, i've read the tutorial about transforming window coordinates to Opengl coordinates. in the last step, when i transform my window mouse coordinates to new opengl world coordinates x,y,z.... i have a problem because they are just the same as my old window coordinates, and z reads -1 all the time. heres the code: //variables GLint viewPort[4]; GLdouble modelView[16]; GLdouble projection[16]; GLfloat winX, winY, winZ; GLdouble mouseWorldCoordX, mouseWorldCoordY, mouseWorldCoordZ; winX = (float)mousePos.x; //Reading mouse coords x winY = (float)mousePos.y; //Reading mouse coords y glGetIntegerv(GL_VIEWPORT, viewPort); //getting viewport winY = (float)viewPort[3] - winY; //changey to increase from bottom to up glGetDoublev(GL_MODELVIEW_MATRIX, modelView); //getting modelView matrix glGetDoublev(GL_PROJECTION_MATRIX, projection); //getting projection Matrix glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); // ??? gluUnProject( winX, winY, winZ, modelView, projection, viewPort, &mouseWorldCoordX, &mouseWorldCoordY, &mouseWorldCoordZ); //get world values those final variables mouseWorldCoordX mouseWorldCoordY mouseWorldCoordZ have just the same values as my winX winY winZ coords. any suggestion? thanks