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 / Matrix / Terrain Using Memblocks

Author
Message
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Jun 2012 03:06 Edited at: 16th Jun 2012 21:03
UPDATE
06/16/2012
Lowered tilex X tilez size of crinkle metal example to help accommodate varying machine specs. Zip file has been updated.

06/14/2012
Corrected an error in the way getMemMatrixHeight() was reading floats from the DLL. The zip file has been updated.

06/11/2012
Ok, I've tweaked the functions a bit in my DLL version of Kelebrindae's memblock matrix library for DBC. The first release is ready so:

Get it Here




Check the README.txt file for general operation and information.

Most of the examples use the arrow keys to move and the mouse to steer.

You'll notice in the height map example, I use another library called TXSynth to generate a perlin noise height map and to convert that height map into a texture map. I compiled the source code into a DLL and added an export table for use with DBC. If you look at the documentation and the source code for TXSynth, you should be able to get an idea how to use it. It generates textures on the fly and has a very low overhead signature.

Here's the original memblock matrix library.




ORIGINAL POST:

Years ago, a user named kelebrindae put together a quite complete set of functions to create and manipulate Matrix/Terrain objects using memblocks. I decided to go through this library and convert it to a DLL.

The advantage of the DLL is speed. For the most part, I converted the code directly to C. In a few cases I rewrote or corrected a couple of things but in general, the code is the same in the DLL as it was in DBC. I threw in a few more functions - some for querying and resetting data, others are just in there for fun.

Here's a quick list of what kelebrindae's memblock matrix library does:



Here's a few extra functions I added:



I'm once again trying to see if there is community interest. Would anyone be interested in using this? I'll probably post it either way.

Enjoy your day.

Attachments

Login to view attachments
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Jun 2012 20:10 Edited at: 8th Jun 2012 20:13
I have two ideas of things you could add:

*Diffuse setting for each vertex (is this supported in DBC? If not, disregard this).
*Gaussian function

Here's the gaussian function I wrote way back in the physics challenge: http://forum.thegamecreators.com/?m=forum_view&t=133847&b=6

You would probably have to add a few more parameters so you can add local gaussian hills, not so it uses the entire mesh and flattens out areas you already created. Another idea would be to have the gaussian hill blend in to what is already on the terrain.

[EDIT] As to me using it: nope. If you made it for DBP I bet you'd get a much stronger response though.

TheComet

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Jun 2012 01:34 Edited at: 13th Jun 2012 22:45
Quote: "I have two ideas of things you could add:

*Diffuse setting for each vertex (is this supported in DBC? If not, disregard this)."

What would this do? What advantage would it have over a texture?

Quote: "*Gaussian function"

Neat! I'll add it in.



Do you know how to change the fall-off? By that I mean the shape of the sides of the hill. I'd like to be able to create a more inverted parabolic shape in addition to the dome like shape the function does now. I'd like to be able to control the point and depth of the fall-off so I could make a very pointy hill/spire, or a voluminous, billowy hill. Or have a random fall-off that would make a varying shape.

Enjoy your day.

Attachments

Login to view attachments
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Jun 2012 17:00
Quote: "What would this do? What advantage would it have over a texture?"


You could create dynamic lighting by colouring the vertices separately according to multiple light sources. This is how MineCraft did it in Beta 1.7 and lower. It's a very powerful technique and extremely resource friendly.

Quote: "Do you know how to change the fall-off? By that I mean the shape of the sides of the hill. I'd like to be able to create a more inverted parabolic shape in addition to the dome like shape the function does now. I'd like to be able to control the point and depth of the fall-off so I could make a very pointy hill/spire, or a voluminous, billowy hill. Or have a random fall-off that would make a varying shape."


As far as I know there's no way of doing that with the Gaussian formula alone, but it would be possible to blend it with a parabolic function. I'll see if I can get something to work.

Have you thought of making it possible to shift the vertices on the X and Z axis as well? That's usually not possible with a matrix, but since you're using a mesh, you could add that in order to make overhangs and other cool formations. If you're bothered, you could even extend on that and make it possible to extrude surfaces. Just some ideas though.

TheComet

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Jun 2012 20:58
Lot's of interesting ideas.

Quote: "Have you thought of making it possible to shift the vertices on the X and Z axis as well? That's usually not possible with a matrix,"

That's in there. I put in functions to set and get any 3d coordinate (X and Z as well as Y).

Quote: "You could create dynamic lighting by colouring the vertices separately according to multiple light sources. "

Even though vertex coloring is supported by DirectX 7, I've never tried using a model with vertex colors set so I really don't know how DBC would respond. The only way to maybe get this to work with a memblock matrix would be to

1. have some method of storing the diffuse color per vertex (which wouldn't be visible until maybe the next steps)
2. Export the matrix as a directX file without a Material definition and with vertex colors and the vertex color template included
3. Load the saved file as a new object.

Enjoy your day.
YoshiDoshi
11
Years of Service
User Offline
Joined: 11th May 2012
Location:
Posted: 10th Jun 2012 05:56
As I'm not that far in 3D, excuse my noobness.
But would this allow you to edit a matrix in realtime like simulate a crater impact?

Thanks

Cheese
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 10th Jun 2012 11:56
Quote: "As I'm not that far in 3D, excuse my noobness.
But would this allow you to edit a matrix in realtime like simulate a crater impact?"

Yes and no. Yes, the means to alter the matrix in real time exists, but the simulation would take some programming. If you want the deformation of the matrix to follow the shape and path of a colliding meteorite, then you would have to manage the collision of the individual vertices of the matrix so that you can program the reaction. This is possible with the use of ColDet collision which I posted in another post - but it would take some planning, understanding and knowledge to do.

On the other hand, you could use a generic crator shape that would be formed regardless of the shape of the impacting object. This would save you the calculation of the individually displaced vertices as you would use the same crator shape no matter what. And in this case, you could simply use getgroundheight() if the colliding object was close enough to the matrix/terrain to be considered a hit.

So, in answer to your question, yes, you could use this library to simulate a resulting crator from an impact in real time. But the library won't do it for you. You would have to decide on how you want to handle it and code that yourself.

Enjoy your day.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Jun 2012 22:47
Cloth screeny

Enjoy your day.

Attachments

Login to view attachments
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Jun 2012 22:51
Mountain Screeny

Enjoy your day.

Attachments

Login to view attachments
Fluffy Rabbit
User Banned
Posted: 14th Jun 2012 01:35
Wow, this is very exciting. I'm sure that it would be completely straightforward to get this to work with ColDet, but unfortunately I still haven't figured out how to use the collision library. I suppose Dark Survival 2 is still something on the horizon.

Anyhow, it would be nice to see an example of the kind of meteorite collision you were talking about, with a mesh that used ColDet to determine how exactly it impacts the terrain, and deform the terrain accordingly.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 15th Jun 2012 00:40 Edited at: 17th Jun 2012 23:07
Quote: "Anyhow, it would be nice to see an example of the kind of meteorite collision you were talking about, with a mesh that used ColDet to determine how exactly it impacts the terrain, and deform the terrain accordingly."


To follow is a crude example of the idea.

The example assumes that in the directory where the program is run, you have a subdirectory named 'lib' . In this directory should be the DBC libraries and dll files for ColDet and the memblock matrix.

Move the camera around with the arrow keys.
Hold the RIGHT mouse button and move the mouse to rotate the camera.
Hold the LEFT mouse button and move the mouse to raise or lower the object to collide with the memblock matrix.



Quote: "...but unfortunately I still haven't figured out how to use the collision library"

What doesn't make sense? The setup goes like this

1. Load the coldet include file and the dll
2. initalize coldet
3. load your model
4. set up your model with coldet collision
5. detect collision with the model either
model to model
model to sphere
model to ray
6. Do something if collision is detected

If you don't want to use a model:
steps 1 and 2 still apply
3. detect collision with either
sphere to sphere
ray to sphere
4. do something if collision is detected

Enjoy your day.
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 15th Jun 2012 12:35
hi,

this dll is very interresting.
(The snippet "specular_crinkle_metal" does not work, black screen displayed.)

@+

DirectX 9.0c (February 2010)/ DBClassic v1.20
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 15th Jun 2012 21:32 Edited at: 15th Jun 2012 21:35
@Silverman

Quote: "(The snippet "specular_crinkle_metal" does not work, black screen displayed.)"


That's odd. It should show two rotating bumpy grids changing color by light reflection on the surface. it should transition between silver, white, blue, and black.

Do you get an error message? Do the other examples work? I looked at the code in the zip file and the code that I'm running on my machine and they are the same.

Perhaps there is a lighting problem?

Try adding this line at the top after POINT CAMERA 0,0,0 and before DO

...
point camera 0,0,0

set object ambient 1,rgb(255,255,255)

do
...

Does that show a washed out matrix? (the colors should be too white)

Enjoy your day.
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 16th Jun 2012 00:44
I have no error message. My first investigations show that the problem is not from your dll. I think this is a limitation of my computer, because if tilex*tilez > 10922, the objects disappear. Maybe I can not display many vertices that your computer .

DirectX 9.0c (February 2010)/ DBClassic v1.20
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Jun 2012 21:08
I lowered the tilex * tilez on the download for that example. See if that makes a difference.

Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Jun 2012 01:31
These are really nice Latch, especially for DBC! How did you do that shading on the terrains if I may ask?

TheComet

Fluffy Rabbit
User Banned
Posted: 17th Jun 2012 08:50
@Latch-

You actually came up with a meteorite example! I will have to test this when I get home.

As far as my confusion goes, it is not the simple logic that gets me but the technical details. So far, I have adapted your warehouse example to use an alternate control routine, and all works except for the fact that gravity seems to happen instantly, pushing the player to the ground in what looks like one frame, the moment the player drops from any height. Nice and smooth X and Z collisions, though. By the way, how would one use your easy player collision function to probe all of the meshes? In the example, it only appears to be checking collisions with mesh 1, and Dark Survival 2 has environments made up of many different objects.

Regarding your terrain library, I hate to do this, but check the image.

Attachments

Login to view attachments
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Jun 2012 12:23 Edited at: 17th Jun 2012 23:04
Quote: "I hate to do this, but check the image."

It's supposed to be like that. It demonstrates that the UVs can be manipulated to rotate and place any section of the image across any number of tiles. If you read through the code in that example you'll find:



Quote: "...and all works except for the fact that gravity seems to happen instantly"

You have to control the rate of gravity yourself. In the warehouse example this is controlled using

You'd have to find values and use a method suitable for your environment.

Quote: "By the way, how would one use your easy player collision function to probe all of the meshes? "

By this I assume you mean the experimental sliding collision function and not the the general collision.
Change the collision object number in the function to whatever collision object you've set up. You have to test each object independently with the sliding collision function.

Enjoy your day.
Silverman
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 17th Jun 2012 15:19
it work fine

DirectX 9.0c (February 2010)/ DBClassic v1.20
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 17th Jun 2012 23:14
@Silverman
Good. I'm glad it was as simple as reducing the tile size. I know I've run into some weird behaviour with DBC and certain mesh sizes before, but I've never been able to track down a specific size under a specific set of conditions. I can make a memblock mesh that is 120 x 120 tiles big using these matrix commands and that's 28800 polygons. But I can't load in an object and convert it to a mesh that has the same polygon count if the original object only contains 1 mesh. So it's very strange.

Enjoy your day.
Fluffy Rabbit
User Banned
Posted: 18th Jun 2012 00:53
@Latch-

Quote: "It's supposed to be like that. It demonstrates that the UVs can be manipulated to rotate and place any section of the image across any number of tiles."

Awesome. My mistake, then.

Quote: "You have to control the rate of gravity yourself.
...
You'd have to find values and use a method suitable for your environment."

How would I do something where there is zero gravity? How would I take care of abrupt vertical collisions? Your method returns a useless Y value in cases where it should just return a number that indicates no collision. Take this code for example:


I'm tempted to just use sphere and ray collision and make my own collision function.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Jun 2012 04:47 Edited at: 18th Jun 2012 21:49
This thread has gotten off track a bit. It should be about the matrix memblock functions. All other questions about ColDet should be in the ColDet thread.

Quote: "Take this code for example
"

@Fluffy
Though you are using the basic framework of my code, the additional code and function you've inserted, camStrafe(),
doesn't seem to be accounting for a change in height at some defined rate. Gravity is an acceleration. In error, you call the returned Y value useless but it is this value that you can use to calculate your change in height over time. If the return value is undefined or the difference between your current Y and the returned Y is too great, perhaps your character falls to their death or you jump to a routine that does something else. If it is within a survivable distance, then you calculate the new position using gravity until a specific height or difference between Y's is reached. There are more than enough tools within coldet to return a true-false indication of whether or not there is collision. You could test for collision first by some other means and if the conditions are within your desired results, then call sliding collision. Or only use the sliding collision for X,Z positions and calculate Y using ray casting. The tools are there. The experimental sliding collision function isn't going to fit in automatically to every scenario, nor is it meant to. The programmer is ultimately going to have to handle the collision responses.

Quote: "I'm tempted to just use sphere and ray collision and make my own collision function. "

No, no no, don't be tempted, JUST DO IT. Create your OWN collision functions. That will help you gain understanding and control.

Enjoy your day.
Fluffy Rabbit
User Banned
Posted: 18th Jun 2012 21:35
@Latch-

Just do it? OK. Here is a fixed version of the above:



Attached is a version of the Dark Survival 2 engine that has ColDet incorporated into it. Finally, efficient physical psuedo-realism in DarkBASIC. Many thanks for your library.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-29 04:59:54
Your offset time is: 2024-03-29 04:59:54