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.

DarkBASIC Professional Discussion / PICK OBJECT inside a skybox

Author
Message
Qweeg
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Kent
Posted: 14th Feb 2005 23:23
Hi,

I am trying to use the PICK OBJECT function but cannot get it to return anything other than the skybox object number. I am using the default camera and that is inside a skybox. Then I have an object, which is visible on the screen, but I can't get pick object to return this. I have tried passing the screen position of this object to the call to pick object like this:



but this just returns 0. If I change the start and end range of this call to include the skybox object id then this is returned. I also tried passing the actual x and y positions of the object (using OBJECT POSITION X(10000)), but this didn't work either - and didn't seem the right way to do it either.

Am I just completely misunderstanding this function, or is the problem to with the skybox? I actually want to access some of the other data that is held when the call to pick object is successful.

Any pointers would be much appreciated.
RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 15th Feb 2005 01:13
The command:
Quote: "Return Integer=PICK OBJECT(Screen X, Screen Y, Object Start, Object End)"

Object Start and Object End are a range of objects to check. just ensure your skybox is not within that range. For example, make your skybox object #1. Then use Pick Object(500,500,2,10). This will only return objects from 2 to 10. The skybox object won't be returned because it's not within the range.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Qweeg
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Kent
Posted: 15th Feb 2005 17:12
This is what I am doing, but I still can't get it to return anything.

The code snippet above is exactly as it is in the program. So I am getting the screen x and position of object 10000, and passing this into the PICK OBJECT function, with a start and end range of 10000 - so it should only ever return object 10000. This stops the skybox object being returned - but doesn't return object 10000 - just returns 0. My understanding is that if I am passing in the screen x and y coordinates of this object then it should be returned by this function call.

I mentioned the skybox because if I change the start and end range to 1,10000 (the skybox is object 1) then the function returns 1 i.e. the skybox.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 15th Feb 2005 18:42
This code should explain your problem. Looks like pick object will only work if object in view of camera, presumably to save calculation time.



Boo!
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Feb 2005 20:21
Is your Skybox inside-out (SCALE OBJECT 1, -100,-100,-100)? It should be, and if it's not that may be why you are getting the problem.

I have no idea if PICK objects takes account of volumes or not, but standard DB collision does, and I would imagine they share common features.

BatVink
Qweeg
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Kent
Posted: 16th Feb 2005 05:38
Thanks for your suggestions guys. Batvink - the skybox was okay (I have now tried taking it out and am still getting the problem).

Spooky, thanks for your code - this has put me on the right track I think. The problem seems to be with the object itself. If I use a sphere, then it gets picked, providing as you say it is not too far off of the screen (it seems okay if it is a little out of view) - and so works exactly how I want it to.

However I was using .x model out of Dark Matter to test this, and this seems to behave very differently. If I use your code, so that a message is displayed when the object is picked successfully, then it is really quite hard to get it to work. By moving the camera around I can get the pick to work, but it seems pretty random - just certain spots where it will be picked - unlike with the sphere where it just has to pretty much visible on the screen.

So does anyone know if there is there some fundemental difference in how this function works on .x models compared with DBPro primitives like spheres, or something else to do with the model itself maybe?
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 16th Feb 2005 06:22
First off, make sure you are using 5.7 as previous versions had some problems with pick object on cetain .x objects, usually those where objects 'centre' is at bottom of object, rather than middle. My original bug post about this:

http://forum.thegamecreators.com/?m=forum_view&t=15722&b=15

There were also reports about scaled objects not being picked correctly, and that was also fixed in recent patches.

Boo!
Qweeg
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Kent
Posted: 16th Feb 2005 19:39 Edited at: 16th Feb 2005 19:40
I am running 5.7, so it's not that. I have also tried it without scaling the objects as I thought it may be that but no joy. The only thing I thought was that - as you say - the DBPro primitive objects such as spheres have their "centre" in the centre, whereas the Dark matter objects all seem to be at the base.

It seems as though the pick object works with dark matter models if you view them from the side. What I mean is if you load one of the people - say the zombie in the standard DM pack, then if the model is either directly in front of or behind the camera (so you can see the either the front or the back of the model on the screen) then the pick object doesn't work. However if the camera is viewing the side of the object then it seems to work a lot better. Not sure if I have explained that very well but hopefully you get the gist.

When I get home tonight I'll try it with one of my models, making sure that the 0,0, point is in the centre of the model and see if that makes a difference.

Thanks for all your time on this Spooky
RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 17th Feb 2005 05:34
Question: Are you using the Glue Object command, or any other commands on the object besides direct positioning and orienting commands? The reason I ask is that Glue Object only moves an Image of the object around. The object's xyz coordinates remain the same regardless of where the object appears to be. I haven't played with Pick Object and glue objects, but I suspect it's got the same problems.

Sorry about my 1st post - didn't read the code that closely.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Qweeg
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Kent
Posted: 17th Feb 2005 05:50 Edited at: 17th Feb 2005 05:51
Hi again Riidii,

No I'm not using anything like that. I've can recreate the problem using Spooky's example code for this. The code is below and I have attached the .x model as this may make it clearer. If you just move forward to the model the pick object doesn't really work. If you move in from the side of the model then it does. It seems pretty odd to me (but usually that means I am doing something silly). If you change the code to use a cube instead of the model it seems to work how I would expect.



Oh and no worries about the earlier post. I'm just grateful that people are taking the time and trouble to try and help me.

Attachments

Login to view attachments
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 17th Feb 2005 06:41
Ah right, I see the problem and know the answer!

Reason is picks from front and back is because the picked location is between the feet. Pick object works by tracing an invisible line from the camera 'through' the coords you gice it, until it hits something. When camera is at side of object, camera is below feet and so 'ray' hits furthest foot. You can see this if you replace code at bottom with:



Obviously you would not normally have object loaded and doing pick object in way you are doing. You would normally have mouse coordinates passed. This works perfectly, even when object is scaled.

To make life easier you should offset object centre by sticking this code after load object command:



Your pick code will then work because middle of object is knights body and there is no way ray can miss.

Hope that helps!

Boo!
Qweeg
20
Years of Service
User Offline
Joined: 23rd Sep 2004
Location: Kent
Posted: 17th Feb 2005 07:46
Spooky - you are a genius! This now works perfectly. Thanks so much for your time helping me with this.

Login to post a reply

Server time is: 2025-06-02 14:06:24
Your offset time is: 2025-06-02 14:06:24