libgdx - Java / box2DLights - Wrong light position -


i'm using libgdx project , more precisely box2dlights.

my problem following 1 : when want put new "pointlight" it's on center of screen. , if change coordinates, doesn't work.

inside "show()" method :

    box2d.init();     world = new world(new vector2(0, 0), true);      rh = new rayhandler(world);     rh.setambientlight(1.2f, 0.2f, 0.2f, 0.1f);     pl = new pointlight(rh, 100, new color(1,1,1,1),(float) 0.5,0,0); 

inside "render()" method :

    gdx.gl.glclearcolor(0f, 0f, 0f, 1f);      gdx.gl.glclear(gl20.gl_color_buffer_bit);     world.step(delta, 8, 3);      renderer.begin(shapetype.filled);     (solarsystem ss : solarsystemlist)     {         if(ss.getcolor() <= 15) colorss = color.yellow;         else if(ss.getcolor() > 15 && ss.getcolor() < 31) colorss = color.orange;         else if(ss.getcolor() > 30 && ss.getcolor() < 46) colorss = color.red;         else if(ss.getcolor() > 45) colorss = color.cyan;          renderer.setcolor(colorss);         renderer.circle(ss.getmapx(), ss.getmapy(), ss.getsize() - 3);     }     renderer.end();      rh.updateandrender(); 

result :

enter image description here if try change coordinates :

pl = new pointlight(rh, 100, new color(1,1,1,1),(float) 0.5, 50, 50); 

enter image description here

... no light anymore

do know how it's possible put light want ?

edit : screen size : width - 860px / height - 645px

if (1,1) top right , (0,0) bottom left , (0.5,0.5) middle of screen, propose : insert value want , divide width , height of of screen example

 ( xposition/gdx.graphics.width, yposition/gdx.graphics.height )  

update :

sorry didn't see (0,0) center propse use instead :

width  = gdx.graphics.width; height = gdx.graphics.height; ((xposition - width/2)/ width/2 , (yposition - height/2)/ height/2) 

update 2 : think doing little arithmetic mistake assume your

width = 860 , height = 645 said

this equation :

x= ((xposition - width/2)/ width/2)

y= (yposition - height/2)/ height/2)

x = (50 - 860/2) / (860/2)

y = (50 - 645/2) / (645/2)

x = (50 - 430) / (430)

y = (50 - 322.5) / (322.5)

x = (50 - 430) / (430) = (-380) / (430)

y = (50 - 322.5) / (322.5) = (-272.5) / (322.5)

x = -0.88

y = -0.84

which closer (-1,-1) aka : left bottom corner

hope helpful :)


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -