Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

125 Neutral

About Krik

  • Rank
  1. Krik

    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. 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. 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. 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. 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. 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?
  7. Likely someone is going to look at me side ways, I may even get my head knocked off and handed back to me, but I have to ask. I am getting tired of fighting IDE's. Everything from the frameworks not being found (even though it is installed and works with other programs) to having to track down some obscure setting. Or a library file needing to be "linked", sometimes in more than one spot. And all compounded by poor documentation, or what is there is missing some key note. When did programing turn into something sort of using AutoCAD. I want to type (well copy, paste at least) and solve impossible coding dilemmas, not change settings on poorly constructed software. I build PHP based web apps for a living, while the PHP does some of the heavy lifting, it is almost night and day when it comes to dealing with IDE's for writing code in C++. PHP can be done in a text editor (obviously a bit nicer one is good), and with that text editor I can include "library" files, pass data to and from other programing languages (MySQL, XML, Javascript, etc), make graphics, create files, ect. Also, as showing the server generated error messages to the user is not preferred, I build my own error handling, which during development can be used to provide additional debugging info. And all that can be done without touching any software settings. Now obviously a compiler is needed for C++ but after that why on earth do I have to leap tall buildings to get an IDE to work with C++. It seems to me one could write C++ in a text editor. Build your own error handling and debugging "library" and run it in a simple compiler. Or maybe these IDE's have finial driven me to looney bin.On top of all that, what is more disconcerting is I know Microsoft. It can be just about guaranteed that upgrading to the next version of Visual Studio will be about the same as having to buy your first copy of Visual Studio, hours and maybe even days learning how to just make your first "hello world" compile. If it is possible to use a text editor and a compiler to do C++, please I'll read a 10,000 page tutorial over keep on fighting these IDE's. It would seem to me it's possible, just most rely on the IDE to take care of certain things that could likely be done fairly simply in one's code or with an additional library file. Funny thing is PHP is written in C and C++ if it were all a C++ lib or .h files man would it make things easy on me (hmm, I wonder???), barring the linking thing that is.
  8. Krik

    Complete beginner

    What languages would you suggest for a total beginner?[/quote] Try learning Python or Java, even C# is easier. I beleive Python has a very active game development community. If I am understanding what I have read about games, C++ is what you need for top notch games, but to build simple ones, where you can hone basic programming skills without the hassels of the C++ language there are several to choose from. If I had to recommend one I would say give Python a look their website has some very well done documentation. In fact to date I only know of one other language that does a slightly better job on documentation, PHP. Most languages are refered to as c-based languages so if you get one down you have a big step up in learning C++. Because I'm interested in Game Development is it advised I focus on that area more so? Or just programming in general?[/quote] I would think you could make a game right out of the shoot. How much code does it take, for example, to make a text based dice game? You could probably do it in a hundred lines of code or less. Start simple and work you way up. The trick is to get your mind set on the fact you will not be starting your million dollar game idea for at least 2 or 3 years (not to discourage you). By "dyscalculus" I assume you mean "dyscalculia". I guess if I was about 10 years younger I would have had it too. But as I was born too soon I never got dyagnosed, thankfully. To do complex math you need to forget the methods you were taught in school. Most don't realize it but just about every day you are doing algebra. If you go do anything were you plan to spend a predefined limited amount of money the process by which you decide how to spend that set amount is algebra. And I guarantee you didn't write out the equation and you likely did the math in your head. The basis for all math is 2+2 (addition) or 2-2 (subtraction), anything more complex than that is had it origin there. Sometimes geometric calculations require a formula but those should be as simple a basic addition (multiplication) and subtraction (division). If its more complex than that someone is just showing off and go find a simpler formula elsewhere. Knowing you have dyscalculia is likely a bigger disadvantage than the actually having dyscalculia, as it causes one to give up long before they would have otherwise.
  9. 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. 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.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!