ifthen

Members
  • Content count

    61
  • Joined

  • Last visited

Community Reputation

820 Good

About ifthen

  • Rank
    Member
  1. Embedding Math Equations in Articles

  2. Object was not declared in this scope?

    If you use the raw pointer solution SiCrane posted, don't forget to delete the pointer in the new bullet maker and after the end of the program so you won't leak memory!   E.g. ... Bullet * myBullet = 0; //nullptr instead of 0 if using C++11 while (!quit) { if (shootNew) { delete myBullet; //does nothing if myBullet is null myBullet = new Bullet(); } if (myBullet != 0) myBullet.doSomething(); } delete myBullet; ... If you don't, the old bullets are still in memory, so after pressing the fire button 2000 times, there are 2000 bullets in memory. Yuck.
  3. Vector MADNESS

    As has been said, use std::vector::back() or vec[vec.size()-1], but ALWAYS check if the vector is not empty. Using either of those without checking for non-emptiness results in undefined behaviour and it will most likely overwrite sizeof(vectype) bytes before the start of vector data, corrupting the memory or causing a segmentation fault.   vec.at(vec.size()-1) throws an exception if the vector is empty, but it sacrifices speed and does not solve the problem except for alerting you instead of corrupting memory.   Paradigm Shifter: You, sir, have made my day.
  4. It can be done quite easily. There are many uses of this technique, e.g. packets. When retrieving those data, bit AND them by the bits you want to retrieve and right shift them so the least significant bit you want is lowest in the retrieved value. Example: You want bits ...00xxxx00 in the int you have. You bit AND 00111100 (called the mask, this number is hex 0x3C) with your int and right shift it by 2 (the offset).     int result = (myInt & 0x3C) >> 2;     ("I grab only the bits that interest me and shift them so I get a number with values starting from zero.")   Setting the value is quite similar - you bit AND with the inverse of 0x3C (that means 0x3C EXCLUSIVE OR (^) 0), so the bits that interest us are zeroed (not needed when you know all of those bits are already zeroed), and then OR the left-shifted setValue. Note that having the value larger than your storage limit overwrites upper bits, so be wary of what you are doing!     int modified = ((0x3C ^ 0) & (myInt)) | (setValue << 2)     ("I decide which bits interest me, get the opposite (those that don't interest me) and leave only them, effectively zeroing the bits that interest me. Then I shift the setValue so I write it to right bits and add it to the modified number, effectively setting the bits that interest me and are 1 in the setValue.")   Also, you can compute the mask (0x3C) like this:       int mask = 0; for (int i = 0; i < numInterestingBits; i++) {   mask << 1;   mask += 1; } mask = mask << offset; //also written mask <<= offset; And that is it. Be sure to make your own functions for it so you don't rewrite it for every value retrieval!
  5. I personally use PSPad. Its behaviour in these situations is similar to Programmer's Notepad mentioned by Servant of the Lord.
  6. Projectile Class Format

    Will every projectile be different? I do not think so, we can say that every projectile behaves according to its type. Make every projectile have some kind of reference to its type (enum, pointer, reference, ID...). That is 8 bytes overhead at most, which is perfectly okay. You then modify the enemy using the projectile type and are okay.
  7. Control Structure for Animating Billboards

    The way I have seen animation implemented in game engines has been quite the same everywhere: they define a class (let's say Animation) that has a method Update(timeFromLast) and a variable animationTime. Update adds timeFromLast to animationTime and finds the current frame (or interpolation of them). There is usually also an enum that specifies the behaviour at the beginning/end; without interpolation, loop and stop are probably the only reasonable behaviour.   Drawing an animated object is simple then: you usually take the current frame from Animation in draw() function of your model and make the magic there.
  8. Isometric tilemap rendering

    Well... you could be rendering your objects with the Z axis set to zero (if you are rendering "fake 3D" orthogonal tilemaps and not true 3D ones). Make sure that you translate them properly to the screen. If you are using the old fixed-pipeline OpenGL, you can simply translate the object like this //in the drawing routine void drawSomeObject() { int Z = 5; // from 1 up, if you want to use 1 too, lower "near" to 0.5 or something so the object is not clipped due to floating errors glTranslate(0,0,Z); //draw it somehow, e.g. using glBegin()/glEnd() glTranslate(0,0,-Z); }   The objects with higher Z value (i.e. farther from you) will be obscured by the objects with lower Z value if you do this.
  9. Rotating camera around an object

    Well... I am certainly not an oracle, so... Are you talking about 2D or 3D? Which programming language are you using and which graphics library/engine?
  10. Isometric tilemap rendering

    glOrtho() takes six parameters: left clipping plane, right clipping plane, a top one and a bottom one, and values of "near" and "far", respectively. What do the last two values mean? Other than being clipping planes, too (making the viewport of glOrtho() look like a cube in which you look into from one side), they are essential for making the depth buffer work. The depth buffer stores the values not in the linear sense, but we can roughly say that they are inversed (as in 1/depth), so the precision is lost only far away from camera where we don't see it. However, this is only "roughly" - the actual equation is much more precise and depends greatly on relationship of "near" and "far" values.   Your problem is that near is 0 in your case, that means that the relationship of "near" and "far" is zero division; that means you lose all of your depth buffer precision. The solution? Set near (the second-last parameter to glOrtho()) to 1.0. It is maybe not the only cause of your depth buffer problem, but it is certainly one of them.
  11. simple 3D game program

    Well, could you paste code which you have so far? We are not wizards and we have not seen your code, so we do not know what is wrong with it.