# Krik

Member

10

125 Neutral

• Rank
Member
1. ## Rotate 4x4 matrix formula

Thanks Geometrian for posting that code. I haven't worked in C++ for about a year so I will have to take a bit of time to dig into that and see what I can glean from it. Since my post I have found a few more examples and articles but I am still a bit off on my calculatios. I am sure some will laugh but the formula I found that cracked everything open was not a formula to create the matrix but a formula that allowed one to pull the degrees of rotation out of the matrix. I took it and just reversed it, then from there I knew where to place the results and I figured out matrix multiplicaion.   But like I said things are bit off. There are some built in functions for simplifing rotation (they are limiting what I can do), and I am comparing my numbers to them. If I just rotate on one axis the numbers are fine it is when I rotate on more than one that things get messed up.   I have my code outputing the numbers from the built in rotation fuctions (first matrix below) and from my calculations (second matrix below), here's what I am seeing X: 2deg Y: 2deg 0.9993908270190958, 0.001217974870087876, -0.03487823687206265, 0, 0, 0.9993908270190958, 0.03489949670250097, 0, 0.03489949670250097, -0.03487823687206265, 0.9987820251299122, 0, 99.93908270190957, 100.06088018891836, 0.002125983043832047, 1 X cosine: 0.9993908270190958 X sine: 0.03489949670250097 Y cosine: 0.9993908270190958 Y sine: 0.03489949670250097 0.9993908270190958, 0, -0.03489949670250097, 0, 0.001217974870087876, 0.9993908270190958, 0.03487823687206265, 0, 0.03487823687206265, -0.03489949670250097, 0.9987820251299122, 0, 100, 100, 0, 1 Note that there is a 100 translate on both the X and Y axis so I can throughtly test my numbers. I looks like the X and Y cosine and sine calculations are correct but something is not being calculated correctly after that. Nor is the calculation being applies to the translate values (I suspect I need to just research a bit to solve this). Hmm, as I look a little closer it looks like maybe some numbers are in the wrong spot ... but why?   Here is a pseudo version of the code I currently have basematrix = [     [1, 0, 0, 0],     [0, 1, 0, 0],     [0, 0, 1, 0],     [100, 100, 0, 1] ]; function RotateMatrix(y, x) {     halfrot = 3.141592653589793 / 180; // pi divided by 180     xcos = cos(x * halfrot);     xsin = sin(x * halfrot);     ycos = cos(y * halfrot);     ysin = sin(y * halfrot);     ymatrix = [         [ycos, 0, -ysin, 0],         [0, 1, 0, 0],         [ysin, 0, ycos, 0],         [0, 0, 0, 1]     ];     xmatrix = [         [1, 0, 0, 0],         [0, xcos, xsin, 0],         [0, -xsin, xcos, 0],         [0, 0, 0, 1]     ];     calcmatrix = MatrixMultiply(ymatrix, basematrix);     calcmatrix = MatrixMultiply(xmatrix, calcmatrix);     for (i = 0; i < 4; i++)     {         for (j = 0; j < 4; j++)         {             //output calcmatrix[i][j]         }     } } function MatrixMultiply(matrixa, matrixb) {     newmatrix = [];     for (i = 0; i < 4; ++i)     {         for (j = 0; j < 4; ++j)         {             newmatrix[i][j] = matrixa[i][0] * matrixb[0][j]                             + matrixa[i][1] * matrixb[1][j]                             + matrixa[i][2] * matrixb[2][j]                             + matrixa[i][3] * matrixb[3][j];         }     }     return newmatrix; } Maybe someone can see what I did wrong.
2. ## Rotate 4x4 matrix formula

I am trying to figure out how to work with a 4x4 matrix, in particular rotating them. I have been searching and reading differnt things but I keep hitting a brick wall when I see the formulas. I can see which parts of the matrix need to be changed depending on if I rotate on the x, y or z axis. But I cannot interpet their formulas so as to use them in code.   I have tried several experiments and I am not geting the right numbers. And since they use letters and greek letters and give no point of refernce for them I am sure additional calculation are need but there is no clear reference to the correct calculation. In one fomula I saw they used cosine and sine with the theta character in parenthases which previously in the article it was defined as pi/2 (which makes no sense at all) but that didn't work when I used it.   I am hoping someone has some nice clearly defined formulas I can work with.
3. ## Can I avoid the hassle of these IDE's?

Wish I could, I would have sworn gremlins was a system requirement for using Microsoft products... No wait, gremlins is one of the support packages they install.
4. ## Can I avoid the hassle of these IDE's?

Yea, Visual Studio would make my life easier if I could get it to work, to start with. I have tried everything I can find to get it to work. And after a couple reinstalls it is looking on drive d for the MSBuld which without it won't even let you start a new project, I solved that by moving MSBuild to drive D. But then it cannot find .NET Framework 4.0 even though I have confirmed it is installed and working. To solve this requires I add a line to the .vcxproj files in every project to look to version 3.5 and then edit "Platform Tools" (I think thats what its called, can't recall were the setting is, at the moment) from v90 to v100. And this has to be done with every project both new and imported. So right now I look at a lot of example code and it takes a fair amount of time just to see how someone elses code works. And even after all that there is still a bug that randomly shows up, when I go to debug, I get a compile error that has some long negative (-) number, which I accidentally found I just need to exit Visual Studio and restart, and everything will work again. And oh and then there is the fact that all this some how is causing it to think my projects are out of date so every time I run the debugging it asks if I still what to compile the project. Visual Studio will making my life easier??? Its been a week getting it to work so not from where I am standing, it has made my life more difficult. In reality Eclipse is easier and it requires that you figure out how to configure MinGW to work with it, and even then the Debugging is very awkward to work with. I am half inclined to use Eclispe but I have yet to find a tutorial on how to get 3rd party libraries to work with it. Of course I may have given up on that bit early as the hassle with Visual Studio has me quite put out with IDE's. I have tried using Eclipse in the past with PHP and it had some idiosyncrasies that made it awkward to use so I am not set on making it work either. Found a tutorial on makefiles http://oreilly.com/c.../book/index.csp and I am also looking at GNU's documentation http://www.gnu.org/s...node/index.html. Probably a little later I will be figuring out how to use CMake. I guess if I find building my own makefiles and batch files some how horrible difficult (which right now is not looking to be the case) I will give Visual Studio another shot. But to do that will require I wipe my C drive and reinstall, which for the way I like things Windows 7 needs heavy modification to work, half, right and reinstalling everything takes the better part of day to get done, and not one I look forward to.
5. ## Can I avoid the hassle of these IDE's?

Actually I don't mind command line, I come form the old days of DOS and Windows 3.1, when to setup new software required that you knew how to use command line. I still on occasion use command line to fix PC's that won't boot to windows. I also worked with Linux back in the 1990's, when it was still very much a command line based OS. I even remember using an 8086 PC (and no that is not is MHz) from the early 1980's, you had to use the command line to configure the print drivers. My programing experience goes back to writing code in Q-Basic, so command line and bat files were at one point old hat for me. I would rather edit ini, bat, dat, and now xml files than try to figure out where some software is hiding some setting. It amazes me how often after using some piece of software for several years I learn it has features I have been wanting for almost as long as I have had the software. If I had been able to look at a configuration file I likely would have spotted it much sooner, you should have seen what I did with Windows 3.1. If I can use batch files like Dragonsoulj is suggesting this may solve much of my headaches. I would much rather type code than learn to use some poorly made software. Also one other thing I ran into while doing my own research was "Preprocessor Directives". I am not sure if there is anything of use in them but they do look to have some potential. Its funny how all the programing books and tutorials just completely skip over these, even though they are used (#include, #define, #pragma, and several others). I am temped to call it the "IDE effect", if it is all taken care of for you why go into any detail of learning how it works.
6. ## Can I avoid the hassle of these IDE's?

That happens a fair amount when working with objects oriented programing in PHP. I have had to many times work my backwords through classes trying to catch exceptions, so thats nothing really unusual to myself. That is one thing nice about PHP a good "var_dump" can output the entire object and you can see if you're calling the information you need correctly and if the information is making its way to where it should be in the object. Of course some IDE's have an object browser not entirely sure how it compares with "var_dump", seems to have some info anyway. Have thought about building a var_dump equivilent for c++, based on what I have read, not an easy prospect to say the least. [quote name='Fredericvo'] For quick and dirty solutions I use vc10 from the commandline and notepad++ as the editor. [/quote] Notepad++ is my prefered IDE for building web apps currently. I assume vc10 is Visual Studio 10, is there a good tutorial or documentation on using it from the command line?

9. ## Need help using D3DXCreateTextureFromFileEx

Since filename is a char*, why do you append .c_str()? It's not a std::string.[/quote] I had tried removing it but had ran into other problems, so I wasn't sure it was the answer, just didn't have the other part of the solution. I would have never thought appending an "A" to the function would fix my code. For all the searching I did never once saw that suggested. I do have some followup questions based on that answer. In researching a solution for my problem I saw several places that recomended that Unicode (W) be used instead of ANSI (A). Am I understanding that correctly? It does appears that if I use "WCHAR*" instead of "char*" and append a "W" to the functions it works also. So which is the recommended route? Also I appended the "A" (also tried "W") to both the "D3DXGetImageInfoFromFile" and the "D3DXCreateTextureFromFileEx" functions. Is it safe to assume that "A" (and "W") can be appened to most of the DirectX functions?
10. ## Need help using D3DXCreateTextureFromFileEx

Been beating my head against the wall for the last few day and so I am hoping someone can help. I am relatively new to programming in C++ (been programming in PHP [and other languages] for several years) and in the last few months I started playing around with DirectX. First, the original code I am trying to modify, and that does work (I think most of it came from a tutorial). LPDIRECT3DTEXTURE9 Dx_Manager::GetTexture(char* filename) { for (int i = 0; i < MAX_TEXTURES; ++i) { if (!d3d_texture.texture && d3d_texture.inuse) { continue; } d3d_texture.inuse = true; d3d_texture.filename = filename; D3DXCreateTextureFromFileA(d3d_device, d3d_texture.filename, &d3d_texture.texture); return d3d_texture.texture; } return NULL; } Apparently "D3DXCreateTextureFromFileA" insists that graphics be sized to the power of 2 (2, 4, 8, 16, 32, etc), and while it can be dealt with, by making unused parts of the graphic transparent, I can foresee problems with scaling as well as interactive graphics elements overlapping each other. And on top of that there is the wasted memory for the larger than necessary graphic. So I am thinking that using D3DXCreateTextureFromFileEx would be better. Here is what, I think, I need to replace line 12 (above) with: D3DXIMAGE_INFO info; HRESULT result = D3DXGetImageInfoFromFile(filename.c_str(), &info); if (result != D3D_OK) { return NULL; } D3DXCreateTextureFromFileEx( d3d_device, filename.c_str(), info.Width, info.Height, 1, D3DPOOL_DEFAULT, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0xFF000000, &info, NULL, &d3d_texture.texture ); But in both the places that I use "filename.c_str()" I get this error error C2228: left of '.c_str' must have class/struct/union If take off the ".c_str()" I get errors similar to this error C2664: 'D3DXGetImageInfoFromFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR' I have tried changing the type of "filename" from "char*" to "WCHAR*", "TCHAR", "LPCWSTR", "LPCSTR" as well as looked up ways to convert "char*" to other types and all have failed to work. And really I am not even sure changing the type definition is the solution to the problem. Any direction on this would be much appreciated. Also in researching a solution, I read in one place that "D3DXCreateTextureFromFileA" is easier on graphics cards than "D3DXCreateTextureFromFileEx". So if there is a completely different approach I should be looking at let me know.