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 Discussion / How to determine if a 3d object is inside a particular region

Author
Message
billy777
22
Years of Service
User Offline
Joined: 9th Jan 2003
Location:
Posted: 3rd May 2009 22:49 Edited at: 3rd May 2009 22:51
Please see attached screenshot...

It's fairly easy to determine if an object is in a standard 4 pointed rectangle... however what if you need to figure out the WALKABLE area on the screen (please see screenshot... note that I am placing a 3d object on top of a static 2d image)

I remember Visual Basic having a ptrRegion API or something... where you could make an enclosed a shape made up of several points and determine if something was inside the region.

(This may be even more complicated with a 3d object in 3d space checking against a 2d region)

Any suggestions for Darkbasic...

Thanks
Bill
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 4th May 2009 00:23
im not experianced with collision but i seem to recall being able to custom make collision boxes for objects, if you made a special box for the bridge then check for collision against the player then that would tell u if the player is on the area

There are only 10 kinds of people in the world, those who understand binary and those who dont
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th May 2009 01:01
Hmmm, interesting. Rather than checking if the hero is IN the area, you could place things at the edge to check for collision. Using some basic 3d vector math, you could position small objects at each corner of the region and check to see if the hero's position would intersect that.

If I have time after work and homework tonight I will try to write up some code for it.

Here is the vector math you could use:

Vector=<StartX,StartY,StartZ>+t*<Xdistance,Ydistance,Zdistance>

Where startX,StartY, and StartZ would be the coordinates of the start object and the Xdistance,Ydistance,Zdistance would be the distance traveled from the start to the end point (or the coordinates of the second object minus the coordinates of the first). t is just a variable for time.

So you would use 2 vectors:
1 for the "wall" and 1 for the hero's movement

This would result in 3 equations:
StartX+t1*Xdistance=HeroX+t2*HeroTravelX
StartY+t1*Xdistance=HeroY+t2*HeroTravelY
StartZ+t1*Xdistance=HeroZ+t2*HeroTravelZ

The math to solve for t1 and t2 would use the first 2 and then you plug in the values you find for t1 and t2 into the 3rd equation and see if it satisfies all three conditions. The idea here is it will check for all positions along each line and see if they ever equal the same thing.

I will get back to you if you need help with the algebra and I will try to work out the code if I can

Hope this helps!

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
billy777
22
Years of Service
User Offline
Joined: 9th Jan 2003
Location:
Posted: 4th May 2009 01:02 Edited at: 4th May 2009 01:05
@smartguy... Yes... I thought about doing something like that.

However...because there will be many different locations... each with different walkable areas... It wouldnt really be feasable to create custom objects for each scene...

I would liked to set up my "game editor" to allow me to create regions by just clicking points on the screen with the mouse to define a region.

Therefore each scene and location would have definable regions for walkable area, hotspots, etc.



@BN2 productions - Yes... that might be a workable idea


Thanks
Bill
billy777
22
Years of Service
User Offline
Joined: 9th Jan 2003
Location:
Posted: 4th May 2009 01:47 Edited at: 4th May 2009 01:49
I am trying something here (see screenshot)

I am creating a grid of 40x40 plains - then in my own game EDIT MODE I select which plains are considered walkable - then I check to see if my character is on a "walkable" plain.

Of course all the plains are hidden during actual game mode.


If Anyone knows of a better way to do this - I would like hear it.
Thanks
Libervurto
19
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th May 2009 02:07
you could use OBJECT SCREEN X and Y.
You could then use the 2D coords to check for collision with the boundaries.
The way I would implement this is by making a mask bitmap with just the boundaries on it. Then position a basic shape (square/circle) at the x,y coords you got from object screen, and check 2D collisions.

But to really get the most out of this I think you'd have to work out the 3D dimensions of the landscape. If all the landscapes are flat it shouldn't be too hard to work out the coords based on the camera's location and angle, but having said that I can't do it myself

OBese87 - bringing you the world of today, tomorrow.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th May 2009 08:33
@billy777

Obese87 is on to something that could be fairly simple. How ever you drew the dotted border around the bridge in your first post, make it solid. Everything inside the border color one color. Everything outside of the border, color a different color. You should end up with a 2 tone bitmap. A walkable color, and a non walkable color. Store this as an off screen bitmap.

Using the screen x and y of your 3d object, create an area that is around the feet and maybe up to the knees of the cahracter. You'll need memblocks for speed to check to see if this area ever crosses into the non-walkable color. Should be a pretty fast method.

You could avoid creating a bitmap altogether if you instead use an array that is the size of the screen and stores only the non passable border in the array:
border(x,y)=1 where ever the border is on screen. Again compare the object x and y and expand the area to check against the array if the character is trying to cross a border. Should be easy to implement.

Or

Make a matrix that is oriented to the angle of the scene. You'll only need a few cells - the bridge, and the outside of the bridge. Color the matrix black, set it to transparaent, and raise the edges around the bridge to a certain height. Get ground height under where ever the character will walk. If the attempted move is to a position at that certain height, then the character can't move there.

Enjoy your day.
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 4th May 2009 08:54
Ok, I think I have the math mostly worked out, or at least the method.

The boundary vector is: <Sx,Sy,Sz>+t1#*<X1,Y1,Z1>
The movement vector is: <Hx,Hy,Hz>+t2#*<X2,Y2,Z2>

So your three equations are:
Sx+t1#*X1=Hx+t2#*X2
Sy+t1#*Y1=Hy+t2#*Y2
Sz+t1#*Z1=Hz+t2#*Z2

Giving a total of 6 t1 or t2 equations
t1#=(Hx-Sx+t2#*X2)/X1
t1#=(Hy-Sy+t2#*Y2)/Y1
t1#=(Hz-Sz+t2#*Z2)/Z1

and

t2#=(Sx-Hx+t1#*X1)/X2
t2#=(Sy-Hy+t1#*Y1)/Y2
t2#=(Sz-Hz+t1#*Z1)/Z2

You can substitute any of the first three into the second three (from here on out, the letter a will represent the axis chosen for t1 and b will represent the axis for t2)

These give rise to these two equations:
t2=(Sb-Hb+((Ha-Sa)/a1)b1)/(b2-(a2b1)/a1)
t1=(Ha-Sa+((Sb-Hb)/b2)a2)/(a1-(a1b2)/b2)

There you go. Plug those in and you will see the point of intersection.

Note that you MUST choose two DIFFERENT axes for the t1 and t2 equations and that the denominator of each must NOT be 0 (essentially means that the start point of the boundary vector and the hero's start point must change by the time t=1)

I imagine this just made you more confused didn't it? Let me know where I can clarify.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
billy777
22
Years of Service
User Offline
Joined: 9th Jan 2003
Location:
Posted: 4th May 2009 17:03
Thanks OBese87, Latch and BN2 Productions... Some good options... I will try to see which one works the best.

Login to post a reply

Server time is: 2025-08-08 20:38:39
Your offset time is: 2025-08-08 20:38:39