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.

Dark GDK / Checking for objects

Author
Message
Kurt
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 27th Feb 2008 14:29
I use a method where you can "use" object. As the player press "e" the function checkItem is called to see what object is the closest one, and if it is close enough.

I thought that you can use like a sphere, that is a couple of squares in front, to get the position he is pointing. But then again, how should i know if the sphere is close to an unknown object? An object that I don't know the id of?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 28th Feb 2008 16:36
Having them in array and doing distance checks - shortest distance wins - is one means - but not very fast because distance checks are kind of "heavy"

Kurt
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 29th Feb 2008 07:29
Yeah I know. Is there any other way to do it? Don't wanna slow down my code with lots of loops!
Sephnroth
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 29th Feb 2008 17:10 Edited at: 29th Feb 2008 17:16
dbIntersectObject() is "a way" but I wouldnt recommend it really. I think you'll find it slower than checking distance.

I wouldnt be too scared of distance checks, depending on the amount of objects you need to check against. Use a custom built for speed square root algorithm and see if you can limit the objects you need to check against (is it active, etc).

heres a fast square root and a distance function that uses it:



try it, see what speed you get. try and improve on it by minimising calls or using one of the other distancing methods as nessiary until you get the frame rate you desire.

good luck

edit:

either store the object ids in an array as they are made (cheapest, best) or keep the ids of objects you would ever want to check within a pre-defined range (like say between 1000 and 9000) and create a for loop that runs through that range and if dbObjectExist(id) - do checks - endif. Though thats not so great.

Depending on how your world etc works you could even chop the whole thing up into metaphorical boxes and call them zones. Define the zone edges and then store, with the object id, what zone each object is in (find the zone by getting the objects x/y/z and seeing if its within the box. object_x > zoneleftedge && object_x < zonerightedge etcetc). Then you can which zone the player (or whatever) is in and only perform distance calculations against objects in the same zone - big speed improvement. But maybe a little much to swallow in one go xD

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Feb 2008 17:26
I don't think you actually need the square root function if you are only checking which object is closest to another.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 29th Feb 2008 18:07
Regardless - (Benjamin I think has a point here for the issue at hand)

IT is a innovative routine though - but I found using the vector length method pretty fast also. Might be Interesting to Bench mark your routine and the Vector Length Function. And lay the Whole Distance checking Speed "Best Practice" to rest

Kurt
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 29th Feb 2008 19:19
After reading your posts(thank you very much) I came up with this idea. Or, you guys did. But here is how you could do it.

I could have a number of arrays. And then a void to create an item.
In the parameters sent to the void I can add a couple of properties. Let's say like this:







Oh, this code got a little messy and probably a lot of errors. Please, go ahead and ask what is what and come along with improvements, i need to short down on the "if's". This is just a code i wrote now, haven't tested yet. The basic is that it creates an array with the possibility to check if the object is useable. Then it checks for the distance of all useable objects. And when it has got the smallest distance, it checks if the winner is close enough. I put 10, dunno why. Then it checks if the player is facing it. Get it? Please, comment!
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Mar 2008 16:41
You do know that you need to be a little less wreckless with your arrays right? I mean - I didn't notice any memory allocation - you are blindly overwriting memory with what I see in that code snip.

For Mainstream C++ coding - the array stuff etc ... Scope out the stdlib library - particularly the vector class (dynamic Arrays) ... and I forget which one is for double linked lists - I think its just list.

If it to much to wrap your head around - I have a decent array class - and stuff you can use or learn from here: http://forum.thegamecreators.com/?m=forum_view&t=124748&b=22

Read through that forum so you know what its about - but I released a ton of code in that thread - (link inside there) that has various clesses for dealing with objects - there is a class for arrays..which you can use for int's or type cast as pointers in 32bit programs... out thebox. You could learn from it and tailor it to work with anything you want - including the sort of thing you seem to be working on in your code above.

Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 1st Mar 2008 17:47
One approach that required less work would be to create a sphere that encompasses the range you wish then check for colliding objects. If you need a snippit let me know, if you create one please post for all to learn

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem

Login to post a reply

Server time is: 2024-09-29 13:35:45
Your offset time is: 2024-09-29 13:35:45