[QUOTE=bromvlieg;28294819]or
[cpp]
if (var < 0) var *= -1;
[/cpp][/QUOTE]
var = -var; would be better. Looks more readable and also should be faster.
[QUOTE=bromvlieg;28294819]or
[cpp]
if (var < 0) var *= -1;
[/cpp][/QUOTE]
No. Please don't ever do this. Every decent programming language has the math.abs function so this is completely unnecessary.
[QUOTE=ZeekyHBomb;28294725]Take the [url=http://download.oracle.com/javase/6/docs/api/java/lang/Math.html#abs(int)]absolute[/url] value.[/QUOTE]
Thanks very much!
[b]edit:[/b] Wait wait wait, but that would still draw top left to bottom right, I'd just be dragging the mouse in the opposite direction, because this is filling in the value for width and height (as opposed to giving it (x,y,x2,y2) you give it (x,y,w,h)). So I'd have to swap width and height with x and y to draw bottom right to top left. I think that's right, or am I being a bit dim? Either way I'll do some fiddling and if I get any more problems I'll take it WDYNHW. Thanks again!
[QUOTE=ZeekyHBomb;28294725]Take the [url=http://download.oracle.com/javase/6/docs/api/java/lang/Math.html#abs(int)]absolute[/url] value.[/QUOTE]
I made a bad joke:
[img_thumb]http://filesmelt.com/dl/badjoke1.png[/img_thumb]
..DevBug?
[QUOTE=ZenX2;28292039]I think I'm the only person in the world incapable of writing this FOV stuff.[/QUOTE]
Dont worry i cant either
[img]http://puu.sh/13Rv[/img]
There we go, it gets really easy after you get used to the whole physics + Drawing stuff! Now I have to add more stuff but that should be easier, at least I hope so.
[QUOTE=Hypershadsy;28292793]I assume it's something like "make all tiles invisible, and if the tile can draw a line to the player without hitting a solid object, and is less than x units away, make visible"
Crap, page king. Well, I don't have content because my project isn't in working condition, but this is certainly a motivation.
[editline]26th February 2011[/editline]
Writing a program with all these squiggly error underlines is like a person watching you make cookies and saying "Oh my god, ha! Those are gonna taste like shit. Oh god. You don't even have the butter in them yet! Where's all the brown sugar?!"[/QUOTE]
If I were writing an FOV algorithm, I'd do:
Draw 12 lines FROM the player, lighting each tile till I hit a wall.
Pick the furthest tile, and check if it can be seen. If it can mark all the tiles on the line seeable.
If not mark all the tiles on the line obscured.
[QUOTE=JenkinsJ;28294621]does anyone have any ideas?[/QUOTE]
Store a pair of points instead of width and height. The first point is where the user originally clicked, and the second point is where the user's mouse currently is.
When you actually draw the rectangle, just use some min/max magic to get a proper rectangle out of it:
[cpp]
int x1 = min(p1.x, p2.x);
int y1 = min(p1.y, p2.y);
int x2 = max(p1.x, p2.x);
int y2 = max(p1.y, p2.y);
int width = x2 - x1;
int height = y2 - y1;
drawRectangle(x1, y1, w, h);
[/cpp]
Speaking of FOV...
[img]http://i.imgur.com/YbgyB.png[/img]
It's a bit laggy, unfortunately. Also, I haven't been able to figure out how to easily display the obscured FOV (the dark areas in this image) to only the old visited areas outside the current FOV. Does anyone know how to do this?
Making an android app that involved using a pre-existing sqlite db (5 meg) it was extremely hard to actually get that into the APK and usuable, in the end had to rename it as .png to stop android compressing it.
[QUOTE=limitofinf;28296199]Store a pair of points instead of width and height. The first point is where the user originally clicked, and the second point is where the user's mouse currently is.
When you actually draw the rectangle, just use some min/max magic to get a proper rectangle out of it:
[/QUOTE]
Thanks, that did the trick!
[QUOTE=ZenX2;28292039]I think I'm the only person in the world incapable of writing this FOV stuff.[/QUOTE]
Take your lighting code which you have advertised in your avatar and re-implement it to cast from the player's position. For FOV you just remove the brightness falloff.
[editline]26th February 2011[/editline]
Also, here's a recreation of FOV and lighting code I've used in the past
[code]
//first, make every tile invisible
Vector2i[] sqaure = getSquare(playerPos, 15); //gets a symmetric square around the players position, 31 units wide (15*2 + 1)
for (int i=0;i<square.length;i++) //loop across every coordinate in the square
{
Vector2i[] line = getBresenhamLine(playerPos, square[i]); //gets an ordered bresenham line from the player to the current tile of the square
boolean tracing = true;
int i2 = 0;
while (tracing)
{
Vector2i pos = line[i2];
World.getTile(pos.x, pos.y).setVisible(true);
i2++;
if (World.isObstacle(pos.x, pos.y) || i2>=line.length) tracing = false;
}
}
[/code]
Remember kids, only update the FOV as needed.
Also, I use a square and not a circle because Bresenham lines aren't contiguous. If you use a circle, you'll get holes in your FOV where there should be none. Also, again, because your lines aren't contiguous, you'll be able to see through open corners. In some roguelikes you can walk diagonally through open corners.
EDIT: Here's what I mean by open corners:
[img]http://www.gamasutra.com/features/20010314/pinter_04.jpg[/img]
[QUOTE=Hypershadsy;28293731][img_thumb]http://dl.dropbox.com/u/21571661/xmlmap.png[/img_thumb]
After an hour of redoing how maps are read, I finally have terrain loading, parsing, ordering, and rendering working.
Behold the programmer art.[/QUOTE]
Thought of using smooth interpolation?
[QUOTE=Jookia;28295261]..DevBug?[/QUOTE]
You know it ;)
Why don't you guys just get the position of the player, divide it by tile dimension and then draw the the tiles around player differently?
[QUOTE=DevBug;28298288]You know it ;)
Why don't you guys just get the position of the player, divide it by tile dimension and then draw the the tiles around player differently?[/QUOTE]
They are, they just need to identify which tiles to draw differently.
[QUOTE=sLysdal;28297392]Thought of using smooth interpolation?[/QUOTE]
It's not final. Hence "programmer art".
Ey! What's wrong with that?
[url=http://dl.dropbox.com/u/11782997/rtest.png][img]http://dl.dropbox.com/u/11782997/rtest_thumb.png[/img][/url]
Minecraft map. It's kinda semitransparent atm, because it calculates an average color (including alpha) from the Minecraft terrain.png, and only draws the topmost blocks. Also those weird edges and seemingly rotated chunks and chunks "outside" of the map are not my fault. Been playing this world since alpha.
Just tried out the java version of eclipse, it's awesome. Is the C++ version the same quality or is it shit?
The lag in my program seemed to be caused by my unnecessarily calculating the FOV for every single angle. I'm currently incrementing the angle by 5 for each calculation now, and it runs smoothly. Also, I improved the FOV.
[img]http://i.imgur.com/GDvMU.png[/img]
[QUOTE=neos300;28301747]Just tried out the java version of eclipse, it's awesome. Is the C++ version the same quality or is it shit?[/QUOTE]
I remember feeling frustrated when I started using it because I wouldn't be able to build my programs, even with really simple code. I kept getting an error along the lines of "Couldn't compile; binary not found" with a "Hello, world" program, so I just gave up on it. I really should be using an IDE, though...
[QUOTE=spear;28302202]The lag in my program seemed to be caused by my unnecessarily calculating the FOV for every single angle.[/QUOTE]
You're using SDL, right? Are you sure it isn't the semi-transparent tiles (assuming that's what that is)? SDL transparency is really, really slow.
Tried to implement PP refractions today.
[img]http://i56.tinypic.com/9gy97a.jpg[/img]
It doesn't look right but I guess it will have to do for now.
Have looked for a tutorial to do it in PP but all the ones I found just used a cubemap or a texture which is quite disappointing.
So I had to improvise.
I could have some use of the tutorials that used a normal texture since in the end I'm using a 2D texture to displace the pixels.
So guys, I can test for a (2d) collision, but how would you 'rebound' from a collision?
I can get the objects velocity and apply forces ect. but I'm not sure what I should do.
[QUOTE=neos300;28302948]So guys, I can test for a (2d) collision, but how would you 'rebound' from a collision?
I can get the objects velocity and apply forces ect. but I'm not sure what I should do.[/QUOTE]
Make the force negative. That's just a simple way, though.
[QUOTE=BlkDucky;28302300]You're using SDL, right? Are you sure it isn't the semi-transparent tiles (assuming that's what that is)? SDL transparency is really, really slow.[/QUOTE]
The only transparent image I have is the player, so no. --Wait, I just realized that I'm stupid for not just making one semi-transparent black tile and then putting it over the others when they're out of the range of visibility. I actually have separate images for the out-of-range tiles. :sigh:
Apparently the rest of the forum thinks all the people in the Programming section are assholes :frown:
[QUOTE=CarlBooth;28303286]Apparently the rest of the forum thinks all the people in the Programming section are assholes :frown:[/QUOTE]
It's almost as if they aren't the same people!
Having a lot of problems. When I'm going to exit my application I want to release all the allocated data. But the program crash. "Windows xp crash report " or w/e it's called. I can't even find the problem really because I don't understand a shit. It seems like it's something wrong with glGenVertexArrays(1, &m_vertexArrayObject); because when I try to call:
[code]
glDeleteVertexArrays(1, &m_vertexArrayObject);
m_vertexArrayObject = 0;
[/code]
the program just crash after I called the winapi function to clear the window struct, HWND and so on.
What the hell should I do? :P
Can I even do m_vertexArrayObject = 0; after calling glDeleteVertexArrays() ?
[QUOTE=CarlBooth;28303286]Apparently the rest of the forum thinks all the people in the Programming section are assholes :frown:[/QUOTE]
We aren't?
[QUOTE=geel9;28303588]We aren't?[/QUOTE]
I don't think I was being an asshole when I helped you with all the Newgrounds Audio app stuff
Sorry, you need to Log In to post a reply to this thread.