HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Feature request: WorldToScreenPoint  (Read 3089 times)

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Feature request: WorldToScreenPoint
« on: Feb 13, 15, 04:43:20 PM »

Any chance we get an external function which would be an equivalent to Camera.WorldToScreenPoint from unity?
It would be a very cool thing to have...

Camera.WorldToScreenPoint

public function WorldToScreenPoint(position: Vector3): Vector3;
Description

Transforms position from world space into screen space.

Screenspace is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (pixelWidth,pixelHeight). The z position is in world units from the camera.

   var target : Transform;
   function Update () {
      var screenPos : Vector3 = camera.WorldToScreenPoint (target.position);
      print ("target is " + screenPos.x + " pixels from the left");
   }
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Feature request: WorldToScreenPoint
« Reply #1 on: Feb 13, 15, 05:15:52 PM »

I thought there was something like this...  I know when a gui control is attached to a world node the gui will track the apparent position of the node on screen, though that seems to be all done in source code.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: Feature request: WorldToScreenPoint
« Reply #2 on: Feb 14, 15, 03:11:55 PM »

as far as i know there is nothing like this currently exposed to the users
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
Re: Feature request: WorldToScreenPoint
« Reply #3 on: Feb 14, 15, 07:27:52 PM »

There is something similar but not quite the same. It uses a (x,y) position in the game world and translates it to a (x,y) screen position. Its from the minimap section, using WorldSpaceToMiniMapSpace().

// WorldSpaceToMiniMapSpace() converts a 3D worldspace position to 2D coordinates within the
// 512x512 minimap texture.  Here, we're using it to decide how to set the UV coordinates to
// display the area around the character.  You can also use it to figure out where to place
// markers for other characters, creatures, etc.

inRange as Boolean = WorldSpaceToMiniMapSpace(position,answer)
Logged
Lead scripter for EO, Repop helper.
HSL Video tutorials:
https://community.heroengine.com/forums/index.php/topic,1719.msg36858.html#msg3685

keeperofstars

  • General Accounts
  • *
  • Posts: 998
    • View Profile
    • StarKeeper Online
Re: Feature request: WorldToScreenPoint
« Reply #4 on: Feb 14, 15, 07:48:41 PM »

external function GetScreenSpacePosition(node as NodeRef) as Vector3

I think that is what you are looking for

Also have these.

// Raycast in 3d using specified position/direction/distance
external function Raycast3D(origin as Vector3, direction as Vector3, excludedNodes as List of NodeRef, distance references Float, intercept references Vector3, meshName references String) as NodeRef of Class HBNode
external function Raycast3D_ListMeshes(origin as Vector3, direction as Vector3, excludedNodes as List of NodeRef, distance references Float, intercept references Vector3, meshNames references List of String) as NodeRef of Class HBNode
// Casts a ray from the camera in the direction near clip plane passing through the mouse position on it
external function RaycastMouse(excludedNodes as List of NodeRef, distance references Float, intercept references Vector3, meshName references String) as NodeRef of Class HBNode
external function RaycastMouse_ListMeshes(excludedNodes as List of NodeRef, distance references Float, intercept references Vector3, meshNames references List of String) as NodeRef of Class HBNode
// Casts a ray from the camera in the direction of the near clip plane passing through the specified xy position
external function RaycastFromScreen(x as Integer, y as Integer, excludedNodes as List of NodeRef, distance references Float, intercept references Vector3, meshName references String) as NodeRef of Class HBNode
external function RaycastFromScreen_ListMeshes(x as Integer, y as Integer, excludedNodes as List of NodeRef, distance references Float, intercept references Vector3, meshNames references List of String) as NodeRef of Class HBNode


// returns the worldspace origin, and unit vector direction, for a ray projected from the mouse position into the world
external function ProjectMouseToWorld(origin references Vector3, direction references Vector3)

// returns the worldspace origin, and unit vector direction, for a ray projected from the given screen coordinates into the world
external function ProjectScreenToWorld(x as Integer, y as Integer, origin references Vector3, direction references Vector3)


And there are a few others like this.

Logged
[img]http://screencast.com/t/x7btcSSyp3h0[\img]

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: Feature request: WorldToScreenPoint
« Reply #5 on: Feb 15, 15, 12:58:24 AM »

Unfortunatelly, none of those functions you mentioned is the function described in the post.


(GetScreenSpacePosition for example works with GUIControl.
Returns the position of the given GUIControl in screen coordinates in the vector's .x and .y (.z is unused))


This is what i need, and i didn't make this function up... only made a copy/paste from the unity API:
http://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html


« Last Edit: Feb 15, 15, 01:00:03 AM by AWW_boss »
Logged

keeperofstars

  • General Accounts
  • *
  • Posts: 998
    • View Profile
    • StarKeeper Online
Re: Feature request: WorldToScreenPoint
« Reply #6 on: Feb 15, 15, 06:33:35 PM »

So you are trying to get the x,y screen coordinates of a 3d object in game. If I may ask what is the goal of said task?

For one that is a very dangerous function to be used in any game as it's a hackers dream function, but outside of that aspect.

What is the goal you are trying to accomplish with providing the user the x,y coordinates of anything other than the gui?
Logged
[img]http://screencast.com/t/x7btcSSyp3h0[\img]

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Feature request: WorldToScreenPoint
« Reply #7 on: Feb 15, 15, 06:59:00 PM »

As I understand him, it is to take a given point in 3D space and at the particular time find out what 2D position it projects to if it is on screen.  So like how the nameplates (or any gui attached to a node) work.  They are on the 2D gui but move to be where the node they are attached to appears on the screen.

Which might be the only way to do it right now: attach an invisible gui to the node in question, then query that gui for its current position at any given time.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

keeperofstars

  • General Accounts
  • *
  • Posts: 998
    • View Profile
    • StarKeeper Online
Re: Feature request: WorldToScreenPoint
« Reply #8 on: Feb 16, 15, 05:48:44 PM »

Right but the client has no need to know the screen's X,Y for that.

That is the aspect that bares the question, why does a client care at all about the x,y location of a 3d node, and what will trigger the aspect of that node is it a mouse click on node to retrieve it? And why feed that data back, if it needs some type of interaction with the node, then a GUI attached to the node works to solve the whole issue, cause you will have the x,y of the gui element.  Also, keeping in mind you can raycast from the mouse to hit nodes behind the mouse. You can even raycast from the screen to identify the nodes in the screen point, etc. So if you just trying to see if there is a hit on a node you have options to solve that. Such as a target cursor seeing if it hits a node in empty space.

So the question is what game feature would ever need the x,y that isn't a gui control?
Which often gets used for GUI type aspects such as moving nodes to locations, and or determining if there is overlap so you can adjust gui controls and a lot of other helpful.

But sending a X, Y location of a node back to the client for other than gui, has little use. And in most to all cases a dangerous use case scenario. Cause the function has to run on the client, which means you just gave screen coordinates back to the client. So you have a client that can run a function and track a node anywhere it moves on the screen, take about 10 minutes to write a client hack to basically build a full auto target / click system, for everything in the game. And the server wouldn't know or care.

but i could be missing a case use for it. so i'm all ears.
Logged
[img]http://screencast.com/t/x7btcSSyp3h0[\img]