Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - makaan

Pages: [1]
1
Modification Help / Mouse position to world coords (in script)
« on: August 29, 2007, 03:32:17 PM »
I know this should be done in C++ but I'm wondering how to get the 3D world coordinates from the 2D mouse position.

here's what i have so far (which doesn't work very well):
Code: [Select]
// commandToServer('GetMouse3DPos', canvas.getCursorPos(), getRes());

function serverCmdGetMouse3DPos(%client, %clientMousePos, %clientRes) {

%Pos2D = (firstWord(%clientRes) / 2) SPC (getWord(%clientRes, 1) / 2);

%x = firstWord(%clientMousePos) - firstWord(%Pos2D);
%y = getWord(%clientMousePos, 1) - getWord(%Pos2D, 1);
// The cursor position is based off of the top-left corner of the screen
// This makes x and y relative to the center of the screen

%delta = "0" SPC (%x / 10) SPC (-%y / 10);
// If you click above your player, for example, this will be about:
// 0 0 1
// The z value is how far above your player you clicked

error(%delta);
%Vec3D = VectorAdd(%client.player.getForwardVector(), %delta);
%Vec3D = VectorAdd(%Vec3D, %client.player.getPosition());
messageClient(%client, '', '3D position is: %1', %Vec3D);
}

Pages: [1]