Advertisement Jump to content
  • Advertisement

wlw_wl

Member
  • Content Count

    72
  • Joined

  • Last visited

Community Reputation

146 Neutral

About wlw_wl

  • Rank
    Member
  1. wlw_wl

    random number?

    srand(param) is a funtion that initializes the randomizer (random number generator) with given value, because computing random numer is and isn't what it says: it is computing some number given some initial parameter, so you understand that it is not truly random. srand(time(0)) initializes it with current time, so that each time you initialize the randomizer, you initialize it with a different initial param (called "seed"). Give it a try, put srand(0) and then output few rand() calls. Run the program few times and the numbers will repeat, as you're initializing with the same value. Setting srand(time(0)) sets a different seed for the randomizer each time the program will run, making the numbers somewhat more... "random".
  2. wlw_wl

    3ds max beginner

    Quote:Original post by blackvans1234 how could i make this question less random? lol i know it's much more complicated then just saying 'modelling' i just dont know which direction i should take considering theres so many options and specialties. That being said, do you have any suggestions as to where i should start? What I mean is that you need a good base for about anything. Say, you'd really like to have your model done very well when it comes to lighting, rigging and animating. This takes a lot of work and practice... for example just to make a model so it smoothes and skins well. You want to be a good modeller so start with basics like try to model something that you have on your desk that has some complexity in it. Hopefully you will be working with someone who might be, among other things, animating your model. If I was such a person, I'd really like to be given something that works, not something that requires me to return it to author for fixing or fixing it myself.
  3. wlw_wl

    Using keyboard / mouse with API

    This isn't much of an openGL question, however since you're using winAPI, you'll get good "reactivity", as you call it, with GetAsyncKeyState and, unlike glut, it will let you easily support events where multiple keys are pressed, like walking forward and strafing at the same time, as for FPS example.
  4. wlw_wl

    random number?

    Quote:Original post by Antonym I've gone ahead and looked into the subject a bit, so rand() isn't the best method to get random numbers? Will this method give me problems in the long run? I require random numbers for simple stuff such as a damage range for attacks, a probability to hit target etc.. for a thing like damage or probability you're a better shot with computing it based on some data rather than random'ing, random() isn't that much random as you think. Set srand(time(0)) as I said before, put it at the beginning of your main or whatever so it initializes the randomizer based on current time, this will give you less chance on the numbers repeating.
  5. wlw_wl

    3ds max beginner

    That is a random question. So here's a random answer: Start with modelling, then lighting, materials, texturing, animation. Each of these topics is more complex than it seems at first glance, guaranteed.
  6. wlw_wl

    random number?

    Use the modulo and then offset the outcome, such as: Let's say you want a "random" number between 13 and 78. srand(time(0)); // initialize randomizer int r = rand(); // pick a random number r = r % 66; // limit that number to between 0 and 65 r += 13; // this will offset it by 13, giving you some number between 13 and 78
  7. Hello, I've implemented glPerspective and glLookAt, however I can't get the former to work. Some explanation first: I'm not using stacks, instead I just have two global matrices, ViewMatrix (serves as projection stack) and WorldMatrix (as model view stack). Both initialize with identity, and then i.e. calling LookAt multiplies ViewMatrix by appropriate matrix. So the pipeline looks like this: take vertex P, multiply it by WorldMAtrix, then by ViewMatrix. This should give screen x and y coordinates to draw the pixel. While wLookAt seems to be working fine (I tested it with some false 3d to 2d projection), the wPerspective won't. Here's the code (I don't know how to make those code snippets...): void wLookAt(double eyex, double eyey, double eyez, double centerx, double centery, double centerz, Vec3 up) { Vec3 forward(0.0, 0.0, 0.0), side(0.0, 0.0, 0.0), _up(up); Mat4x4 m; // temp matrix m.identity(); forward.x = centerx - eyex; forward.y = centery - eyey; forward.z = centerz - eyez; normalizeSelf(forward); // just normalizes a vector side = cross(forward, _up); normalizeSelf(side); _up = cross(side, forward); m.m[0][0] = side.x; m.m[1][0] = side.y; m.m[2][0] = side.z; m.m[0][1] = -_up.x; // "-" because objects got drawn upside-down m.m[1][1] = -_up.y; m.m[2][1] = -_up.z; m.m[0][2] = -forward.x; m.m[1][2] = -forward.y; m.m[2][2] = -forward.z; //ViewMatrix = m * ViewMatrix; ViewMatrix *= m; ViewMatrix.translate(-eyex, -eyey, -eyez); } and the other one: void wPerspective(double fovy, double aspect, double znear, double zfar) { double fovy_rad = fovy * 0.017453292519943; // degs to radians double yScale = -1/tan(fovy_rad/2.0); // -cot(fovy_rad/2), yet again "-" because of up-down double xScale = yScale / aspect; Mat4x4 m; // temp matrix m.zero(); m.m[0][0] = xScale; m.m[1][1] = yScale; m.m[2][2] = zfar/(znear-zfar); m.m[3][2] = znear*zfar/(znear-zfar); m.m[2][3] = -1; ViewMatrix = m * ViewMatrix; //ViewMatrix *= m; } and after calling in drawin loop WorldMatrix.loadIdentity(); ViewMatrix.loadIdentity(); Vec3 up(0.0, 1.0, 0.0); wLookAt(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, up); // drawing area is 800x600 wPerspective(45.0, (double)(4.0/3.0), 0.0, 100.0); and Flushing*, I get some weird coordinates which cause app to terminate - negative coordinates in a very first frame, which shouldn't happen as theo nly one object in the scene is set up at the origin and 1 unit big. *) maybe I did this wrong? for each vertex flushing does this: //(d is some vertex in 3d space with Lx, Ly, Lz (L for it's local) coords Vec3 A; A = Vec3(d->Lx, d->Ly, d->Lz) * WorldMatrix; A *= ViewMatrix; //and (try to) draw pixel at (A.x, A.y); - FAIL Please, if you have a clue but need more of the code, say it. I didn't want to paste all at once because it would be unreadable...
  8. Big thanks DevFred! The initializer is just what I (and VS) needed :-) @bobofjoe I'll use the initializer, but thanks!
  9. // from .h struct wColor { int r,g,b; }; extern wColor default_color; // that is why: class wVertex { public: double x, y, z; wColor Color; wVertex(double x0, double y0, double z0 = 0, wColor _color = default_color); // ... }; // from .cpp wColor default_color; default_color.r = 0; default_color.g = 0; default_color.b = 0; wMaterial *default_material = new wMaterial(default_color); //---------------- So what you say is that I should move that to some initialization function or something?
  10. Sorry, it should be: void do_something(int x, int y, color default_color = some_color); just a "typo"
  11. Hello, I do a simple thing: // my.h file struct color { int r,g,b; }; extern color some_color; /* extern because I also use some_color in function declarations in the same .h, like this one:*/ void do_something(int x, int y, color some_color); // my.cpp file #include "my.h" color some_color; some_color.r = 0; // * Seems ok to me, but not to VS. Following errors while compiling .cpp: line marked by *: error C2143: syntax error : missing ';' before '.' error C4430: missing type specifier - int assumed. error C2371: 'some_color' : redefinition; different basic types seems that, despite the declaration of some_color, he thinks I missed the type specifier, so he assumes int - that causes the first and third error. What's wrong here? [Edited by - wlw_wl on November 5, 2008 5:15:31 PM]
  12. wlw_wl

    [Resolved] Basic I/O problem in C++

    really all I see is that possibly something is left in the buffer, try using ostream& flush ( ostream& os ); (before attempting to read name) as referenced here: http://www.cplusplus.com/reference/iostream/manipulators/flush.html
  13. Noticed that just after posting. I get the idea, it's nice and it's not unknown to me, just didn't think of using this. Thanks very much for enlighting me :-) Now only the buffer thing... How to access it in WinAPI? I recon it will be some one dimensional char array or something.
  14. Quote: Unless there are some hardware/career restrictions that force you to use C, I'd suggest you start using C++ and taking advantage of interface. Quote: SetPixel(x,y) style is de facto slowest possible approach to do rendering. Almost without exception APIs provide a way to access drawing buffer directly in form of pixels. Both of you please provide some more information. I was told to use PutPixel-like function, since I was using VS it's SetPixel. If there's a faster way, I'd be pleased to know it. Also I don't like COLORREF and I'd like to get rid of it, and non-SetPixel approach would free me from it, I guess :)
  15. wlw_wl

    [Resolved] Basic I/O problem in C++

    getting a line means getting a character string until finding a newline character, so, as KulSeran points out, you need to find how that \n character gets in places where you don't want it to be. Happend hell a lot of times to me while doing very very simple programs at university.
  • 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!