123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|582|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> find 3d object on 2d screen....

Sun, 16 Mar 2008, 13:54
Orion Pax
How can I go about locating a 3d objects position on the 2d screen?
Sun, 16 Mar 2008, 14:13
Afr0
Object.Position?

Assuming you've designed your class right...

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 16 Mar 2008, 14:48
Orion Pax
ok, im sorry...im working with blitz3d here. Figured since I posted in the blitz forum that someone would have noticed that. I am assuming your thinking of C?
Sun, 16 Mar 2008, 15:22
Phoenix
You need to be more specific. Explain in detail what you're exactly trying to say, as you're very vague. Do you perhaps want to know where a Blitz3D entity is located on the screen in pixels?

I know little about Blitz3D, so I'm afraid I can't help you. Your best bet is to look it up in the command reference, or wait patiently until someone who has B3D experience shows up and tells you. I recommend the first alternative.

And, to be picky, he's not thinking of C since there are no classes in that language...
Sun, 16 Mar 2008, 15:23
JL235
C# (or object-oriented languages in general) actually, not C.

Are you trying to work out if a 3d object is on screen or is this about picking a 2d location on the screen and finding out what object is draw at that location (which if there are multiple objects then will be the closest to the screen)?

These (at least to me) are two very different ideas. Perhaps you could also try and describe what you are trying to achieve, in case there is a better different method to achieve it.
Sun, 16 Mar 2008, 15:57
Jayenkai
There's no absolute way to do it..
Or at least, whilst I tried to do my "2D point+click in a 3D stylee" thing, it wasn't that easy.
There's one way to do it, but A) it's not quick, and B) It's not always going to work.

First off, you could use EntityInView to check whether it's onscreen at all.


One way to get a more precise result is to use CameraPick(X,Y)
But that would mean having to scan the entire screen to find the exact co-ords of whereabouts the object is.

The best option is to try your best to find an alternative method to do what you're trying to doing.
If you let us know the purpose of the request, we might be able to come up with different ways of doing things for you.


-=-=-
''Load, Next List!''
Sun, 16 Mar 2008, 16:28
Orion Pax
What I am trying to do is use the mouse to select something in 3d space. And once selected, draw a box around it. Basically I want an item to basically get highlighted when the mouse moves over it. The highlighting will be the box that will be drawn over it. I just want to find its location on the screen.
Sun, 16 Mar 2008, 16:37
Orion Pax
I thought about using:



This will find the entity that is under the mouse...but not sure how to get its location on the screen in 2d to draw the square around it.
Sun, 16 Mar 2008, 16:42
Jayenkai
It'll be 99.9% easier to have an alternative method to do it..

A possible alternative being to make entityalpha 0.5 when highlighted..

I'm not 100% sure how it'd be done, but could you maybe create a 3D cube that scales to the size of the picked entity, or something like that?
Or maybe recolor the entity..
Or make a copy of the entity, recolor that, then put it slightly in front of the original..

There's plenty of ways to show a highlighted object within 3D space..
Doing 2D on 3D things makes everything much more complex.

-=-=-
''Load, Next List!''
Sun, 16 Mar 2008, 16:47
Orion Pax
That sounds better...i will just adjust the alpha or color slightly.
Sun, 16 Mar 2008, 17:49
JL235
One way to find it's 2d location might be to do CameraPick at MouseX*MouseY and then 4 more at offsets to the left, right, up and down of MouseX*MouseY. Start with large offsets and then make them smaller and smaller until say 3 of the 5 CameraPicks have found the same entity and then take the average between them.

It won't be pinpoint accurate, but it might be good enough. However it could be expensive and I don't know how you'd handle tracking the entity if it's moving.
Sun, 16 Mar 2008, 18:01
Orion Pax
That would be too much work as the objects might be moving.
Tue, 18 Mar 2008, 09:43
mindstorm8191
I know there's a command to do this already... I just forget what it is. Look up the command CameraProject, or something related. Its in the camera command set, so look around there for your options. After you call the command, you can use ProjectedX#() and ProjectedY#() to get the 2D screen coords (I don't know what ProjectedZ#() does for you).

-=-=-
Vesuvius web game
Wed, 19 Mar 2008, 10:48
Orion Pax
Thanks. That does what I exactly want. Now I just have to figure out how to draw a square around it to fit almost perfectly but resize as the object moves.
Wed, 19 Mar 2008, 11:16
Orion Pax
Well I thought I figured it out with meshwidth/meshheight. But when I text out the variables it says that a cube created with default values from createcube() is 2 in width and height. And this is not being scaled in any way and the cube shows up a lot bigger than that.
Wed, 19 Mar 2008, 14:14
GoliX
After some messing I came up with this, it's pretty messy.
:/
Use the mouse wheel to move backwards and forwards.

You're probably best off coupling a sprite with each object and hiding the sprite when it isn't selected. Then blitz can do all the scaling for you.


Wed, 19 Mar 2008, 16:03
Forklift_Fred
"You're probably best off coupling a sprite with each object and hiding the sprite when it isn't selected. Then blitz can do all the scaling for you."

Stroke of genius! The award for strikingly simple innovation that nobody ever thought of before surely goes to GoliX

-=-=-
Come rain or shine...
Wed, 19 Mar 2008, 18:18
GoliX
Hehe thanks
For a while there I wasn't sure wether you were being sarcastic or not fred . I went searching up and down the thread to see if someone had already said what I'd said but I didn't see anything,(though it's similar to jays 3d cube idea).
Wed, 19 Mar 2008, 18:23
Forklift_Fred
No, I'm being serious. Light-heartedly serious, but I do like the idea.

-=-=-
Come rain or shine...
Wed, 19 Mar 2008, 20:39
Orion Pax
Golix that was exceptional. It works great. Just one thing. I tried it with a scaledmesh and it doesnt resize correctly to the new size of the mesh.

Just wondering how did you come up with those figures? Did you major math in college or something? I had a similar idea just couldnt come up with an equation like that.
Wed, 19 Mar 2008, 23:12
GoliX
Lots of trial and error :o. It took quite a while but I didn't want to let it win
Thu, 20 Mar 2008, 00:41
Orion Pax
I tried messing with the values and i cant get it. I noticed you dont use the meshwidth and meshheight for anything. You have them set to W and H respectively, but you dont use them for anything. Since if you scale mesh created in blitz by 10, the resulting size is 20 instead of 2. I tried multiplying the scale by (meshwidth/2) but that aint work. I have tried several other things and come close in one aspect but not another. If I could only get a percentage of how much more space it takes up then maybe I could get the scale increased by that much.
Thu, 20 Mar 2008, 05:39
GoliX
Yeah, it's messy code, a lot of unused veriables from trying different things. It's very touchy too, it seems like changing anything can throw it off .

I'm going to try to write it again later but cleaner and smoother.

Also about the scalemesh, that was what I was experimenting with the meshwidth/height commands for, I'm going to include that in my next go .
Thu, 20 Mar 2008, 08:54
Orion Pax
Yeah, I can barely get it to resize correctly but the distance is throwing it off and not resizing fast enough or slow enough depending on the variable I changed and how I changed it.
Thu, 20 Mar 2008, 09:16
GoliX
It's a bit messy because you can't just scale the square just based on the distance you have to take into acount that as something gets further and further away from us, it shrinks at a slower and slower rate in our viewport. Division helps here, I divided the size of the square(taking up the whole screen) by the distance from the camera

I'll see if I can make an example of the sprite thing.

EDIT

Heres one:



You can make the red line thinner and crisper by increasing the texture(and rect) size.

You have a mouse cursor now, roll mouse to zoom again, click on the cube to select it, and click on the empty map to deselect it.

Sorry for the untidy code.