Jump to content

Вопрос по трансляции координат (Question for coordinate translation)


photo

Recommended Posts

Приветствую!

 

Подскажите, пожалуйста. Как получить направление в мировых координатах, в формате vec3, от текущей позиции Player'а на 2D-точку, которая указана в координатах экрана?

 

Спасибо!

 

Hi!

 

Can you tell me, how i can get direction (vec3) in world coordinates from Player eye position to 2D-point in screen coordinates?

 

Thank's!

Link to comment

void getPlayerMouseDirection(vec3 &p0,vec3 &p1) {
	Player player = getPlayer();
	if(player == NULL) return;
	mat4 projection = player.getProjection();
	mat4 imodelview = inverse(player.getIWorldTransform());
	float aspect = float(engine.app.getWidth()) / engine.app.getHeight();
	float x = -(float(engine.app.getMouseX()) / engine.app.getWidth() * 2.0f - 1.0f) / projection.m00 * aspect;
	float y = (float(engine.app.getMouseY()) / engine.app.getHeight() * 2.0f - 1.0f) / projection.m11;
	p0 = imodelview.m03m13m23;
	p1 = imodelview * vec3(x,y,1.0f);
	p1 = p0 - normalize(p1 - p0) * player.getZFar();
}

 

You can change engine.app.getMouseX()/getMouseY() on your 2D screen coordinates or use this function directly from core/scripts/utils.h

  • Like 1
Link to comment
×
×
  • Create New...