java - libGDX - how to use 3D object indicating direction in 3D space? -


i use libgdx 3d game. in game 3d arrow should indicate direction in 3d space. player moving, direction of 3d arrow updated every frame.

i want place arrow in direction, camera looking 3 units before camera, arrow visible. therefore added camera direction current camera position , used translation part arrow. direction calculated substracting arrow position target.

all works fine, arrow displayed @ right position , moves. problem is, sometimes points target, , not.

here code:

vector3 targetposition = new vector3(1, 1, 10); vector3 cameraposition = gamecontroller.getcamera().position.cpy(); vector3 cameradirection = gamecontroller.getcamera().direction.cpy(); vector3 = gamecontroller.getcamera().up.cpy();  vector3 arrowposition = cameradirection.scl(3).add(cameraposition); vector3 arrowdirection = targetposition.cpy(); arrowdirection = arrowdirection.sub(arrowposition).nor();  matrix4 transformationmatrix = new matrix4();  // calculate orthogonal vector up.crs(arrowdirection).crs(arrowdirection);  arrowmodel.transform = transformationmatrix.settolookat(arrowdirection,     up).trn(arrowposition); 

to avoid vectors calculated wrong, debug lines added:

modelbuilder.begin(); meshpartbuilder partbuilder = modelbuilder.part("lines", gl20.gl_lines,     usage.position,     new material(colorattribute.creatediffuse(color.green))); vector3 linepos = arrowposition.cpy(); partbuilder.line(linepos.cpy().add(arrowdirection), linepos); partbuilder.line(linepos.cpy().add(up), linepos); debugmodel = new modelinstance(modelbuilder.end()); 

as result, see correct green line vector (current vector of camera), , green line pointing correctly target, green cube. arrow other:

http://www.directupload.net/file/d/3638/2ka7kvvj_jpg.htm

in picture arrow quite near right direction (green line), there other situations, points in wrong direction.

i used quite lot combinations of .translate, .trn, .settolookat, , .rotate of them showed similar, wrong results.

do have idea went wrong here?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -