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 / 'vertexdata' How to add vertices?

Author
Message
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Jul 2011 16:02
Yup, I decided against using potrace because it's output formats were limited. It's mainly for exporting to other editors.

After having a look through tons of pages and documents about converting polygons with holes, I'm now getting a much better understanding of it. I'm very patient, sometimes slow at learning some of the really tough maffs but I do get there.

'Triangle' does a great job for multiple purposes and outputs in very simply text files, no converting needed at all. Until I actually work on writing the code myself using the ear-clipping method.

I've also sussed that I can do some heavy duty calculations in C++ and just use the 'execute executable' to call them. It would be nice to link compiled object files from C++ directly but until I suss dll's then I'll do it this way.

I'm still struggling tracing my own outline of the generated map, I'm considering something slightly different to generate it just by drawing vectors instead of a bitmap style of generation.

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jul 2011 22:10
Quote: "I've also sussed that I can do some heavy duty calculations in C++ and just use the 'execute executable' to call them."


Interesting you should mention that. I was thinking of suggesting that solution to someone else for a different problem - and might use it myself.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Jul 2011 01:27 Edited at: 17th Jul 2011 04:32
I've looked in to a new method to generate a pseudo random level and it's so much easier. I'll need to use an array before creating the mesh data first though, but it does skip so many of the previously mentioned steps.


*typo in image* edge not face...

It is kind of the reverse of ear clipping triangulation but starting from scratch...

It now looks like I'll be scrapping all my old code and starting the level generator all over again but with faster, fresher ideas. Back to actually working with the internals of a 3D object again without getting stuck this time...

@Green Gandalf - I might eventually convert the new code into an exe file and run it from there. Unless I write a lot of heavy calculation code and put them into an exe and just use a command like switches to produce the data. Experimentation is needed there.

@NeuroFuzzy - Very nice... I knew it could be done but never looked into it.

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Jul 2011 03:27
Using the previously mention ‘walking triangles’ method I’ve made a start with my code. Well, I’ve got the UDT’s defined and the rest of the code inside my head ready to come out. It’s been a long day and I’m knackered…

Here’s a quick knock up of a diagram that explains the generation algorithm: the image loads 99% of the time



And hardly any vertices used but still the Index count can climb quite high, but at least this can actually be kept in check during the generation code. If the Index count tries to go over the 65535 limit then the code will complete and return what it has already got.

On a good note too, this code can be used to generate levels while a game is running as it will be very quick. (I will benchmark both DBPro and C++ generation code.) This will be a bonus feature as a game can have portals, teleporters, ladders, stairs which take the player to another section completely. Placement of level objects can be done using the 'inner edge' list.

Now to get on with the coding in DBPro first…

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jul 2011 13:59
Quote: "Now to get on with the coding in DBPro first…"


Sounds good. I look forward to seeing it.

Not sure how you are choosing the next vertex at each step. Is there a risk you might get long thin triangles after a certain point? You might want to put some checks to stop that.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 19th Jul 2011 15:10
Yep, I'm going to put in line length restraints (which can be adjusted during testing) and also restricting the angles of the lines.

Seeing as each of the edges of the main outline polygon all go clockwise I can choose my angle from the first point in the random edge chosen. And using a check 'PointInPolygon()' then I can scrap the creation of a new point if it's within the main polygon.

I should in theory be able to create 20,000 triangles (faces) approx to generate a floor map, making a total of 60,000 indices and not going over the DBP limit.

Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jul 2011 16:09
There are a couple of things with your algorithm that are not exactly wrong, but something you may want to look into:
1. When you pick your new vertex, you probably don't want it to overlap with an existing poly.
2. You will produce a layout that will contain 'blobs' (not the problem), with a single corridor between them (this is the problem), ie there will only be one way to get from blob A to blob B, and in fact from any blob to any other blob.
3. There will be many dead-end corridors.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Jul 2011 01:18
@IanM - What I might do at the end of this is randomly connect some edges along the main outline polygon. So far the main polygon won't have any holes in it. The connecting edges I will check for distance and other checks to see if it's a valid connection.

Currently I'm stuck trying to check if a point is in a triangle. Trying to find some helpful pointers on google but not coming up with anything yet if anyone has anything?

I just want to check if point x, y is in triangle x1, y1, x2, y2, x3, y3.

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jul 2011 01:51
I'm sure I've got some code that does that. I'll try to dig it out tomorrow. I got it by Googling by the way so you should be able to find it.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Jul 2011 02:31 Edited at: 21st Jul 2011 03:05
I'm just trying to convert http://www.anderswallin.net/2007/06/point-in-triangle-test/ this to DBPro code. Basically checks if a point is to the right of each line. If it is then it's within the triangle.

Still trying to find out how to work out how to check if the point is to the right...

EDIT:
I've found something at last - http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jul 2011 12:52 Edited at: 21st Jul 2011 13:55
Sounds like the right sort of thing but may be rather more than you need.

You could give this a try. I can't recall now whether we got all the bugs out but I think we did (within floating point precision). It was code that RUSSIA and I were working on. I'm sure it could be tidied up a bit.



Edit Here's the link to the original discussion. The "point in triangle" issue was discussed about halfway down the thread. I give a link in one of my posts as well.

triangle issues
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Jul 2011 15:24
As it's a floor/ceiling that WLGfx is trying to generate, then the Y component of triangles should be set to 0 when checking for triangle overlap.

Alternatively, a 2D check would be much more efficient: http://www.thegamecreators.com/?m=codebase_view_code&i=2bcb484ca7ce23bd2372ad00984d5002

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Jul 2011 16:03 Edited at: 21st Jul 2011 16:18
Yes, that helped a lot. Thanks Green Gandalf. I had a look at Russias thread too.

I think last night I was getting very tired and my brain cell wasn't functioning.

I think I'll just go down the route of checking each of the individual triangles and exit the function if it finds one that the point is in. If not then the new vertex/face/edges can be added and the old edge placed in another array.

EDIT:

@IanM - Brilliant. That'll help a lot. Going to implement that piece now. I should have an example sometime today.


Now to test it...

Another thing... Can a UDT have UDT's inside it?

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jul 2011 16:20
Quote: "Alternatively, a 2D check would be much more efficient"


I'm sure it would in this case. I overlooked that.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Jul 2011 18:53 Edited at: 27th Jul 2011 17:15
Well, I've added a little piece to the code that creates triangles as separate objects just to see the progress until it finally works. So far I just get 1 triangle showing.

I've attached the project. but I think the problem is somewhere in this piece:



EDIT1:
I've altered acos and asin to cos and sin. A bit better...

EDIT2:
I've also just changed this in the above function:


EDIT3:
Re-uploaded the project with a few bugs removed but still ain't working properly but at least triangles are now being created...

EDIT4:
The vertex in poly check is working fine. But for some reason the new faces that are created are overlapping. I've been staring at the screen for ages now trying to find a typo or something. (Re-uploaded the project)

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 25th Jul 2011 03:36 Edited at: 25th Jul 2011 16:17
I'm at a point were I'm stuck and I think it's within this function where I pick an edge, find out it's angle and change the angle to create another face. Am I using the ATANFULL function wrong or are my COS and SIN functions wrong. I've played with the figures and nothing seems to be working.



The full project is in the above post, it uses Matrix1 Utils...

EDIT: I'm suspicious that I'm not getting correct angles so I've been looking into dot product stuff. The normal tan() function gives angles from -90 to 90. So I'm thinking maybe using another check I can get a full 360 check. I'm getting lost in this trig stuff... Argh!

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Jul 2011 14:31
I'll take a look later today.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 27th Jul 2011 17:18
After much fiddling about with the code I've decided to restart this project in C++ and GDK. At least with C++ I can use the standard math libraries as well as a much clearer way using structures and classes.

I'll be using my current code as a basic template. I'm determined not to give up on this.

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 29th Jul 2011 17:25 Edited at: 30th Jul 2011 16:13
@Green Gandalf - I've restarted in C++ and found it much easier to actually code. I'll start a new thread in the GDK section as the generation code develops. Using the code above as a baseline I've adapted it for C++ and it works great so far. Easier to debug too.

I will be coming up with some other algorithms to generate a bitmap image using thick drawn lines and possibly implementing 'Triangle' to generate the mesh.

Definitely getting somewhere now I can use explicitly declared variables which is what I think the problem was in DBPro.



Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2011 01:05
Quote: "I'll take a look later today."


Oops.

Sorry. Been busy with guests. Sounds like you're making progress. But one thing puzzles me:

Quote: "Definitely getting somewhere now I can use explicitly declared variables which is what I think the problem was in DBPro."


What was the problem exactly?
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 30th Jul 2011 16:24



I'm not sure exactly what the problem was in the end with Dark Basic version. I know that undeclared variables always initialise to zero and if there 'was' a typo then that would have happened. Plus I found it much easier to use the standard c math library and just work in radians instead of degrees. I did however find that the atan2() function in c used disty, distx, in that order. I also think that might have been the problem with the Dark Basic version. The atanfull() command might need the x and y values the other way around like the c version. I might double check some things later.

The point were I am at now is as you can see in the image is that lines are crossing each other so I need to check for intersecting lines before I can lay down the new face. The code runs almost instant so far, so another quick check won't make any difference to the generation of the level. I've seen some trig examples through google searching so it's just a case of implementing one of those now. Fingers crossed I'll have the complete level generator up and running shortly...

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2011 23:33
Quote: "I know that undeclared variables always initialise to zero and if there 'was' a typo then that would have happened."


Ah, I see what you mean. In other words the problem is the possibility of implicit declarations allowed in DBPro not the explicit ones.

Quote: "The atanfull() command might need the x and y values the other way around like the c version. I might double check some things later."


I haven't noticed that - unless it's where the angle is measured from. Should be simple enough to check with some elementary examples.

How do other people avoid crossings with the walking triangles idea?
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 31st Jul 2011 15:22 Edited at: 31st Jul 2011 15:45
I'm scrapping the checking for a point inside a polygon test. Although it works great and is fast, I will have to check for intersecting lines instead. This should then stop the walking triangle from overlapping. I've got some sample code from google I should be able to implement.
I'll only really need to check against the outer array of the edges.

I'm also going to randomise the angle of the new line created to about 10 degrees either way of 45 degrees. This should make for more interesting map layout.

'Implicit' variables... I'm getting my words mixed up now. They've been a thorn in my side with DBPro. Especially as source file grow larger and it gets harder to keep track of everything. Visual Studio's code definition window is an amazing useful tool for programming as each function, variable, etc you type it will show its definition.

With the outer edges of the polygon floor map stored separately I can easily use those coords for the walls once it's finished.

Hopefully I get a quiet Sunday and I can get this completed today.

EDIT: I've just changed the ATANFULL(x,y) to ATANFULL(y,x) and the DBPro version now works the same as the C++ version. The documentation in DBPro shows that ATANFULL() command to be wrong.

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2011 00:06
Quote: "'Implicit' variables... I'm getting my words mixed up now. They've been a thorn in my side with DBPro. Especially as source file grow larger and it gets harder to keep track of everything."


I agree. It's the main thing I find annoying with DBPro. I like to be warned if I've used a variable which hasn't been declared rather than spend ages debugging a program only to find that I've misspelt something on one occasion.

Quote: "The documentation in DBPro shows that ATANFULL() command to be wrong."


Why? The DBPro Help file is useless in this case and gives you no way of finding out how the command works so how can you say it's wrong.

Actually, this is rather strange because I thought the Help file entry for ATANFULL had been corrected in response to a complaint by Jeff Miller some time back. This is what it says on my copy:

Quote: "ATANFULL
This command will return the angle of two points in degrees between 0 and 360.

Syntax

Return Float=ATANFULL(Distance X, Distance Y)

Parameters

Distance X

Float
This value is a float number such as 0.5
Distance Y

Float
This value is a float number such as 0.5

Returns

This value is a float number such as 0.5

Description

The distance values are calculated by finding the distance between two points for both the X and Y axis. The distance values can be a real or integer number. The return value is a real number."


Try drawing a picture from that and working out what DBPro is doing.

If you know what you're doing it's easy to see what DBPro is doing but that's hardly the point.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 1st Aug 2011 01:44
The C++ version is atan2(distY, distX), and after getting that to work with my project, I thought I'd re-check the DBPro version. All I did was to swap the X and Y around so I now had ATANFULL(DistY, DistX) and that version worked perfect instead of going by the documented version. It does seems to be the same as the C++ version.

My help file on the ATANFULL() is exactly the same as in your notes, but when I altered my code it work the other way round.


I was pulling what was left of my hair out at the time trying to figure out what was wrong with it. It was only when I came to change over the C++ and GDK that I thought I'd swap them over. If I'd have sussed that out at the time I would have stuck it out with the DBPro version of the project, but I've now come a long way with my current C++ version.

The check for the point inside triangle/polygon didn't work out in the end as some faces (more like lots of them)were overlapping so I've now incorporated a line intersection check instead. I am almost there. So far it gets stuck in an infinite loop because I'm trying the get it to not check certain edges were the vertices are the same because this will invalidate the line check. Here's what I have so far:


Part of the header file:


Once it's all completed I will leave it as free open source for anyone to use. I'll probably have a go at building a game out of it in the end though myself just for the fun of it.

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2011 01:50
Quote: "but when I altered my code it work the other way round."


Other way round from what?

The Help file doesn't tell you. There are two angles involved, adding to 90 degrees, and DBPro reports one of them - but the Help file doesn't say which it returns. My guess would be that DBPro uses the C++ version - whichever that is.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 1st Aug 2011 03:48 Edited at: 2nd Aug 2011 05:24
Quote: "Other way round from what?"


Originally I was using it as 'angle = ATANFULL(distX,distY)' but when I swapped the distX and distY around it worked perfect. As far as I can tell it must be using the same as the C++ 'atan2(distY,distX)'.

After lots of googling about the atan2() function I found how it worked and based my code around that information. I then just assumed it would be the same for the DBPro version so all I did was to change the X and Y round. The only difference is the DBPro returns it's result in degree and the C++ returns its value in radians...

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Aug 2011 13:04
You can use either of course - as long as you know what you are doing, i.e. which angle is being returned.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Aug 2011 05:40 Edited at: 2nd Aug 2011 05:52
@Green Gandalf - I've got to say a big thanks for just spending a little time keeping up the chatting whilst my head has been hitting every wall along the way. It's kept me going and I've finally got it working.

A screen shot showing the current progress. No crossing faces, random tunnels. Just ignore the horrid colours for now.



The outline of the floor map is stored in an array of it's own so that I can simply use those coordinates to generate the walls. The other edges that are not part of the polygons outline are in another array and they can be used to place items into the game.

So far on my very slow laptop it takes approximately 1 second in debug mode to generate 1000 triangle faces using my walking triangle algorithm.

I've attached the C++ project (for Visual Studio 2008 Express) with an executable which generates 1000 faces. All source code is commented.

To look around the scene hold down a mouse button, move mouse and use cursor keys.

My next step is to generate the walls and ceiling of the map and then to texture them. With the decent layout of the triangles I should be able to multi-texture the generated level too.

And again, thanks to both Green Gandalf and IanM for keeping me sane.

EDIT: Will this need to moved to the GDK or WIP forums?

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Aug 2011 13:05
Looks good. I'll see if I can do anything with your C++ project - I've got VS/C++ but it's all still a Dark Art to me.

I'll probably have to wait for my next reincarnation before I get to grips with C++ - with DBPro all the hard work is done by Lee and IanM so the rest of us can just code.

Quote: "Will this need to moved to the GDK or WIP forums?"


Hard to say with a thread like this. If it's still a WIP then it might be worth starting a new WIP thread with a link to this one.

Quote: "And again, thanks to both Green Gandalf and IanM for keeping me sane."


You're welcome.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Aug 2011 17:19
After bouncing between both DBPro and C++ GDK, I've actually found that C++ is easier for me. Possibly because I spent most of my earlier years with C on the Atari ST and the Amiga computers. I do know that in DBPro you can just write some code and it runs. In C++, just to print some test values on the screen the code is ten times as big. Although you can have multiple projects inside just one solution in Visual Studio.

Ealier on in this thread, IanM gave some sample code showing how to create a 3D model from scratch. After looking through the DBPro/GDK documentation I've found that the example given was using the Matrix1 Utils but this is for DBPro only. I'm currently still searching the forums to see if there is anything in them that might help.

I have an array of vertices, an array for the faces with the index of the vertices, an array for the outline of the map and an array for the inner edges too. These are ready to be converted now into a 3d object and some other stuff done to them to create my walls and ceilings.

The VertexData command set only works on already made objects.

So... How do I make a 3d object from scratch? This time in C++ GDK.

NOW I'M STUCK AGAIN... LOL

The idea for the game I want to build using this is simple. Create a few small maps for each level and have portals linking them. The player will have to go through the level finding maybe keys to unlock corridors, collect all the goodies and shoot things along the way. The levels will be unlimited to because of the pseudo random level generator algorithm I've done.

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Aug 2011 19:05
Quote: "How do I make a 3d object from scratch? This time in C++ GDK."


Now that is a question for another board. Sounds like it's worth you starting a new thread on the Dark DGK or Programming Talk boards.

For this sort of low-level stuff it's probably worth you looking at the MS DX9 SDK docs. That uses VS C++ and has plenty of useful examples. You can download it free from Microsoft. I use it a lot for the DirectX part of the docs. I occasionally browse the C++ stuff to see what's available but the code itself is alien.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Aug 2011 19:26 Edited at: 2nd Aug 2011 21:52
I've noticed that over these last 6 or so months there have been some people or person that has managed to integrate DirectX stuff, objects, particles, etc directly with the GDK screen. I'll be having a look into that definitely. If I can eventually use both then that will help.

For the time being I'll just stick with the dbMakeObjectTriangle() command and build all the inside of my level that way. I will probably have to use the standard vertexdata commands to modify the UV data though but I'll figure it out somehow. And it will probably cause a slowdown in the generation code.

Once I have that part done then I can move on to creating a mesh manually and thus reducing the amount of vertices. At the moment the FPS difference between this project and my last has greatly improved. I'm determined now to finish this project 100% and then use the code to create a small game...

I'm still going to thank you though Green Gandalf...


Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Aug 2011 22:01
Version 3.0 of the Pseudo Random 3D Level Generator completed.



UV mapping all sorted and working. Floor map generation, duplicated and reversal of faces for the ceiling. And the walls created by extruding the edges of the maps outline.

Attached is the Visual Studio C++ Express 2008 project file, commented and with an exe file attached.

Hold down a mouse button to move around the level and use the cursor keys.

All this source code is open for anyone to use and abuse. I'll also post this in the Code Snippets forum once I have some more generalised functions.

Part of the generation code (not posting it all as it got quite big and it's in the attached file anyway):


I had to strip it down and put everything into separate functions so I could get it working properly.

Many thanks to TGC's forum members.

If anyone finds this useful then give me a shout.

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Aug 2011 13:44
Looks very good.

I may not be able to test the code till later this week but will as soon as I get the chance.

That screenshot looks as if you could turn it into a "Hall of Mirrors" - just apply a reflection shader to each wall with a dynamic cube map and you could cause the player all sorts of problems.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Aug 2011 18:36 Edited at: 3rd Aug 2011 18:47
Mmmm, interesting idea about the mirrors. I'll keep that one in mind. Thanks. (logged that thought in my notes)

I've a few ideas to dress the levels up a bit.

1. Using the array data that stores the edges, both inner and outer edges, I can put decorations along the walls and other things on the floor.

2. Create a whole list of functions that allows this to be used as a level generator in any ones code. It won't take much to expand the code now and I can add code that adapts the decorations too.

3. Turn it into a dll for DBPro. Only when I've got the map decorations working though. How I do that is another story.

So far I've got functions working that retrieve the centre coordinates of any of the inner edges, zero being the centre of the maps inner edge. Handy for item placement and player start and end positions. I'm going to throw in a function that works out the furthermost inner edges so maybe portals can be placed at the edges of the map. Also the edges lengths can be fetched too as they differ through the random generator.

The hardest part has been done, now it's just fancying it up a bit.

EDIT: Wow, reflection shading really sucks on this laptop. I'll try on my other pc...

EDIT2: Only one reflection plane per scene. Ahh, trying another method...

Warning! May contain Nuts!
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 7th Aug 2011 21:23
Hi WLGfx,i had a very similar idea to yours a while ago,didnt realise at the start of this thread that this was were you were heading with it.Good job with the GDK version,ive been trying to use it more myself recently but just end up trying things in DBPro first and never get round to porting them accross.
Anyway your post above reminded me of mine so i dug out the code from my old laptop and grabbed a couple of screen shots.I think im using a completely different method to yours for the map generation,but the effect is very similar.


code needs 3 textures to work

Feel free to rip it it bits and see how it ticks,maths isnt my strong point so i must admit that the line intersection code was snipped from a thread along time ago and i cant remember who wrote it but thanks.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 8th Aug 2011 00:42
Wow paul5147, I'm not the first to have to re-learn tons of stuff. It took me a long time to get it finally working as I wanted, and my intentions changed a few times. I've currently ported everything over to PureGDK (new forum link WIP). Although I got everything working in GDK. So much easier to do research on google working with C++.

My line intersection code was the same used by tons of people, I had to change it to suite my needs and the current C++ version has been inlined too for faster execution. The only thing I've got to get working properly with it at the moment is the UV mapping on the walls, some of my textures sometimes get stretched a bit too far. Floors and ceiling UV is fine. I'll compare your line intersection code with mine too.

Oh yeah, another thing I might be having an issue with is the accuracy of the floating point compared to double precision. The algorithm works 99.9%, some of the levels generated with some figures still have some over-lapping edges.



Warning! May contain Nuts!
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 8th Aug 2011 07:19 Edited at: 8th Aug 2011 07:22
Thanks WLGfx,I found one rather crude method of getting rid of some of the stretched textures on the wall sections,but due to them all being random lengths its not ideal.
I simply check the length of the edge and if its over a certain length then i make it in sections,rather than just 2 polys ill use 4 or 6,not perfect but good enough for now.
I lost a lot of code in a hard drive crash a while ago and i dont think this is using that method but im sure i had it working at some stage.
I dont get any overlapping of edges with the intersection tests im running in this,but i did have to make sure i never generated a triangle that was a straight line or that really messed things up.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 9th Aug 2011 04:29
I've slightly altered my code for the work around with float in-accuracies and so far it seems to be working 100%.

I might check the length of the edge and see if I can wrap the UV's around the entire outline of the main polygon, but that would mean I would have to sort my edges in the polygon outline. It's a main priority once I've got the other things coded and working.

I can't say I've come across a triangle generated being a perfect straight line, but then I only really tested it a random seed value between 0 and 10. I'll keep that in mind, although originally I had to faff about a lot the atan2() function before I understood it. Actually that's true of all the trig I've learned whilst working on this.

So far I'm using my web server for current projects I'm working on as my backup. Plus I have umpteen hard drives at home for backups. I definitely do not want to go down that road again like years ago so I can understand how it feels.

The main aim of what I'm after is every face will share the vertices, ie two triangles will only use 4 vertices instead of 6. Over mega large level objects this does make a huge difference on FPS, especially since I'm doing all my coding with a crappy ATI Radeon 200M Xpress graphics chip in my laptop. Frame rates are very slow...

Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Aug 2011 12:48
Are all your polygons in the same plane? If, for example, they were all at the same Y value, e.g. a level floor, you could just use the world XZ coordinates of each vertex as the UV values and scale them by a fixed appropriate value. The textures would all automatically line up then. Make sure you have texture wrap mode set and that you use a seamless texture.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 9th Aug 2011 20:55
My floor and ceiling objects are on the same plane, I've managed to fix the UV for those but for the walls I am going to have to take a different approach.

1. Sort my outer edge array so that an edge follows the last one in order correctly. Because of the generation algorithm the edge array is mixed up in a random order.
2. The V texture coords will simply go from 0 to 1.0. ie from floor to ceiling.
3. Each U coord will then be based on the edges length. This edge length will carry on right round the polygon until it's back at the beginning. Hopefully giving me the correct UV values and my walls don't look stretched.

I still have to implement that part in building my walls, but the floor and ceilings are perfect.



The create_wall_object() function is my next priority to get working correctly.

Wow, how long have I been working on this now?

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Aug 2011 19:40 Edited at: 10th Aug 2011 19:40
Just in case anyone is interested in knowing how to stop textures from being stretched along multiple plane objects, here's a snippet from my pseudo random 3d level generation alogorithm:



Here's a screenshot of the difference between the two:


Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 12th Aug 2011 05:11 Edited at: 12th Aug 2011 05:15
I'm transferring this over to the WIP forum now because I have now got the decorations started and working too... Here's what it looks like:

and the initial code that does these decorations:


Hopefully soon I will have an game that will generate millions of levels randomly and fully decorated with spiders webs, lights, rocks, etc... I'll need some ideas now...

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Aug 2011 00:39
LINK (CODE SNIPPETS) - http://forum.thegamecreators.com/?m=forum_view&t=188271&b=6&p=0

WLGfx's Pseudo Random 3D Level Generator for Dark Basic Pro.

I thought I'd give something back to The Game Creators community for all the help they gave with my persistent questioning.



Warning! May contain Nuts!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2011 17:14
Thanks. Just tested that on my old laptop - works very cleanly.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2011 17:49 Edited at: 18th Aug 2011 17:49
Just noticed a slight problem. I've just tested two different seed values and noticed that the UV texturing of the wall immediately behind the player when you start is screwed up:



My guess is that when you loop through the edges to adjust the UV coordinates you missed out the first edge. I couldn't see any other glitches.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Aug 2011 20:24 Edited at: 18th Aug 2011 20:31
Yep, I'm currently looking into trying to fix that particular face separately. As I go round the edge of the outline polygon those last vertices seem to get mixed up in the calcs.

Now handles collision setup and placement of some simple level obstacles which are also added to the collision system. (Sparkys)

I have also fixed:

to:

which caused it to get locked up in the generation code. Still keeps it within the last 12% of the edges created which speeds up the algorithm.

Just throwing quickly together an example of using the code with this:



Keys: WASD - Move, Space - Jump, Return - Change level, Mouse - Look

(Still all done with no media)

@Green Gandalf - Without the help from these forums I'd have given up a long time ago.

EDIT: It's wierd seeing a screenshot of it from someone else...

Warning! May contain Nuts!
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 19th Aug 2011 02:56
Looks good, I might have a project to use it some day so thanks!

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Aug 2011 11:21
Quote: "Yep, I'm currently looking into trying to fix that particular face separately."


Are you trying to continuously map the UV coordinates as you work around the outline? If so you'll obviously have a problem when you meet the other end of the outline. I suggest you either have an awkward seam at the join or use some sort of "best fit" so that one wall section is as good as it can be, i.e. slightly stretched or shrunk, but still continuously UV mapped to the next section. There are obviously more complicated ways of achieving the same result. One discontinuous seam might not be too noticeable though and is obviously simplest unless you are welding the vertices (which I assume you are not). If you're not continuously UV mapping from one section to the next there shouldn't be a problem of course.

I haven't looked at your code in detail yet so sorry if the answers to these comments are obvious from the code.

Quote: "Without the help from these forums I'd have given up a long time ago."


So would I . There's nearly always someone on hand who can answer my questions.

Login to post a reply

Server time is: 2026-07-10 10:22:50
Your offset time is: 2026-07-10 10:22:50