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 / Hm... Tried search, but what I found did not help. Height Check.

Author
Message
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 16th May 2008 04:42
This is what I got so far. (This is just the code, either run the code in .rar file, or .exe to see it.)

I am having trouble with making the sphere stay over the ground. I searched, and I did find something, tried it out, and it did not work as hoped. Can anyone help me? I want my sphere to stay above the ground, if I was not clear enough earlier. Thanks in advanced.



Attachments

Login to view attachments
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th May 2008 04:50
you're not adjusting the sphere's ypos to the ground height.

It is far better to complete a 10 line program than to start a 10,000 line program.
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 16th May 2008 04:58
I know, I forgot to mention I got frustrated and removed the ypos code. It made it work like crap.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 16th May 2008 18:09
the difficulty is that you're using an object not a matrix as the terrain, therefore DB doesn't know the ground heights.
If you don't know something you have to perform checks, if you don't store the data you have to perform the same check over and over, this could cause your model to bounce up and down (if you are checking collisions and moving up on collision and down without collision).
There are two solutions I can think of: one requires more work and will be faster at run-time, the other requires less work and can be applied to any terrain but it will be slower and less accurate.
The former method is to create an array to store the height of each point on the landscape, the latter method is to make a drone object and place it at a distance below the main sphere, you would then perform the same height checks as mentioned before only now you are checking for when the sphere isn't colliding and the drone is.

It is far better to complete a 10 line program than to start a 10,000 line program.
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 17th May 2008 00:23 Edited at: 17th May 2008 05:52
Well, the method I attempted is worked, but it acted as if the ground model was a box, not land, so it just stayed just above the highest point of the land. That was my problem. I may just get started on working on the array format. See what I can do with that.



Hm.... I am working on the land, and I am trying, for the first time ever, Memblocks, one question though, how do I specify which vertex I wanna find the Y pos on?

Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 17th May 2008 07:36
Eh, due to the fact that my question has slightly changed, I have decided to make a new post here asking a different, yet similar question.

I am trying to make it so that I use memblocks and arrays so I can make the height, but one problem, I need to know the x, y, and z position of each vertex.

How do I select which vertex I am reading the information one? I have 464 vertices in the model, and I need to know each one's position.

Quote: "This command will make a memblock from a mesh. The specified values must be integer values and the source resource must exist or the command will fail. The memblock stores the data as described below.

Memblock-Mesh (32 Byte Header)
-Header
--4 BYTES (DWORD) Number Of Vertices
--4 BYTES (DWORD) Offset in Bytes to Vertice Data
--4 BYTES (DWORD) Number Of Normals
--4 BYTES (DWORD) Offset in Bytes to Normals Data
--4 BYTES (DWORD) Number of Faces
--4 BYTES (DWORD) Offset in Bytes to Face Data
--4 BYTES (DWORD) Size Of All Face Data
--4 BYTES (DWORD) Offset in Bytes to Texture UV Data
-Data
--Vertice Data
---For Each Vertex
----4 BYTES (FLOAT) - X Position of 3D Geometry
----4 BYTES (FLOAT) - Y Position of 3D Geometry
----4 BYTES (FLOAT) - Z Position of 3D Geometry
--Normals Data
---For Each Normal
----4 BYTES (FLOAT) - X Normalised Normal of 3D Geometry
----4 BYTES (FLOAT) - Y Normalised Normal of 3D Geometry
----4 BYTES (FLOAT) - Z Normalised Normal of 3D Geometry
--Face Data
---For Each Face (a face makes a polygon using A,B and C as vector points)
----2 BYTES (DWORD) - Number of Vectors in Face (always use 3)
----2 BYTES (DWORD) - Index to Vertex in Vertex Data for Vector A
----2 BYTES (DWORD) - Index to Normal in Vertex Data for Vector A
----2 BYTES (DWORD) - Index to Vertex in Vertex Data for Vector B
----2 BYTES (DWORD) - Index to Normal in Vertex Data for Vector B
----2 BYTES (DWORD) - Index to Vertex in Vertex Data for Vector C
----2 BYTES (DWORD) - Index to Normal in Vertex Data for Vector C
--Texture Data
---For Each Vertex
----4 BYTES (FLOAT) - U Value of Texture
----4 BYTES (FLOAT) - V Value of Texture "


That is the information in the help file on making a memblock out of a mesh. Ok, I understand that.

Quote: "This command will read a float from the specified location of the memblock. The memblock must exist or the command will fail. The Position value is specified in bytes. The Float returned will be a value between -2147483648 to 2147483648. The parameters must be specified using integer values.

SYNTAX
Return Value = MEMBLOCK FLOAT(Memblock Number, Position) "


That is the float memblock command help file. With that, how do I decide which vertex I want? I looked on these forums and on google, but came up empty handed...

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th May 2008 08:25 Edited at: 17th May 2008 11:37
[Edit]
Obese87 reminded me of a much simpler way than what I wrote previously. I've left it in the post so you can look at it if you want, but here's a very easy way:

Your obejct or the camera has an initial height above the terrain. Create a PLAIN object whose y value is twice the height of the camera (in first person) or twice the height of your object that will traverse the terrain. So if your objects y position was 30, you'd create a plain like this:

Next, set your terrain to polygon collision:


Now, set the plain to the same position as the object. When ever the object rotates, rotate the plain. When you are going to move the object, move the plain first. Test for collision where the plain is. In a loop, move the plain up until there is no collision. As an ELSE clause, move the plain down until there is collision. This will be the ground height (depending on your increments). After the loop, position the object where the plain is and stop all collision detecting until you are going to move again.

[Original Post]

Quote: "With that, how do I decide which vertex I want? I looked on these forums and on google, but came up empty handed..."


Now that is the trick! If you've created your landscape out of a grid in a 3d model program, how does one know the order of the vertices? Is vertex number one in the lower left hand corner or is somewhere else completely? When going through a memblock, the vertices are ordered, of course, but their order doesn't necessarily correspond to the actual position in 3d space relative to the objects size.

I've been working on this problem and have a couple of possible solutions.

1) Get the size of your object in the x and z direction. Divide each direction by the number of tiles you want to store in your array. For example, a terrain that is 10000 x 5000 units, you might divide it up into 25 x 10 tiles. So that means there are 400 units per tile in the x direction, and 500 units per tile in the z direction.
1b) At each tile intersection (every z units by x units) use a small box (like .1 x .1 x .1) or some other small object (a plain rotated 90 degress flat would be best) and move it up or down in the y direction until you detect collision. This is the height at that position. Record the position and the height in your array.

2) Memblock - even if you don't know the order of the vertices, a standard terrain generally runs in the x and z directions with the height in the y direction. If you go through all of the vertices in the memblock, you can create your own order in the array based on the x and z value.

For example, just looking at a terrain, if the coordinates of the first 4 vertices were in this order in the memblock:

(2,1,2)
(1,10,2)
(3,2,0)
(3,2,1)

We can make a couple of determinations. The lowest x is 1, the highest x is 3, the lowewst z is 0 and the highest z is 2. The scale between x and z values seems to be 1. There are only 3 different x values and 3 different z values. This suggests that terrain size is 2 x 2 (the vertices are always 1 more than the cell size so the vertice dimensions would be 3x3)

The idea would be to go through all of the vertices in the memblock and put them in order according to lowest to highest in our array, and at those coordinates use the y height. Since the indexes of an array are not allowed to be floats, you'd convert that later using the scale between values to match against a legitimate x and z position.

So the array (based on this example) might look like:

dim array#(3,3) : rem assuming z is first then x

and the values from our small sample:
array#(0,3)=2
array#(1,3)=2
array#(2,1)=10
array#(2,2)=1

In short, you have to establish the order of vertices based on world positions and store them in an array. That way you can match your position to the array indexes and return a height.

3) You can also use the face information from the memblock. However, you'd still have to figure out which face you are over, calculate the face normal, then using the dot product, you can calculate the height of your position. A bit more complicated but it would be accurate if done properly. It would also eat resources and is better left up to a dll.

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th May 2008 09:29
Latch's 1st method is exactly what i was trying to suggest

@Latch
what do you think of my drone idea?

It is far better to complete a 10 line program than to start a 10,000 line program.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th May 2008 10:47
Quote: "what do you think of my drone idea?"


Are you talking about using a sensor object that tests the height by collision just before the sphere moves to a point? I had completely forgotten about that method - weird because I used to suggest that... Or are you talking about something different? If so, I'm not sure I understand.

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th May 2008 00:34 Edited at: 18th May 2008 00:35
my drone idea is to have a second object positioned slightly below the main object and at the same X and Z co-ordinates.
When the player moves, both objects are moved up or down the Y axis until only the drone is colliding with the terrain.
This would prevent the player from bouncing against the terrain.

It is far better to complete a 10 line program than to start a 10,000 line program.

Login to post a reply

Server time is: 2025-06-05 21:15:43
Your offset time is: 2025-06-05 21:15:43