Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / A little help with converting 3d object (r.w. location) position to 2d screen position (not 2d to 3d)

Author
Message
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 15th Jun 2010 22:10 Edited at: 15th Jun 2010 22:16
I don't even know where to start on this lol - I have an object - a blank plane. Think of it like a road. From it's positions and based on what type of road it is, I offset the position of the right and left lane(s) by "X" amount. What I need to do, since this is an editor I am coding here, is display lines for the route cars and traffic will drive on in the editor. So there are a total of four points for a standard road. 1) North Right and Left lane offsets and 2) South right and left lane offsets. I need to convert the positions in 3d real world to 2d screen and draw a line from North to south for the offset points. I'm handy with vectors so i'd love help in that route.

I can (if I manage to convert from 3d to 2d) position hidden objects at the end points and set a vector3 to it's position. Then Using the pick commands, the user can move the offsets how they see fit and design their own road. There's just not a lot that came up in the search for what I'm needing to do.

Daryn

- On a side note this was supposed to be in Pro... wrong forum. Whoops, my bad.

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 16th Jun 2010 10:21
Hi Daryn, would the 'OBJECT SCREEN X' and the 'OBJECT SCREEN Y' be the commands you are looking for? These commands return the x and y screen coordinates of a 3d object.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 16th Jun 2010 10:52
What I need is the reverse of the pick screen and object commands. I need to translate a 2d position from a 3d one, not a 3d from a 2d. - So if you know how to use the pick commands back words lol, I'd love to see it - other wise, nah...

Consider this

| ' |
| ' |
| ' |

As a road.

It has two lanes (or) right and left. Traffic goes down these two lanes (or up it) in the center of the lanes. (I've tried using Dark AI but unfortunately the paths system draws points in a different manner and I can use it...) - in those two lanes there would be an imaginary line in which traffic follows.

Consider one lane. It would have two draw points or the line start and end. In the game, you can imagine that when you draw the road or network, the positions of the line start would connect to the positions of the previous objects line end. Because I am only doing this in the editor for fine tuning, I need to actually see the lines or PATH that the vehicles will follow. To do that, I need the line start and end points to be converted back into 2d so that a 2d line can be drawn from the points - I just have no I dea how to transform 2d or vector2s back into 3d or vector3. Also - For larger transit and network types, there are more than one lane for the right and left side of the object, so path making and finding plays a big role for interchanges and intersections. Hope that helps.

There's and Image attached if not

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.

Attachments

Login to view attachments
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 16th Jun 2010 18:43
This should help clarify things a little.

Going from 2D screen coordinates to 3D world coordinates.


Going from 3D to 2D screen coordinates.



Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 16th Jun 2010 20:36 Edited at: 16th Jun 2010 20:42
I understand what the pick commands can do and I have them in the editor and game now - when you hover over terrain there is a highlight of a dark grid that drops off alpha radially as well as a cursor for the grid in the editor(like in 3ds Max) that are positioned using the pick commands. But the image i uploaded tells you that these points in the game will need to be stored - so first, that would require that for every object that traveled down the road - if I display its path, I would need to create 4 spheres for every section of road for North right and left (two lane) and south right and left, use the above command and then using that set of RNAx,LNAy,RSBx,LSBy values, draw a line connects from one point to another. So then if I wanted to show the path of one car, say from home to work - that would be...

Then Number of Points per transit network piece = 4, likewise objects plus additional spheres for path display
The Number of objects in path = (lets say) 400
Right off that bat that's a lot of objects... if you make spheres to display the path...

400 road objects * 4 road path spheres = 1,600 objects

If each object were 10X10, and each grid tile was 3ft that would be...

(30Ft*400 objects = 12,000Ft or about a mile and a half.)

That would make large paths a real process on the cpu - and who travels more than one and a half miles each day? That was for a two lane road - but what about a six lane avenue w/ right and left lanes? Or an eight lane high way? WOH!

I just need an alternative method for converting 3d coordinates into 2d points or I'll get this project in a jar.

What exactly do the pick commands do - and if there is a way to create custom pick commands, how do you do so - if I can understand that, maybe I can create a reverse pick command for 3d vectors to 2d screen points... hope that clarifies.

-Daryn

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 16th Jun 2010 21:59
Why not just reuse the same spheres? There's no need for each vehicle to have it's own set of spheres. Just an array that has it's path of spheres.

Car 1
Path(1,1) = Sphere1
Path(1,2) = Sphere2
Path(1,3) = Sphere6 ` Left turn at intersection
Path(1,4) = Sphere12 ` Next sphere on that street in the lane you want

Car 2
Path(2,1) = Sphere2 ` Just ahead of Car 1
Path(2,2) = Sphere3 ` Go straight through intersection
Path(2,3) = Sphere4 ` Next sphere ahead
Path(2,4) = Sphere5

Quote: "I just need an alternative method for converting 3d coordinates into 2d points"


Is that 2D points on the screen, or in the 3D world?

Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 16th Jun 2010 22:44 Edited at: 16th Jun 2010 22:56
Guys - the positions of the spheres translated into 2d and then linked together to form a line - its for editing and debug. Not for car positions.

Considering the above, where you position the spheres - that real world location needs to be converted to 2d screen coords. then linked together using the line command.

2d points.

for a road there are 4

North Right and Left......| North Left ' North Right |
This is the middle...........|........v........'.........^.........|
South Right and Left......| South Left ' South Right |

North Left and right are 3d points that need to be converted with South left and right into 2d screen points. Then linked together using the line command - no more examples.

Sorry if I sound frustrated but i am lol. But you very near understanding me fully.

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 17th Jun 2010 01:27 Edited at: 17th Jun 2010 01:36
Ok, that's what I thought initially. Which is why I posted this previously,



That puts a DOT on the screen where your Sphere1 is.

Do the same thing for Sphere2.

Then do the LINE command using the X and Y of both of those dots.

[edit]
Here is a full example, drawing a line between 2 3D objects.



Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 17th Jun 2010 16:43
Right - did this for the editor... but what I was saying was that if In the game I clicked on a building per say and displayed the path vehicles took from their homes to the location I clicked, it would take 704 spheres (A mile = 5280, the scale of my objects is 3ft per square, 1 grid section = 10*3ft. so to get the total amount of objects used (the road only) we do 5280ft/30ft. Now we multiply that number by four for the four spheres)

That is a lot of spheres - and while I could just make an array and store positions - and use the same spheres over and over again - is it really that hard to do exactly what the pick commands do and just not do it with an object? Is it really all that hard to transform a vector3 into a vector2? - lol - i guess it is.

If I could figure this out then I could dance.


Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 17th Jun 2010 18:25
You could do it all with one sphere, just moving it to the next location, do the pick, then move on to the next.

I'm not sure of the functions used to find the screen coordinates. I've always been fairly good at math, but there's some of it that I haven't really sunk my teeth into yet.

Have a look at this though.
I Googled "3D position to screen coordinates"
http://freespace.virgin.net/hugo.elias/routines/3d_to_2d.htm

Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 17th Jun 2010 21:23
Lol - well I nearly got express out and wrote tried to write a DLL for this one

Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 18th Jun 2010 00:24 Edited at: 18th Jun 2010 01:47
That article actually helped me do exactly what I wanted to do and it is super super easy to do this now. awesome. ty. I feel a little slow now - knowing all I had to do was google it - silly me.

EDIT:

The only question I have is - say I have the camera pointing at an object from 0,0,-100 - the object is at the origin (0,0,0). How do I determine the 3d distance the object would have to go before it's off screen? I suppose this would be a 3d value (could me morphed into a single distance but I can do that) being that the object could move left and right, up and down, frontwards and backwards - although forward and backwards would take a much greater distance before it was off screen, if the camera was not tilted... so that's it - just the 3d distance across the screen based on the camera position from the object position. Thank you for helping me out!



Jack and Jill went up a hill to fetch a pale of water... but Jill got tired of his s#%& so she shot him.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 18th Jun 2010 19:00
3D distance is much easier. That alone wont tell you if the object is in screen or not though.



Based on the formula,

d# = sqrt((x1# - x2#)^2 + (y1# - y2#)^2 + (z1# - z2#)^2)

The longer function above just performs the calculations faster.

Login to post a reply

Server time is: 2024-09-28 18:26:51
Your offset time is: 2024-09-28 18:26:51