Show Posts
|
|
Pages: [1] 2 3 ... 17
|
|
1
|
Game Development / Newbie & Debugging Questions / Re: Noise Problem
|
on: 2013-04-30 04:52:03
|
This is noise for java written by Perlin himself. It's what I use: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
| public final class Noise {
public static int seed = 100; private static final int P = 8; private static final int B = 1 << P; private static final int M = B - 1; private static final int NP = 8; private static final int N = 1 << NP; private static int p[] = new int[B + B + 2]; private static double g2[][] = new double[B + B + 2][2]; private static double g1[] = new double[B + B + 2]; private static double[][] points = new double[32][3];
static { init(); }
private static double lerp(double t, double a, double b) { return a + t * (b - a); }
private static double s_curve(double t) { return t * t * (3 - t - t); }
public static double noise(double x) {
int bx0, bx1; double rx0, rx1, sx, t, u, v; t = x + N; bx0 = ((int) t) & M; bx1 = (bx0 + 1) & M; rx0 = t - (int) t; rx1 = rx0 - 1;
sx = s_curve(rx0); u = rx0 * g1[p[bx0]]; v = rx1 * g1[p[bx1]];
return lerp(sx, u, v); }
public static double noise(double x, double y) {
int bx0, bx1, by0, by1, b00, b10, b01, b11; double rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v, q[]; int i, j;
t = x + N; bx0 = ((int) t) & M; bx1 = (bx0 + 1) & M; rx0 = t - (int) t; rx1 = rx0 - 1;
t = y + N; by0 = ((int) t) & M; by1 = (by0 + 1) & M; ry0 = t - (int) t; ry1 = ry0 - 1;
i = p[bx0]; j = p[bx1];
b00 = p[i + by0]; b10 = p[j + by0]; b01 = p[i + by1]; b11 = p[j + by1];
sx = s_curve(rx0); sy = s_curve(ry0);
q = g2[b00]; u = rx0 * q[0] + ry0 * q[1]; q = g2[b10]; v = rx1 * q[0] + ry0 * q[1]; a = lerp(sx, u, v);
q = g2[b01]; u = rx0 * q[0] + ry1 * q[1]; q = g2[b11]; v = rx1 * q[0] + ry1 * q[1]; b = lerp(sx, u, v);
return lerp(sy, a, b); }
static double noise(double x, double y, double z) {
int bx, by, bz, b0, b1, b00, b10, b01, b11; double rx0, rx1, ry0, ry1, rz, sx, sy, sz, a, b, c, d, u, v, q[];
bx = (int) Math.IEEEremainder(Math.floor(x), B); if (bx < 0) { bx += B; } rx0 = x - Math.floor(x); rx1 = rx0 - 1;
by = (int) Math.IEEEremainder(Math.floor(y), B); if (by < 0) { by += B; } ry0 = y - Math.floor(y); ry1 = ry0 - 1;
bz = (int) Math.IEEEremainder(Math.floor(z), B); if (bz < 0) { bz += B; } rz = z - Math.floor(z);
if (bx < 0 || bx >= B + B + 2) { System.out.println(bx); }
b0 = p[bx];
bx++;
b1 = p[bx];
b00 = p[b0 + by]; b10 = p[b1 + by];
by++;
b01 = p[b0 + by]; b11 = p[b1 + by];
sx = s_curve(rx0); sy = s_curve(ry0); sz = s_curve(rz);
q = G(b00 + bz); u = rx0 * q[0] + ry0 * q[1] + rz * q[2]; q = G(b10 + bz); v = rx1 * q[0] + ry0 * q[1] + rz * q[2]; a = lerp(sx, u, v); q = G(b01 + bz); u = rx0 * q[0] + ry1 * q[1] + rz * q[2]; q = G(b11 + bz); v = rx1 * q[0] + ry1 * q[1] + rz * q[2]; b = lerp(sx, u, v); c = lerp(sy, a, b); bz++; rz--; q = G(b00 + bz); u = rx0 * q[0] + ry0 * q[1] + rz * q[2]; q = G(b10 + bz); v = rx1 * q[0] + ry0 * q[1] + rz * q[2]; a = lerp(sx, u, v); q = G(b01 + bz); u = rx0 * q[0] + ry1 * q[1] + rz * q[2]; q = G(b11 + bz); v = rx1 * q[0] + ry1 * q[1] + rz * q[2]; b = lerp(sx, u, v); d = lerp(sy, a, b);
return lerp(sz, c, d); }
private static double[] G(int i) { return points[i % 32]; }
private static void init() { int i, j, k; double u, v, w, U, V, W, Hi, Lo; java.util.Random r = new java.util.Random(seed); for (i = 0; i < B; i++) { p[i] = i; g1[i] = 2 * r.nextDouble() - 1;
do { u = 2 * r.nextDouble() - 1; v = 2 * r.nextDouble() - 1; } while (u * u + v * v > 1 || Math.abs(u) > 2.5 * Math.abs(v) || Math.abs(v) > 2.5 * Math.abs(u) || Math.abs(Math.abs(u) - Math.abs(v)) < .4); g2[i][0] = u; g2[i][1] = v; normalize2(g2[i]);
do { u = 2 * r.nextDouble() - 1; v = 2 * r.nextDouble() - 1; w = 2 * r.nextDouble() - 1; U = Math.abs(u); V = Math.abs(v); W = Math.abs(w); Lo = Math.min(U, Math.min(V, W)); Hi = Math.max(U, Math.max(V, W)); } while (u * u + v * v + w * w > 1 || Hi > 4 * Lo || Math.min(Math.abs(U - V), Math.min(Math.abs(U - W), Math.abs(V - W))) < .2); }
while (--i > 0) { k = p[i]; j = (int) (r.nextLong() & M); p[i] = p[j]; p[j] = k; } for (i = 0; i < B + 2; i++) { p[B + i] = p[i]; g1[B + i] = g1[i]; for (j = 0; j < 2; j++) { g2[B + i][j] = g2[i][j]; } }
points[3][0] = points[3][1] = points[3][2] = Math.sqrt(1. / 3); double r2 = Math.sqrt(1. / 2); double s = Math.sqrt(2 + r2 + r2);
for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { points[i][j] = (i == j ? 1 + r2 + r2 : r2) / s; } } for (i = 0; i <= 1; i++) { for (j = 0; j <= 1; j++) { for (k = 0; k <= 1; k++) { int n = i + j * 2 + k * 4; if (n > 0) { for (int m = 0; m < 4; m++) { points[4 * n + m][0] = (i == 0 ? 1 : -1) * points[m][0]; points[4 * n + m][1] = (j == 0 ? 1 : -1) * points[m][1]; points[4 * n + m][2] = (k == 0 ? 1 : -1) * points[m][2]; } } } } } }
private static void normalize2(double v[]) { double s; s = Math.sqrt(v[0] * v[0] + v[1] * v[1]); v[0] = v[0] / s; v[1] = v[1] / s; } } |
|
|
|
|
|
4
|
Discussions / General Discussions / Re: A New Approach to Databases and Data Processing — Simulating 10Ks of Spaceships
|
on: 2013-03-01 01:49:00
|
|
I read that post from the Hacker News link. I disagree with what you imply about Java not being a language designed for concurrency. Defining "designed for concurrency" as "doesn't have mutable state" is a religious argument, not a technical one. Mutable state is has potential downfalls compared to immutable state but it's also less efficient. This is a technical trade off, not a issue of capability nor appropriateness.
|
|
|
|
|
6
|
Java Game APIs & Engines / Tools Discussion / Re: Spine: 2D skeletal animation
|
on: 2013-01-04 08:26:53
|
Oh my God!
You and people like you disparage the whole work of Open Source community, this is a shame. Although it is really great what you've done, but this just is not fair, that you take someone's work and willingness to share their work to the community, and with that you want to earn money.http://www.youtube.com/watch?v=uFMMXRoSxnA There's nothing wrong with making money from OSS. You are simply factually incorrect. I like RMS but he's not trying to create a world in which software engineers can't make money, he's trying to create a world in which software cannot restrict your freedoms. I'd suggest you learn a little about OSS before you open your mouth again. And quite frankly, as the author of some great OSS software which other's have profited from, I think you should apologise to Nate.
|
|
|
|
|
11
|
Java Game APIs & Engines / Java 2D / Re: GUI for active rendering in Java2D
|
on: 2012-12-01 14:09:10
|
|
Thanks for the suggestions, guys.
I decided not to go for the idea of having the active rendered content on another panel - that doesn't work for my design.
@noblemaster: yeah, I've read that stuff already: it doesn't work, or at least it didn't for me.
I've gone with refactoring the code into LWJGL code, rather than compromising the design. It's been pretty easy: I just set the viewport upside down and the coordinates are all the same as the Java2d version so the code is happy.
|
|
|
|
|
14
|
Java Game APIs & Engines / Java 2D / GUI for active rendering in Java2D
|
on: 2012-11-29 02:53:23
|
|
I wrote a basic little artillery game in Java2D which runs well and looks pretty good. Then I went to add some GUI elements to it. Swing doesn't really work under active rendering. Does anyone know of any good GUI toolkits that will work with active rendering?
Not the end of the world if there's nothing available - I'll just convert the code to libgdx or lwjgl. That said, it runs great now so I'd like to avoid rearchitecting unless I absolutely have to.
|
|
|
|
|
17
|
Discussions / General Discussions / Re: Java is pretty cool
|
on: 2012-10-30 01:05:10
|
|
Heh. Another one of these threads.
I agree with Cas: Javascript is shit. I earn a living writing Javascript and I loathe it. It is definitely the best tool for writing web apps, but that's damning with faint praise. It's nightmarish to maintain, it has the performance of an drunk encephalitic tapeworm and about as much charisma. If you write little toys with it, it's fine but it scales badly. You try having a giant code base and then something breaks and you get no warnings whatsoever and when you do get an error it's nowhere near the actual problem. A nightmare.
Any language that can't even do 'include' is pretty f**ked IMO.
|
|
|
|
|
20
|
Discussions / General Discussions / Re: Tremble, mortals! I have enslaved your administrator
|
on: 2012-10-01 12:24:27
|
It is with sinister pleasure that I announce the enslavement of your humble administrator Riven in Puppygames' cellar. Riven has now quit his full-time job in order to make tea for me whenever I so command it. By nights he dreams of becoming a rock star games programmer, so he writes code for Puppygames now. The results of our efforts will hopefully be available in about 6 months time. Normal service is likely to be interrupted as I will thrash him with a willow switch if he strays from his giant task-list and tea-making duties. When he returns you may release ra4king from his cage and give him some water. That is all. Cas  Awesome! Congrats to both of you, but please let Riven out of his Gimp suit occasionally to take care of JGO 
|
|
|
|
|
21
|
Discussions / Miscellaneous Topics / Re: I'm back!
|
on: 2012-10-01 11:07:36
|
I don't know if many noticed, but the past 2-3 weeks I've been mostly off of JGO. Reddit and school (mostly Reddit) have fully engulfed my life! I had over 130 unread threads and I never thought I'd see this day again:  Anyway: I've lost all motivation to program and do anything other than waste time on the internet. I haven't opened Eclipse since September 8..... Hey bro! Totally know what you mean about motivation. I was working on a game which was going nicely. I've always wanted to have deferred rendering for the lighting solution. I've got all the multi-render-target stuff working but I'm stuck on the lighting phase. I'm right out at the edge of my GL knowledge here and the inability to debug the shader phase is super frustrating. I get stuck reading Reddit and playing Battlefield 3 to avoid the frustration of not moving the code on... which of course means I don't move the code on which makes me MORE frustrated! Arrrgh! I'm trying to get back into it tonight. No Reddit/BF3 for me tonight! 
|
|
|
|
|
22
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-09-28 00:50:15
|
|
Aaahh! Ok, thanks for the clarification - I get where we diverge now - mainly around the use of the '*' character. I guess the larger issue here is that we don't have a number of characters available to use for overloading which means that we're always compromising somewhat. It's this element of compromise which always disappoints me with operator overloading.
|
|
|
|
|
23
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-09-27 01:30:51
|
Funny thing about primitives: they're a compiler optimization, they need not be exposed at the language level. Smalltalk has never really had them, and most of Java's JIT technology came from smalltalk derivatives (Self and Strongtalk). Scala also doesn't have them, yet it also emits bytecode that uses primitives -- in fact, because of annotations like @specialized, it's able to do so in more places than Java.
Java did not start out with JIT at all, and therefore did not launch with many ambitions to advance the state of its compiler to leave out the primitive/object distinction or even blur it in any way.
Sure you can still hand-optimize quite a lot of code with primitives ... just like you can if you wrote everything in C.
This is the reason I said in a previous thread about Java that I'd have preferred that the language didn't have the primitive / type class split. It seems unnecessary given a smart enough compiler.
|
|
|
|
|
24
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-09-27 01:24:16
|
... uses this notation for cross product: a X b, which is precisely what I referring to - that is that standard notation for the multiplication operation.
In arithmetic sure. 10×5. Or sometime when you're abstractly talking about some (potentially unspecified) field, but then again it's almost as common to use a 'dot' as well. But we're talking about a specific algebra: Standard notation for vectors: let small letters be scalars and capitals be vectors: product of a vector with a scalar: sV (no cross symbol) cross product: A×B dot product: A.B product: AB - Doesn't exist..it isn't representable in terms of vector We must be talking across purposes. All I have been claiming is that A x B is the standard notation for vector cross product - which you seem to have agreed with. I also claimed that A x B is usually "a * b" in programming languages and therefore "a * b" would be an obvious choice for overloading vector cross product (esp. since you can't overload the 'x' character) I also claimed that the '*' multiplication operator when overloaded often inherits it's programming language level precedence. I also claimed that programming level precedence doesn't always map correctly to various mathematical domains thereby creating a problem representing maths in code using operator overloading. I don't know why you've kept going on about inner / outer products, scalar/Vector multiplication or Vector multiplication OF ANY KIND. I'm not discussing any of those cases, I'm just discussing "A x B" with vectors, the cross product of A and B. If you want to disagree with me, can you disagree with one of the points I actually made rather than making up straw men of your own? regarding Mathematica: I asked you for a mathematical reference showing that A x B has a different precedence in the context of Vector maths than A + B, not a programming reference. It was a simple enough request I believe. All of your verbiage related to Mathematica is simply restating your intuitions - the very ones I asked for a reference for in the first place.
|
|
|
|
|
25
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-09-26 01:34:52
|
|
@Roquen: Mathematica is a programming environment for mathematics. The choices made there are just programming language choices and don't constitute a mathematical reference.
The reference you referred to (Wikipedia) uses this notation for cross product: a X b, which is precisely what I referring to - that is that standard notation for the multiplication operation.
@Cas: there's really very little difference from "a = a dot b" and "a = a.dot(b)", so... would a change like that be worth it?
|
|
|
|
|
27
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-09-24 03:49:36
|
I don't understand why this kind of thread is going on AGAIN.....but I'll just repost sproingie's brilliant post: Gosh I bet we'll convince everyone this time around.  You know, no-one is actually forcing you to read the thread  False. My OCD is forcing me to  Haha. 
|
|
|
|
|
28
|
Discussions / General Discussions / Re: Universal Programming Language (UPL)
|
on: 2012-09-24 03:38:22
|
XMLVM is probably the daftest most esoteric idea around. Every time I read back the concept to myself in my head I just end up shaking it slowly, bemused. Reminds me of the story about the king, the toaster, and the software engineer again. Cas  I've never heard that story. Care to share? 
|
|
|
|
|
29
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-09-24 03:33:09
|
I don't understand why this kind of thread is going on AGAIN.....but I'll just repost sproingie's brilliant post: Gosh I bet we'll convince everyone this time around.  You know, no-one is actually forcing you to read the thread 
|
|
|
|
|
30
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-09-24 03:31:27
|
@kaffiene: To me it seems like most people seem to base their opinion on C++ operators and a very high percentage without any real first hand experience. I've no knowledge of scala so I cannot really comment on that implementation. I look more to mathematical DSLs than any general purpose language for reasonable operator overloading.
I was programming C++ before an official spec was released. When I started with it, it was a bunch of pre-processors for a C compiler (SAS-C, in my case). I do have a reasonable amount of experience with the C++ case, but most of my issues with operator overloading are to do with the fact that you can't actually properly represent a mathematical domain properly in code anyway (due to issues about what operators are available and their existing meanings and precedence in code) (1) Can't tell at a glance what a = b + c means without knowing the types of a,b,c and reading their definitions if they're classes
Not having operators doesn't change this fact. With or without the situation is identical. No, it isn't. Without overloading "a = b + c" is definitely an operation that does not involve classes and the definitions of a, b and c do not need to be read to understand the statement. If you see "a.set(b.plus(c))" you know instantly that a,b and c are classes and you *will* have to read the code (2) Operators inherit precedence from primitives even if it's no longer appropriate (e.g.: Vectors: a * b (cross product) should have the same precedence as a + b (addition) but the cross product gets higher prescendence because it inherits the precedence of multiplication.
I've always seen inner and outer products having higher president than add/sub. I cannot see any logical argument to give them the same. But ultimately that's a different story because the outer product of vector analysis isn't a product so why overload the product operator in the first place? And besides some language do indeed allow user defined prescience rules...but that's a different can of worms and something that the vast majority of people would totally hate. Personally I'm not in favor of. If you check: http://en.wikipedia.org/wiki/Vector_calculus#Vector_operationsYou will see that Vector cross product being defined as "multiplication of two vector fields, yielding a vector field" "I've always seen inner and outer products having higher president than add/sub. I cannot see any logical argument to give them the same." Show me a reference where vector cross product gets higher precedence. Wikipedia Vector calculus page doesn't mention that. Neither does Wolfram, nor any other reference I've ever read. (3) You can't all the operators you want. E.g. Vector dot product: I can't have a . b for vectors.
No argument...more operators is all good. If fact many algebras need many operators for operator overloading to be of any real usage. Example Clifford algebra pretty much needs product, geometric inner and outer products, Euclidean inner and outer products and multiple conjugates to be generally useful. But really this is a different issue. It's important because the main argument for Operator Overloading is that you should be able to represent the mathematics properly, but in practice you actually can't. If you can't do it properly the whole *reason for* operator overloading is undermined. I would never use * for cross product.
Nor should you as it's not a product. It's an outer product, specifically: (ab-ba)/2...as such overloading product is an illogical choice. Only being about to choice from basic operators, then the only logical choice is "^" as the wedge product is a semi-standard notation for outer products. (SEE: later) The multiplication operator is the STANDARD operator used for cross product. Check that Wikipedia reference, or ANY Wolfram page on Vector maths.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|