Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (789)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3 4 ... 10
 11 
 on: 2019-05-16 22:32:20 
Started by CopyableCougar4 - Last post by orange451
@DesertCookie

Assimp's aiImportFile can take a ByteBuffer input. Surely you could read a file in your jar (as a URL) to a ByteBuffer and pass it in?

 12 
 on: 2019-05-16 10:07:26 
Started by CopyableCougar4 - Last post by DesertCookie
Have you found a working way to load model files from within the jar file?

 13 
 on: 2019-05-15 21:09:15 
Started by FabulousFellini - Last post by VaTTeRGeR
Quote
just resize the window and it works. Definitely not the case here.

Errmm ... it actually is that simple, you just resize and update your viewport in that resize method that gets called automagically and you're set Cheesy

This is the super condensed version:

1  
2  
3  
4  
5  
6  
7  
@Override
public void resize(int width, int height) {
    // Viewport => How much of your world you want to display in the window.
    // You basically use this to adjust after a resize and for zooming in/out. This has no effect on the camera position/rotation.
    viewport.setWorldSize(viewportWidthInWorldUnits , viewportHeightInWorldUnits);
    viewport.update(width, height, true);
}


That's literally it. Don't forget to set your sprite sizes in world units though, that's another easy mistake.

 14 
 on: 2019-05-15 20:57:06 
Started by FabulousFellini - Last post by FabulousFellini
Ok thanks!  I'll try some of this out and see what's up.  Thanks man!  I thought it would be easier than this lol.  I.E. just resize the window and it works.   Definitely not the case here.

 15 
 on: 2019-05-15 20:39:21 
Started by FabulousFellini - Last post by VaTTeRGeR
This stuff is taken directly from my game project and it should work for you and also explain some concepts.

First you need to setup your Camera and Viewport, the Scaling mode is important, read the LibGDX-Wiki and test some Scaling modes yourself to see the difference:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
private void setupCamera() {
   
   camera = new OrthographicCamera();
   
   // ww and hw are your world width and height in world units (meters for example!)
   // Read the LibGDX Wiki on viewports and try different types
   viewport = new ScalingViewport(Scaling.fit, Metrics.ww , Metrics.hw, camera);
   
   // [...]
   
}



Then you need to calculate your viewport size, do this in your games resize-method, it is called when needed by LibGDX, read the Wiki if you need to know more:
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  
@Override
public void resize(int width, int height) {
   
   // width and height of the window in pixels
   Metrics.wv = width;
   Metrics.hv = height;
   
   // I want 1:1 texel to pixel mapping on screen for zoom=1.
   // You can choose how much of your world you show here, you could also choose a constant width OR height in meters instead.
   // world width and height in meters
   // window_width_in_pixels * zoom / pixel_per_meter
   Metrics.ww = Metrics.wv * camController.getZoom() / Metrics.ppm;
   // window_height_in_pixels * zoom / pixel_per_meter
   Metrics.hw = Metrics.hv * camController.getZoom() / Metrics.ppm;
   
   // World viewport uses world coordinates (meters) so we pass ww (WidthWorld) and hw (HeightWorld).
   viewport.setWorldSize(Metrics.ww , Metrics.hw);
   // Always input your screen width and height
   viewport.update(Metrics.wv, Metrics.hv, true);
   
   // My stage on the other hand uses pixel coordinates so i pass wv (WidthView) and hv (HeightView).
   stage.getViewport().setWorldSize(Metrics.wv, Metrics.hv);
   // Always input your screen width and height
   stage.getViewport().update(Metrics.wv, Metrics.hv, true);
}


Now the fun part, getting the position in world coordinates where the mouse pointer is:
1  
2  
3  
4  
5  
6  
7  
8  
// v get's overwritten and returned
public static Vector3 mousePositionInWorld(Vector3 v, Camera camera) {

   v.set(Gdx.input.getX(), Gdx.input.getY(), 0f);
   camera.unproject(v);

   return v;
}


Getting the screen-position in pixels from a point in your game world:
1  
2  
3  
4  
5  
6  
7  
// v should contain the world position you want to convert
public static Vector3 worldToScreenPosition(Vector3 v, Camera camera) {

   camera.project(v);

   return v;
}


The most important step is to always update your viewport! This works irrespective of screen size, fullscreen or not.

 16 
 on: 2019-05-15 18:13:54 
Started by Speiger - Last post by Speiger


I used a different terrain for that but this seems to look correct.

 17 
 on: 2019-05-15 17:56:13 
Started by FabulousFellini - Last post by FabulousFellini
What's the best way to do this?  I've read it's done by converting world coordinates to screen coordinates.  I've also read you can use camera.unproject().    (I'll be honest and haven't tried anything yet, I just wanted to have something to go off of when I get off work).  I want to try the camera.unproject method.  Does this method go into the resize() method in LibGDX?  Or do I call unproject when the mouse actually clicks if the game is full screen?   

Basically, the problem is my screen size is set for Android-like, and I have an inventory screen where you can click on different weapons to select which weapon you want to use.  But if the screen is resized, this all breaks and you can't click on anything to select inventory (not even where the original coordinates started...so basically if you resize the screen to full screen and click on where the inventory should be before resizing, that doesn't work either)  Is there something I'm missing?  Thanks and have a good day Smiley

 18 
 on: 2019-05-15 16:23:07 
Started by Speiger - Last post by philfrei
If you have time and inclination, it would be neat to see a picture of the corrected version.

 19 
 on: 2019-05-15 09:47:16 
Started by Speiger - Last post by Speiger
Em yeah a friend of mine and me have solved that problem.
A 2x2 grid check of the vertex was not enough to get the amount of detail so we decided to switch to a 3x3 grid check.

That alone did not give enough good results so we came up with a solution to fix this problem at least a lot better.
This solution only handles like 99.5% of the cases (only extreme edge cases are left that you can not directly detect in this system)

The solution was to generate all possible cases automatically and evaluate them manually.
Since we had a 3x3 grid that was 8 bits of data around that point of interest. Well technically 16 bit since we have to see the difference between is higher & is lower.

That was not really hard. Setting up a UI that asks you is this ok or does it need to be rotated was pretty simple. After that it was around 1 hour sitting there pressing 2-3 buttons constantly to say: Yay/Nay (I felt like monkey push button to get reward xD)

That resulted out of the 65k cases that there were like 2.6k broken cases that needed to be rotated.
It was a long list.

I leave the code here if other people have close issues with that kind of system.
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  
//Calculates if the Vertex needs to be rotated to look nice in the map.
public int calculateVertexState(int x, int y)
{
   int index = createIndex(x, y);
   if(index == 109) //Edge Case where i needed to check what vertex rotation comes directly after that.
   {
      return createIndex(x + 1, y + 1) == 110 ? 1 : 0;
   }
   else if(index == 115)//Edge Case where i needed to check what vertex rotation comes directly after that.
   {
      return createIndex(x + 1, y + 1) == 118 ? 1 : 0;
   }
   //ROTATION_CACHE is just a IntSet(FastUtil)/Set<Integer> with all the possiblities that i had manually selected
   return ROTATOR_CACHE.contains(index) ? 1 : 0;
}

//Creates a Bit Based index around the vertex that needs to be checked. (Right=>Left)First 8 Bits are if the terrain is higher then the vertex to check. Second 8 bits are if they are lower then the vertex to check.
public int createIndex(int x, int z)
{
   int height = getHeight(x, z);
   return getMultiFlag(x, z, height, 0, true) | getMultiFlag(x, z, height, 8, false);
}

//Helper function to reduce code size. It Just creates a 8 Bit Number the represents the HeightDiffereces
private int getMultiFlag(int x, int z, int height, int bitOffset, boolean up)
{  
   return getFlag(x - 1, z - 1, height, bitOffset, up) | getFlag(x, z - 1, height, bitOffset+1, up) | getFlag(x - 1, z, height, bitOffset+2, up) | getFlag(x + 1, z - 1, height, bitOffset+3, up) | getFlag(x - 1, z + 1, height, bitOffset+4, up) | getFlag(x + 1, z, height, bitOffset+5, up) | getFlag(x, z + 1, height, bitOffset+6, up) | getFlag(x + 1, z + 1, height, bitOffset+7, up);
}

//Helper function to reduce code size. Checks if the terrain is higher or lower and returns 1 bit based on that.
private int getFlag(int x, int z, int height, int bitOffset, boolean up)
{
   if(up)
   {
      return (getHeight(x, z) > height ? 1 : 0) << bitOffset;  
   }
   return (getHeight(x, z) < height ? 1 : 0) << bitOffset;
}


Thanks to fast util its only like 10-20kb of data that i actually store in ram.
Also this code is enough that you can easily generate yourself the "Automated Display Evaluation System" out of that.

That should at least cover enough cases that i can easly generate terrain without problems. And even if there is some left there is a manual fixing system for that. Once the map is generated the vertex data is anyway stored in the save file so players themselves don't get any issues afterwards.

If you have any improvement ideas go ahead i will follow this thread at least a bit.

Thanks for reading/time. Speiger

Edit 1: Oh yeah i just forgot, why i return 0-1 in the function instead of the true/false is because this function actually parses directly into a Texture (which is the terraincolor, heightmap, colorOverlayForTerrain, VertexRotation, not in that order), because i use a Instanced Mesh renderer for a giant map and only have like 1 mesh for the entirety of it (mesh is 16x16 tiles). (Largest right now is 4096x4096 tiles)

 20 
 on: 2019-05-14 05:03:29 
Started by Speiger - Last post by LiquidNitrogen
i take the height difference between opposite corners, and if one is bigger than the other then flip it.

1  
2  
3  
4  
   float length1 = Math.abs(cornerHeight1 - cornerHeight3);
   float length2 = Math.abs(cornerHeight2 - cornerHeight4);

   if (length1 > length2) flip = true;

..although that looks like it wont work on the peaks there.

Pages: 1 [2] 3 4 ... 10
 
hadezbladez (2595 views)
2018-11-16 13:46:03

hadezbladez (928 views)
2018-11-16 13:41:33

hadezbladez (2551 views)
2018-11-16 13:35:35

hadezbladez (500 views)
2018-11-16 13:32:03

EgonOlsen (3675 views)
2018-06-10 19:43:48

EgonOlsen (4028 views)
2018-06-10 19:43:44

EgonOlsen (2440 views)
2018-06-10 19:43:20

DesertCoockie (3247 views)
2018-05-13 18:23:11

nelsongames (3293 views)
2018-04-24 18:15:36

nelsongames (4264 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!