Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

667 Good

About zacaj

  • Rank

Personal Information

  1. zacaj

    potatoeses or potatoeseses

    If you insist on doing it that way, then malloc is indeed what you want to use if you want to allocate the memory for them without calling the constructors.  You just have to be careful that the first bit of memory in each object doesn't ever end up being zero, otherwise your check wouldn't work.     Alternately, just have an empty constructor.  
  2. zacaj

    Using STL Maps

    Since you didn't allocate them using new there won't be a memory leak
  3. zacaj

    potatoeses or potatoeseses

    If you want to use any inheritance then you need to story individual pointers to objects, so the 4 bytes are required anyway (and it's not like 4 bytes per object will actually make an impact).  If you only have one object then I'd suggest just giving them a bool active variable and then just setting it to zero to show that they're 'dead' or whatever.  As to the unbearableness, it only affects maybe three lines of your code, and besides, you *are* using C++.  What did you expect?     really though, unless there's some big reason why you're using an array like this, I'd recommend you switch to using a std::vector<SomeObject*>
  4. zacaj

    potatoeses or potatoeseses

    Off the top of my head, try SomeObject **so; so = new SomeObject*[max_objects]; An array is a pointer to a block of memory, so in your case you want a pointer to a block of pointers that you can then individually allocate
  5. I'm working on a DOOM-esque game in opengl for 7dfps and I need to make the billboarded pickups and enemies.  Is there somewhere which documents the 'correct' way to rotate the quads and to choose which sprite of the enemy to show?  If not, can someone tell me if there's anything wrong with the algorithms I've come up with?   For billboards: I have made the billboard perpendicular to the player's view angle.  I also tried making it perpendicular to a line pointing at the player's position, but it looked worse.     For enemies: radiansToSide=PI*2/8  (8 is the number of sprites I have for enemy) angle=atan2(enemy.y-player.y,enemy.x-player.x) angle+=radiansToside/2    angle/=PI*2 angle*=8 angle=floor(angle) //angle is now an int 0-7
  6. Try using a union union FloatInt { int i; float f; } FloatInt fi; fread(&fi.i,sizeof(FloatInt),1,fp); Are you sure blender wrote a float and not a double?
  7. class Foo; Foo *foo_pointer; //valid. It's just a pointer, so it only needs to know that Foo is a type (which it does from the forward declaration), it doesn't need to know anything about Foo itself Foo foo; //error. Actually making a variable of type Foo (foo_pointer is of type Foo*, not Foo) can't be done, because we don't know how big Foo is. void accessFoo(Foo *foo) { foo->x=4;//also an error. We don't know what variables Foo contains, so there's no way we could access them } class Foo { public: int x; }; //declaring the type Foo down here doesn't affect the code above it Foo foo2; //this is now valid, because Foo is a fully defined type void main() { foo_pointer=new Foo();//although foo_pointer was declared above the Foo class, since *this* code is below the Foo class, it can access foo_pointer's members foo_pointer->x=8; accessFoo(foo_pointer); }
  8. A.h: class B; //forward declaration class A { //contents } B.h: class A; class B { //contents } A.cpp: #include "A.h" #include "B.h" //code  B.cpp: #include "B.h" #include "A.h" //code This is the safest way.  Basically you can't include a file that includes the first file.     Forward declaring a class allows you to define pointers using that type, but not access them.     So in class A you can have   B* b;   but you can't have an inline constructor that calls a function in b or accesses its variables.   Since you don't usually #include a .cpp file directly, it's safe to just include all the classes .h files in your .cpp files
  9. zacaj

    Help with floorcasting

    Ah!  When he was saying "the distance from the projected pixel to the floor" I thought he meant vertical distance!  That makes all of his code make sense, even if I still can't get the floor to render right when I change the camera height.  (I've got it working fine for z=0)   In his tutorial, he renders the floor in vertical spans above and below the wall sections, computing for every pixel.  You seem to be suggesting that I do floor spans horizontally?  Wouldn't that mean I'm going to need some kind of complicated algorithm to figure out the horizontal spans, since the walls are all drawn vertically?
  10. Been trying to make a little textured raycaster for fun the past few days.  Walls went fine, but I hit a wall when it came to floor texturing.  No idea how to do it.  So I found http://lodev.org/cgtutor/raycasting2.html , and I was able to adapt their floorcasting code quite easily.  It worked, except that it couldn't handle it when I changed the camera height.  Looking at their section on computing the 'currentDist' (from current pixel to floor, I'm assuming vertically), none of what they say makes any sense. "the distance from a pixel in the center of the screen to the floor is infinite"  What? "for the bottom of the screen, you can choose a distance" I'm assuming this would be where my camera elevation goes in "for example, 1" oh, thank god they chose 1 as their magic number.  It's not like that ever comes up anywhere else "the distance the pixel represents in function of it's height in the bottom half of the screen is inversely related as 1 / height."  that wasn't even proper english.  Plus, when they say 'inversely' and then use 1/x I assume the 1 is from standard math, but it's the only place on the page where they make any reference to the camera height which they so helpfully chose as 1 earlier. "you can use this formula" no explanation on how they got that, or anything.   Is it even possible to have different camera elevations with this technique?  
  11. How am I supposed to get a BMP of every character? And by array you mean a BITMAP array?     Oh look what I found on Google:   http://www.dafont.com/perfect-dos-vga-437.font     How am I supposed to use a TTF in SDL? (I know about SDL_ttf() and such.) I'm assuming I make a black BG that takes up the whole screen, then assign a letter in the TTF to each keystroke? That should work, correct?   If you know about SDL_ttf then what's the problem?
  12. Make a console program that prints out each character and then take a screenshot?  
  13. SDL should be enough.  Just get a BMP of all the characters you can print and make an array you can "print" into.
  14. Go over the points in your grid, calculate distance from center point of circle to that point.  If it's less than the radius of the circle, then do point.z+=(1-distance_away/radius)*height_change to get a gradient
  15. zacaj

    Grand Theft Auto 1 Movement

    tank movement/control?
  • 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!