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?













0















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
}









share|improve this question
























  • 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















0















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
}









share|improve this question
























  • 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













0












0








0








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
}









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved