terrain collision system returning small height valuesTerrain and Collision in a GameCollision system for an object?Collision system not working3d heightmap terrain and collision detectionHow do i make 3D collision detection with my terrain and my character? LWJGLSmooth Terrain Collision - 3DglfwGetCursorPos returning int valuesLibGDX, How to create a 2d collision terrain2D terrain + collision in javaWhy are textures displayed incorrectly when using indexed rendering (glDrawElements) when trying to load them from a wavefront .obj file?
Is there a reason to prefer HFS+ over APFS for disk images in High Sierra and/or Mojave?
SOQL query causes internal Salesforce error
How do I tell my boss that I'm quitting in 15 days (a colleague left this week)
Do you waste sorcery points if you try to apply metamagic to a spell from a scroll but fail to cast it?
Why didn’t Eve recognize the little cockroach as a living organism?
Check if object is null and return null
Why is the Sun approximated as a black body at ~ 5800 K?
How much do grades matter for a future academia position?
Quoting Keynes in a lecture
Origin of pigs as a species
Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?
Alignment of six matrices
Storage of electrolytic capacitors - how long?
Should I warn a new PhD Student?
Is there a distance limit for minecart tracks?
Do I have to know the General Relativity theory to understand the concept of inertial frame?
Mimic lecturing on blackboard, facing audience
Review your own paper in Mathematics
Deciphering cause of death?
Why does a 97 / 92 key piano exist by Bösendorfer?
Is there anyway, I can have two passwords for my wi-fi
Language involving irrational number is not a CFL
Did I make a mistake by ccing email to boss to others?
What is this high flying aircraft over Pennsylvania?
terrain collision system returning small height values
Terrain and Collision in a GameCollision system for an object?Collision system not working3d heightmap terrain and collision detectionHow do i make 3D collision detection with my terrain and my character? LWJGLSmooth Terrain Collision - 3DglfwGetCursorPos returning int valuesLibGDX, How to create a 2d collision terrain2D terrain + collision in javaWhy are textures displayed incorrectly when using indexed rendering (glDrawElements) when trying to load them from a wavefront .obj file?
I'm trying to make a simple terrain collision system for my game, but
it's just returning small values ranging from 0.3 - 1, nothing higher or lower, and my character just stays at the same height.
I've been trying to fix this for hours, but I haven't found the solution yet.
Here is the code for collisions:
package terrain;
public float getHeightOfTerrain(float worldx,float worldz)
gridx<0
private RawModel generateTerrain(Loader loader,String heightMap)
BufferedImage image = null;
try
image = ImageIO.read(new File("res/"+heightMap+".png"));
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
int vertex_count = image.getHeight();
heights = new float[vertex_count][vertex_count];
int count = vertex_count * vertex_count;
float[] vertices = new float[count * 3];
float[] normals = new float[count * 3];
float[] textureCoords = new float[count*2];
int[] indices = new int[6*(vertex_count-1)*(vertex_count-1)];
int vertexPointer = 0;
for(int i=0;i<vertex_count;i++)
for(int j=0;j<vertex_count;j++)
vertices[vertexPointer*3] = (float)j/((float)vertex_count - 1) * size;
float height = getheight(j,i,image);
heights[j][i] = height;
vertices[vertexPointer*3+1] = height;
vertices[vertexPointer*3+2] = (float)i/((float)vertex_count - 1) * size;
Vector3f normal = calculateNormal(j,i,image);
normals[vertexPointer*3] = normal.x;
normals[vertexPointer*3+1] = normal.y;
normals[vertexPointer*3+2] = normal.z;
textureCoords[vertexPointer*2] = (float)j/((float)vertex_count - 1);
textureCoords[vertexPointer*2+1] = (float)i/((float)vertex_count - 1);
vertexPointer++;
int pointer = 0;
for(int gz=0;gz<vertex_count-1;gz++)
for(int gx=0;gx<vertex_count-1;gx++)
int topLeft = (gz*vertex_count)+gx;
int topRight = topLeft + 1;
int bottomLeft = ((gz+1)*vertex_count)+gx;
int bottomRight = bottomLeft + 1;
indices[pointer++] = topLeft;
indices[pointer++] = bottomLeft;
indices[pointer++] = topRight;
indices[pointer++] = topRight;
indices[pointer++] = bottomLeft;
indices[pointer++] = bottomRight;
return loader.loadToVAO(vertices, textureCoords, normals, indices);
private float getheight(int x,int z,BufferedImage image)
z<=0
}
java lwjgl
add a comment |
I'm trying to make a simple terrain collision system for my game, but
it's just returning small values ranging from 0.3 - 1, nothing higher or lower, and my character just stays at the same height.
I've been trying to fix this for hours, but I haven't found the solution yet.
Here is the code for collisions:
package terrain;
public float getHeightOfTerrain(float worldx,float worldz)
gridx<0
private RawModel generateTerrain(Loader loader,String heightMap)
BufferedImage image = null;
try
image = ImageIO.read(new File("res/"+heightMap+".png"));
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
int vertex_count = image.getHeight();
heights = new float[vertex_count][vertex_count];
int count = vertex_count * vertex_count;
float[] vertices = new float[count * 3];
float[] normals = new float[count * 3];
float[] textureCoords = new float[count*2];
int[] indices = new int[6*(vertex_count-1)*(vertex_count-1)];
int vertexPointer = 0;
for(int i=0;i<vertex_count;i++)
for(int j=0;j<vertex_count;j++)
vertices[vertexPointer*3] = (float)j/((float)vertex_count - 1) * size;
float height = getheight(j,i,image);
heights[j][i] = height;
vertices[vertexPointer*3+1] = height;
vertices[vertexPointer*3+2] = (float)i/((float)vertex_count - 1) * size;
Vector3f normal = calculateNormal(j,i,image);
normals[vertexPointer*3] = normal.x;
normals[vertexPointer*3+1] = normal.y;
normals[vertexPointer*3+2] = normal.z;
textureCoords[vertexPointer*2] = (float)j/((float)vertex_count - 1);
textureCoords[vertexPointer*2+1] = (float)i/((float)vertex_count - 1);
vertexPointer++;
int pointer = 0;
for(int gz=0;gz<vertex_count-1;gz++)
for(int gx=0;gx<vertex_count-1;gx++)
int topLeft = (gz*vertex_count)+gx;
int topRight = topLeft + 1;
int bottomLeft = ((gz+1)*vertex_count)+gx;
int bottomRight = bottomLeft + 1;
indices[pointer++] = topLeft;
indices[pointer++] = bottomLeft;
indices[pointer++] = topRight;
indices[pointer++] = topRight;
indices[pointer++] = bottomLeft;
indices[pointer++] = bottomRight;
return loader.loadToVAO(vertices, textureCoords, normals, indices);
private float getheight(int x,int z,BufferedImage image)
z<=0
}
java lwjgl
ericlippert.com/2014/03/05/how-to-debug-small-programs
– Scary Wombat
Mar 7 at 2:24
Scary Wombat i just put a small part of my code so that won't help
– vincent castro
Mar 7 at 2:32
add a comment |
I'm trying to make a simple terrain collision system for my game, but
it's just returning small values ranging from 0.3 - 1, nothing higher or lower, and my character just stays at the same height.
I've been trying to fix this for hours, but I haven't found the solution yet.
Here is the code for collisions:
package terrain;
public float getHeightOfTerrain(float worldx,float worldz)
gridx<0
private RawModel generateTerrain(Loader loader,String heightMap)
BufferedImage image = null;
try
image = ImageIO.read(new File("res/"+heightMap+".png"));
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
int vertex_count = image.getHeight();
heights = new float[vertex_count][vertex_count];
int count = vertex_count * vertex_count;
float[] vertices = new float[count * 3];
float[] normals = new float[count * 3];
float[] textureCoords = new float[count*2];
int[] indices = new int[6*(vertex_count-1)*(vertex_count-1)];
int vertexPointer = 0;
for(int i=0;i<vertex_count;i++)
for(int j=0;j<vertex_count;j++)
vertices[vertexPointer*3] = (float)j/((float)vertex_count - 1) * size;
float height = getheight(j,i,image);
heights[j][i] = height;
vertices[vertexPointer*3+1] = height;
vertices[vertexPointer*3+2] = (float)i/((float)vertex_count - 1) * size;
Vector3f normal = calculateNormal(j,i,image);
normals[vertexPointer*3] = normal.x;
normals[vertexPointer*3+1] = normal.y;
normals[vertexPointer*3+2] = normal.z;
textureCoords[vertexPointer*2] = (float)j/((float)vertex_count - 1);
textureCoords[vertexPointer*2+1] = (float)i/((float)vertex_count - 1);
vertexPointer++;
int pointer = 0;
for(int gz=0;gz<vertex_count-1;gz++)
for(int gx=0;gx<vertex_count-1;gx++)
int topLeft = (gz*vertex_count)+gx;
int topRight = topLeft + 1;
int bottomLeft = ((gz+1)*vertex_count)+gx;
int bottomRight = bottomLeft + 1;
indices[pointer++] = topLeft;
indices[pointer++] = bottomLeft;
indices[pointer++] = topRight;
indices[pointer++] = topRight;
indices[pointer++] = bottomLeft;
indices[pointer++] = bottomRight;
return loader.loadToVAO(vertices, textureCoords, normals, indices);
private float getheight(int x,int z,BufferedImage image)
z<=0
}
java lwjgl
I'm trying to make a simple terrain collision system for my game, but
it's just returning small values ranging from 0.3 - 1, nothing higher or lower, and my character just stays at the same height.
I've been trying to fix this for hours, but I haven't found the solution yet.
Here is the code for collisions:
package terrain;
public float getHeightOfTerrain(float worldx,float worldz)
gridx<0
private RawModel generateTerrain(Loader loader,String heightMap)
BufferedImage image = null;
try
image = ImageIO.read(new File("res/"+heightMap+".png"));
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
int vertex_count = image.getHeight();
heights = new float[vertex_count][vertex_count];
int count = vertex_count * vertex_count;
float[] vertices = new float[count * 3];
float[] normals = new float[count * 3];
float[] textureCoords = new float[count*2];
int[] indices = new int[6*(vertex_count-1)*(vertex_count-1)];
int vertexPointer = 0;
for(int i=0;i<vertex_count;i++)
for(int j=0;j<vertex_count;j++)
vertices[vertexPointer*3] = (float)j/((float)vertex_count - 1) * size;
float height = getheight(j,i,image);
heights[j][i] = height;
vertices[vertexPointer*3+1] = height;
vertices[vertexPointer*3+2] = (float)i/((float)vertex_count - 1) * size;
Vector3f normal = calculateNormal(j,i,image);
normals[vertexPointer*3] = normal.x;
normals[vertexPointer*3+1] = normal.y;
normals[vertexPointer*3+2] = normal.z;
textureCoords[vertexPointer*2] = (float)j/((float)vertex_count - 1);
textureCoords[vertexPointer*2+1] = (float)i/((float)vertex_count - 1);
vertexPointer++;
int pointer = 0;
for(int gz=0;gz<vertex_count-1;gz++)
for(int gx=0;gx<vertex_count-1;gx++)
int topLeft = (gz*vertex_count)+gx;
int topRight = topLeft + 1;
int bottomLeft = ((gz+1)*vertex_count)+gx;
int bottomRight = bottomLeft + 1;
indices[pointer++] = topLeft;
indices[pointer++] = bottomLeft;
indices[pointer++] = topRight;
indices[pointer++] = topRight;
indices[pointer++] = bottomLeft;
indices[pointer++] = bottomRight;
return loader.loadToVAO(vertices, textureCoords, normals, indices);
private float getheight(int x,int z,BufferedImage image)
z<=0
}
java lwjgl
java lwjgl
edited Mar 7 at 2:39
vincent castro
asked Mar 7 at 2:04
vincent castrovincent castro
1
1
ericlippert.com/2014/03/05/how-to-debug-small-programs
– Scary Wombat
Mar 7 at 2:24
Scary Wombat i just put a small part of my code so that won't help
– vincent castro
Mar 7 at 2:32
add a comment |
ericlippert.com/2014/03/05/how-to-debug-small-programs
– Scary Wombat
Mar 7 at 2:24
Scary Wombat i just put a small part of my code so that won't help
– vincent castro
Mar 7 at 2:32
ericlippert.com/2014/03/05/how-to-debug-small-programs
– Scary Wombat
Mar 7 at 2:24
ericlippert.com/2014/03/05/how-to-debug-small-programs
– Scary Wombat
Mar 7 at 2:24
Scary Wombat i just put a small part of my code so that won't help
– vincent castro
Mar 7 at 2:32
Scary Wombat i just put a small part of my code so that won't help
– vincent castro
Mar 7 at 2:32
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034945%2fterrain-collision-system-returning-small-height-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034945%2fterrain-collision-system-returning-small-height-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
ericlippert.com/2014/03/05/how-to-debug-small-programs
– Scary Wombat
Mar 7 at 2:24
Scary Wombat i just put a small part of my code so that won't help
– vincent castro
Mar 7 at 2:32