Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 4
1  Game Development / Game Mechanics / World to screen coordinates on: 2014-04-30 06:52:16
Hi all, I've just got a quick question relating to converting world coordinates to screen coordinates. I've got a code snippet below that's written in javascript rather than java, but it should be fairly understandable. My issue is that I'm performing a 3D perspective projection, but this function allows for points that are behind the camera (off the screen) to still be rendered. I'm wondering whether there's a check that I can perform to check whether the point in question is outside of the view. I know it's not a very good way of doing this. :p I'm just playing around trying to get something made. If anyone knows how I perform this check I'd appreciate your help. Thanks

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  
var xOffset = canvas.width >> 1;
var yOffset = canvas.height >> 1;

function world_to_screen(x, y, z) {
   // Vert relative to camera position
  var rel_x = x - xCam;
   var rel_y = y - yCam;
   var rel_z = z - zCam;

   // Vert relative to camera orientation
  var c = Math.cos(yRot * (Math.PI / 180.0));
   var s = Math.sin(yRot * (Math.PI / 180.0));
   var orient_x = c * rel_x + 0 * rel_y - s * rel_z;
   var orient_y = 0 * rel_x + 1 * rel_y + 0 * rel_z;
   var orient_z = s * rel_x + 0 * rel_y + c * rel_z;

   var proj_point = persp_point(orient_x, orient_y, orient_z);
   var screen_x = ((proj_point[0] * canvas.height) | 0) + xOffset;
   var screen_y = ((proj_point[1] * canvas.height) | 0) + yOffset;

   return [screen_x, screen_y];
}

function persp_point(x, y, z) {
   return [x / z, y / z];
}
2  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 20:54:15
All works great. Cheesy Thanks for everyone's help. Hey UprightPath, when you say the next shortest path, wouldn't that always be greater than the shortest path? Also, do you know how I would solve that problem?
3  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 20:33:13
Thanks for all your help. Smiley I'll try this out and reply back.
4  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 16:24:02
Yeah, I've tried adding in a few print statements to help shed some light but it's a bit overwhelming and I'm not sure what I'm supposed to be looking for. Sad
5  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 16:09:53
All the tutorials I've looked at have told me to add the start node to the open list. :x
The start node is removed almost immediately because it is the node with the lowest f value in the open list and that node is removed at the beginning of the loop.
6  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-14 15:50:22
Hi all, I'm just trying to implement this algorithm that I've mentioned above, but it seems to be stuck loading endlessly.

Here's my source: http://www.java-gaming.org/?action=pastebin&id=896

At the moment I'm declaring it with the start and goal nodes set to (0, 0) and (10, 5) respectively. Can anyone spot the reason why it's loading out?

Thanks!
7  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-09 23:36:50
Thanks guise. Smiley
8  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-09 23:36:31
Oh yeah, of course. Tongue That makes sense. Sorry for not getting that's what you meant, Riven. :x I'm knackered today.
9  Game Development / Game Mechanics / Re: A* path finding on: 2014-04-09 23:12:07
Oh, I think I originally misread the pseudo code. Am I right in thinking the path is in the closed list once this has ended?
10  Game Development / Game Mechanics / A* path finding on: 2014-04-09 22:55:02
Hi all,

I don't mean to create a topic regarding the exact same subject as another topic on the front page, but I didn't want to hijack their's. :p
Anyway, I've been implementing A* path finding from a tutorial found here: http://web.mit.edu/eranki/www/tutorials/search/
I've been going off the algorithm detailed at the bottom of that page and was just wondering where the final path is.
In other implementations of this algorithm, there was an open, closed and final path list. I understand most of the algorithm, but once it's been designed, how do I access the final list of nodes?

Thanks Smiley
11  Game Development / Newbie & Debugging Questions / Re: Bresenham's line algorithm on: 2013-10-15 23:13:08
Ah, I see why it's 1. :x Sorry, didn't read the preceding paragraph clearly enough.
12  Game Development / Newbie & Debugging Questions / Re: Bresenham's line algorithm on: 2013-10-15 21:41:19
Hey guys, thanks for the replies and sorry to resurrect an old topic, but I just have one quick question about the floating point method. Smiley Here's the article I'm referring to again:
http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

My question is, after the error exceeds 0.5 and the Y component is increased, why is the error decreased by 1? I understand why it's decreased, but what is the significance of decreasing it by 1 exactly?
13  Game Development / Newbie & Debugging Questions / Bresenham's line algorithm on: 2013-09-18 23:28:15
Hi all, I've just found a Javascript implementation of the Bresenham's line algorithm and I'm just trying to understand what it's actually doing and was wondering whether anybody would mind giving me a brief explanation about a few lines of it.

Here's the algorithm itself:

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  
function renderLine(x0, y0, x1, y1) {
    var xx0 = x0;
   var yy0 = y0;
   var xx1 = x1;
   var yy1 = y1;
   
   var dx = Math.abs(xx1 - xx0);
   var dy = Math.abs(yy1 - yy0);
   
   var stepx, stepy;
   if(xx0 < xx1) stepx = 1;
   else stepx = -1;
   if(yy0 < yy1) stepy = 1;
   else stepy = -1;
   
   var err = dx - dy;
   while(true) {
      renderPoint(xx0, yy0);
      if(xx0 == xx1 && yy0 == yy1) break;
      [b]var e2 = err << 1;
      if(e2 > -dy) {
         err -= dy;
         xx0 += stepx;
      }
      if(e2 < dx) {
         err += dx;
         yy0 += stepy;
      }[/b]
   }
}


The section I'm having difficulty getting my head around is emboldened. I understand from reading the wikipedia page on the different methods of implementing it that you create an error variable and loop through every value between the two points X components, then you add the slope of the line to the error until it reaches over 0.5 and then you increase the Y component and subtract 1 from the error. I also understand that this is more or less what's happening above using integer arithmetic rather than floating point arithmetic although I'm not entirely sure why error needs to be multiplied by 2 or what the significance of this being over -dy or under dx is. Forgive my noobiness - I'm just stuck with this. Tongue If anyone could explain this I'd be grateful.

Thanks
14  Game Development / Newbie & Debugging Questions / Rotation around an arbitrary axis on: 2013-08-16 04:54:22
Hi all,
Just got an issue with a 3D first person view I'm trying to create for use with LWJGL. I've got 3 vectors representing the side, up and forward axes set at (1, 0, 0), (0, 1, 0) and (0, 0, 1) respectively. When rotating the view I perform a "rotation around an arbitrary axis" about the vector representing the axis I want.
It's all working as expected, but I want the camera to rotate around a fixed Y axis (0, 1, 0) as it does in most FPS games, but at the moment it's just rotating around the up vector, whichever way it's pointing. The issue here is that X axis rotations changed the direction of the Y axis, so it won't stay at (0, 1, 0). Is there any way around this? Here's my current camera class for reference: http://www.java-gaming.org/?action=pastebin&id=684
Thanks in advance for any help Smiley
15  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-13 03:32:22
Thanks for the reply. Smiley Yeah, all I remember from secondary school with regards to quadratic equations was that formula. I'm just trying to look at the other methods of solving it to help me get a better understanding. Completing the square is the method that I recall the teacher saying takes too long to work out in an exam. Hurray for the British education system. D: So now I'm trying to learn it on my own and struggling a bit.
16  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-13 03:18:43
Old enough for it to be embarrassing. ): I'm alright with other areas of algebra. This has just stumped me.
17  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-13 02:18:55
Yeah, I keep re-reading this instructions thinking I'm missing a subtle wording, but that step completely throws me. The other steps are fairly trivial.
18  Discussions / Miscellaneous Topics / Re: Quadratic equations on: 2013-06-13 01:55:04
Thanks for the replies guys! So Geemili, is what I described just FOIL in reverse?
19  Discussions / Miscellaneous Topics / Quadratic equations on: 2013-06-13 01:39:40
Hi all, I'm trying to learn how to solve quadratic equations but I've ran into a problem.
On the wikipedia page: http://en.wikipedia.org/wiki/Quadratic_equation
It explains the step by step process of solving a quadratic equation using the "Complete the square" method. The fourth step states: "Write the left side as a square, and simplify the right side, if necessary."
And this appears to change the expression "x² + 2x + 1" into "(x + 1)²" and I'm not exactly sure how that's come about. Could somebody explain it to me?

Thanks!

Paul
20  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-07 00:43:25
Thanks. Smiley I'll substitute it.
21  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-07 00:32:23
Thanks for your help. Smiley I'll have a sit down and try and understand it.
22  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-07 00:20:10
Thanks for the reply. That seems to work far better. Smiley It's just that it looks very bright. The image becomes saturated by light.
23  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-06 19:23:01
Ah I see. Do you know how I would apply this to my algorithm?
24  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-06 18:36:38
Yeah the threshold values range from 1-64, so presumably it breaches its respective channel fairly often which explains the artifacts, but I'm not entirely sure how to normalise the threshold value. I've tried dividing the value by 64, which is the highest value that is held in the matrix, although I'm working in whole numbers and only one instance would yield 1 and the rest would be 0.
25  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-06 16:17:30
The closest colour rounding seems to actually be working before adding the threshold. As the colour's stored as an integer it performs the division first and rounds that result and then multiplies. So the end value is actually floored to the nearest 64 in this case. For example:

140 / 64 * 64
2 * 64
= 128

So 140 becomes 128 when floored to the nearest 64. Sorry if I'm teaching you how to suck eggs, I'm just making sure.
26  Game Development / Newbie & Debugging Questions / Re: Bayer ordered dithering on: 2013-05-05 13:50:16
Just updated with a screenshot of the problem: http://i.imgur.com/9SWukYS.png
Posting this just so you guys can see how it's producing effectively the right results, just with slightly skewed channels.
27  Game Development / Newbie & Debugging Questions / Bayer ordered dithering on: 2013-05-04 18:39:08
Hi all, I'm attempting to add a stylised order dithering effect on an image although I've been met with unexpected results. I have an 8 by 8 threshold matrix as follows:

1  
2  
3  
4  
5  
6  
7  
8  
int[] dither = new int[] { 1, 49, 13, 61, 4, 52, 16, 64, 
            33, 17, 45, 29, 36, 20, 48, 32,
            9, 57, 5, 53, 12, 60, 8, 56,
            41, 25, 37, 21, 44, 28, 40, 24,
            3, 51, 15, 63, 2, 50, 14, 62,
            35, 19, 47, 31, 34, 18, 46, 30,
            11, 59, 7, 55, 10, 58, 6, 54,
            43, 27, 39, 23, 42, 26, 38, 22 };


I just found this on the wikipedia page for ordered dithering and have been following the explanation in order to produce this effect myself. The algorithm producing the effect from this matrix is as closely resemblant of that explained in the wikipedia page and is as follows:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
int w = image.getWidth();
int h = image.getHeight();
int bd = 64;
for(int y = 0; y < h; y++) {
   for(int x = 0; x < w; x++) {
           
      int c =  pixels[y * w + x];
      int d = dither[(y & 7) * 8 + (x & 7)];
           
      int r = ((c >> 16) & 0xff) + d;
      int g = ((c >> 8) & 0xff) + d;
      int b = (c & 0xff) + d;
           
      newpix[y * w + x] = 0x000000 | closestCol(r, bd) << 16 | closestCol(g, bd) << 8 | closestCol(b, bd);
           
   }
}


This is just the method that reduces the amount of colours available in each channel:
1  
2  
3  
private int closestCol(int c, int b) {
   return c / b * b;
}


The above code simply adds the corresponding value from the threshold matrix to the image data and then attempts to find the nearest colour to it after rounding. The issue is that the dither values are quite high and saturate the channel of the pixel. I've tried averaging the channel colour with the corresponding dither value but that makes the screen far darker than it should be. Is there a detail that I'm missing whereby it adds the effect without harshly altering the tone of the image?

Just for reference, I've been consulting with this page: http://en.wikipedia.org/wiki/Ordered_dithering

Here's a before and after dither comparison so you can see the results: http://i.imgur.com/9SWukYS.png

Thanks,

Paul
28  Game Development / Game Play & Game Design / Re: Trying to pixelate a section of an image on: 2013-04-18 23:04:04
I've sorted it now. Previously I'd made a magnification method and I think I borrowed too much logic from it. The working solution just loops through the outer for loops in steps the size of the block size. Then an inner set of nested for loops samples each of the pixels in that block, finds the average colour and then loops through them setting each to the colour of the average.
It's not the best solution but I'll post it here in case anyone needs a starting point.

http://www.java-gaming.org/?action=pastebin&id=545
29  Game Development / Game Play & Game Design / Re: Trying to pixelate a section of an image on: 2013-04-18 21:24:31
Thanks for both your replies. Smiley I've substituted the single colour divides and used the components and it works great. I was just also wondering whether the magnification of the image is expected or whether I've glossed over another detail. :p Normally when I see pixelation the area of the image that's been pixelated is to scale with the rest of the image.
30  Game Development / Game Play & Game Design / Trying to pixelate a section of an image on: 2013-04-18 20:38:12
Hi all, I've been looking around for a premade algorithm to pixelate an image or something similar that I could expand on although I've only been able to find descriptions of the algorithm so I've attempted to make it. What it does is loops through every pixel in a BufferedImage, loaded from a 16-bit PNG image file (byte for each component) and it divides the current X and Y components by the square size . From here it performs a further nested for loop to total the pixel colours in the block that this pixel is in.

It then divides by the block size, which is represented by the "pp" field, except it's squared because it samples pixels in a square along the X and Y axes. According to a few explanations I've read this should give me the average pixel colour for this block and every pixel in this block should be coloured in it. The algorithm I've written works somewhat in that the general shape of the image is preserved after the pixelation with far less detail, as is expected. The problem is that the colours are completely wrong and I'll show you how in the image below:

http://i.imgur.com/Ezfp4W8.png

Here there's just a picture of a hamster I found. The algorithm magnifies the area by a sort of scale factor.

Also here's the algorithm:

http://www.java-gaming.org/?action=pastebin&id=544

Can anyone spot why the colours aren't averaging out right?

Thanks

Paul
Pages: [1] 2 3 4
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (22 views)
2014-07-24 01:59:36

Riven (21 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (53 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!