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 / Find the Angle/slope of the terrain

Author
Message
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 6th Feb 2014 02:54
I want to be able to find the angle of the terrain at a given point. Is there any way to do this with ray-casting? I imagine that you would need to use more than one ray-cast, then possibly use the heights (y-value) and the distance between them to determine the angle/slope of the incline.

What I want to be able to do is position box on the terrain at random locations that are "aligned" to the ground. Rotated in such a way that they bottoms are flush with the ground slope.

I hope I explained what I am trying to accomplish. Any help would be greatly appreciated. In the meantime I will be working on a simple code snippet that hopefully can be expanded upon to show the solution.

Thanks everyone.
Dia
20
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 6th Feb 2014 05:06
Depending on what you are using for your raycasts, sparky's collision dll and dark dynamics raycasts for example, both of which return the collision normal (i.e. Surface angle) of the ray collision, and can be used to align your box objects to the ground

This is not the sig you are looking for....
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 6th Feb 2014 11:02
Quote: "Is there any way to do this with ray-casting? I imagine that you would need to use more than one ray-cast, then possibly use the heights (y-value) and the distance between them to determine the angle/slope of the incline. "


You are right !! and as Dia say, we can achieve that in lots of ways. This code snippet works in a matrix, but also can be adapted to Advance Terrain.




Cheers.

I'm not a grumpy grandpa
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 6th Feb 2014 20:05 Edited at: 6th Feb 2014 20:29
Here's a tilt function by Latch that will work on a Matrix or Terrain. (Use Get Terrain Ground Height for terrains.)



To call it, just use tilt(mat,obj,pivot)
(There may exist better versions of this by now.)

A full, working example can be found here:
How Do You Tilt An Object On A Matrix?

Look for the post by Latch.
It's a little confusing because it uses a 'pivot object' in conjunction with your main object, but it works.

david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 6th Feb 2014 22:31 Edited at: 6th Feb 2014 22:33
I really appreciate all the responses. They have been very helpful. I did some searching on the forums and found some really helpful code.

Needless to say I can't use any functions that rely on the DBP functions: wrapvalue and newxValue, and their equivalents. I can however use sin/cos and any other math functions to solve this problem.

I'm trying to make this work on multiple languages that's why I cant use those functions.

This is what I have come up with.






The problem I am having is that while it works great in DBP it doesn't work so great in c++ It almost works like it should be there are random rotations on some objects.

If there is another way I can go about achieving these results any ideas would be greatly appreciated. thank you.

I really can't use any built in functions or dummy objects or tilts or object limbs. Just the base object itself and the Y height of the intersections. I thought I could do it using ATAN2 but I couldn't work it out.

Attachments

Login to view attachments
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 6th Feb 2014 23:14
This is another example that use only coordinates. Take a look if you can convert it to c++ .



Cheers.

I'm not a grumpy grandpa
Dia
20
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 7th Feb 2014 00:52
Just out of interest, how far does your ban on db commands go? I mean, given you are already using dbpro commands to load and position objects, the camera commands etc. The newxvalue and wrapvalue commands can be fairly simply written from scratch, the raycasts can be written from scratch as well, convoluted, but fairly straightforward to implement

This is not the sig you are looking for....
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 7th Feb 2014 03:27
Well I can understand what your saying, but its not all that bad. Just anything that isn't relying on the objects orientation basically. such as roll/pitch and anything that would be a limb of that object as a helper. for example sin and cos are basic functions across many languages, where wrapvalue is pretty much only found on DBP. DBP stores the rotations on internal data structures so I cant use anything that would rely on those. Basically I can only do this using Position, Height, distance of raycasts and trig. I almost have it but not quite. Thanks.
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 7th Feb 2014 03:28 Edited at: 7th Feb 2014 03:29
I simply want to cast a couple of rays down onto the terrain and determine the angle of the incline.

Then I want to figure out how much to rotate the box object on the x and z axis in degrees.

There is no need for any fancy ground following techniques or terrain hugging. I know that's the basis of what everyone thinks I'm after. I simply want to position box objects aligned to the ground. I only have to run the function once for each box as I showed in my example.

Thanks everyone.

Login to post a reply

Server time is: 2025-05-16 02:07:01
Your offset time is: 2025-05-16 02:07:01