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 / switching trees for lower poly and then plain, whats the best way of acheving this?

Author
Message
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 27th Jan 2011 05:02
hi all, I have a bit of a dilemma, what is the best way in which to change from heigh poly trees to low poly trees to plain trees, I was thinking of using sqrt, but know that this can be a bit on the slow side, dose any on know haw I could achieve the same thing with a different technique?

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
Mattman
23
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 27th Jan 2011 05:50
I think using a distance formula (which would utilize the sqrt function) is a good starting point. If it turns out that that method is too slow, then you can look for an alternative. But I think checking for distance is an entirely appropriate first solution.

I am currently working on a game set in a city. It checks to see how far away the buildings are and hides/shows them based on their distance to the camera. In tests with lots of buildings to test for, everything is running smoothly

Why make sense when you could make brownies?
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 27th Jan 2011 06:29 Edited at: 27th Jan 2011 06:56
@ Mattman did you use the sqrt in your city's code?

what would every one else use, I know there is an example that came with the snippet file that you could buy 3 odd years ago, but for the life of me I can't find it, that talk you though the hole thing.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jan 2011 11:49
There's no need to take square roots. If d1 and d2 are the two distances where the changes occur then compare the objects' squared distances with the squares of d1 and d2. Might save a bit of processing if large numbers of objects are involved.
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 27th Jan 2011 12:25 Edited at: 27th Jan 2011 12:26
!

I had this problem in older versions of WOR - I decided instead of checking a set sphere around the camera, I'd just check a square. It's much easier to calculate and far faster to check all the objects at once.

I just check for trees within a set X-axis, Z-axis boundary around the camera.



Obviously this won't create an exact spherical loding region, but for something as imprecise as swapping models in and out at far away range, it works great and it's really fast.

LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 27th Jan 2011 12:50
I use vector3 to check distances. This is how I do it:
1. Place this
somewhere near the beginning of your code.
2. This
is a typical function that I would use.
3. The function is called like this:


When I have a game with a large number of objects to check, I generally will place them in a defined quadrant when they are created. I only check the objects in the quadrant that the player is in. It has worked fine for me. Hope this is helpful.

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 27th Jan 2011 14:51 Edited at: 27th Jan 2011 16:44
Like LBFN says, you could split your world into sections and place your objects into them. However I would only perform a distance check to each of the sections, then use that to control the LOD of the objects within it. Depending on how many objects that you want to create, you might also want to think about recycling your objects once they get too far away from the camera.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Jan 2011 15:43
Hi you all.

Here there is a good tuto made by Pasky...you will need to tanslate to english, but you will be able to understan it for sure.


http://www.telefonica.net/web2/paskyprog/



cheers



I'm not a grumpy grandpa
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 27th Jan 2011 18:18
I'd use Kaedroho's LOD plugin, which does all this for you automatically.

My signature is NOT a moderator plaything! Stop changing it!
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 27th Jan 2011 19:15
Yeah if you want proper LOD, use a plugin. - I tried the DBP LOD commands and it just refused to work. xD (Made a whole thread on it and still couldn't get it working )

sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 28th Jan 2011 00:04
thanks all, I'll look in to this a bit more if any one else can think of any other examples then please post then.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 28th Jan 2011 14:29 Edited at: 28th Jan 2011 14:43
@ LBFN can you use the code you posted to check against the camera and an object?

Edit

I hate to sound like a noob but what is LOD?

Edit

scratch that, is it Look or Load,object,Distance?

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Jan 2011 15:05
LOD = Level of detail.

It refers to the technique of using lower poly versions of objects when the objects are further away from the camera, i.e. lower levels of detail would be used.

To take an extreme example, there's no point in the cpu/gfx card processing 1000 vertices for an object that's so far away that it occupies only 1 screen pixel.

It's much the same principle that's behind the use of mipmaps.
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 28th Jan 2011 16:28
I'll add that one to me old brain, thanks Green Gandalf.

I've started work on this now, so will let you all know how I get on with this.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 28th Jan 2011 17:02
when I make a vector like this


would it be better to make it like this



or would this affect my code latter on?

because I'm adding more then one type of tree and am going to use arrays to handle them all.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Jan 2011 17:17
Did you mean to write something like



?

That should be fine although a lot depends on the rest of your code.
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 28th Jan 2011 17:25 Edited at: 28th Jan 2011 17:32
yeah I did. lol

first off I added this


inside the loop


this is the function


Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 28th Jan 2011 17:34 Edited at: 28th Jan 2011 18:03
problems!

error object dose not exist, this is the line that's flagged in the error


check out my code on the post above

any takers?

thanks in advance

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 28th Jan 2011 18:09 Edited at: 28th Jan 2011 18:12
You need to assign object numbers to the TreeArray(#).TreeObj, like this:




The function itself would be like this:



and the call like this:



Since you are checking 59 trees, it doesn't make sense to print out all of them. You could easily check to see which ones are the closest or farthest away. You could store the resulting distances and object numbers in an array if they met certain criteria.

You don't have to do it like this, it's just how I would do it.

LB

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 28th Jan 2011 18:31
I'm pretty sure it's faster to just do a comparison of squared lengths, without using vectors at all:

sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 28th Jan 2011 22:04
I gave up on the vectors, went back to what I know
lol

I did get the vectors to work, but only on one tree, so not much use there.

@ LBFN sorry I did what you posted, but just could not get it to work, if I did this


I got an error message saying array out of bounds, everything else I used worked, and if I removed the for-loop it worked also, but like I said with one tree only.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 29th Jan 2011 00:39 Edited at: 29th Jan 2011 15:11
Okay, here is some example code for you. This creates 59 'trees' (boxes) and places them randomly. Use the arrow keys to move around. The tree closest to the camera will turn red. The one farthest away will turn green.



Hope this helps,

LB

sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 29th Jan 2011 21:29
@ LBFN

this only seems to work on two object at one time, the closest and the farthest away, its very limiting, as a sqrt would give me, say we used dist#, would say if dist# > 500 would turn all trees that are 500 and farther away green, and all the trees that are under 500 would turn red, witch is what I want, as I don't want a single tree to disappear I would like all trees above the dist# rang of 500 to vanish.

I don't know if your code could do that, but I spent a hole day messing around with it, and gave up, and did the same thing in 20 minuets with a sqrt, if this works on mass with an array then I'll use it, if not I'm going back to a sqrt.

thanks for the help so far.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 29th Jan 2011 22:08
Quote: "this only seems to work on two object at one time, the closest and the farthest away, its very limiting"


You must have missed the
Quote: "Okay, here is some example code for you."
(emphasis mine) and this
Quote: "The tree closest to the camera will turn red. The one farthest away will turn green."
part. It's doing exactly as I intended. It was simply an example to show you how to check the camera distance from the trees and to react to that data. My hope was that you would take it and apply the specific criteria you wanted to manipulate the trees based upon the distance calculations.

To alter the code to have trees greater than 500 screen units away to be colored green and closer than that colored red, you can easily do so like this:


sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 30th Jan 2011 03:17
I hadn't had much time to play with it much, as I was working on something else, but had fund this out for myself, I do apologise, I lost internet connection so I didn't get time to edit my post and retract what I said.

I have a question, dose this save on fps and hardware acceleration/usage, and what is the speed like over other methods, as that is what I had hoped for?

thanks again for the help, I will post an image as soon as I can with this in place, so you can see the out come.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 30th Jan 2011 05:17 Edited at: 30th Jan 2011 06:12
here's a screen shot for your help


by the way the worked really well, so will use for all of my objects, thanks again.

Soul sucking devils, twisting the body's of the damned, slivering slim drips from every poor, sin licking at ears, and a smell so bad it stings the eyes, welcome to the darkness.
LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Jan 2011 05:59 Edited at: 30th Jan 2011 06:04
There have been some discussions in the past as to which method is fastest, whether using squared lengths versus vector3. I've always stuck with vector3 as it gives me good results, but it's really a personal preference. Mobiius mentioned Kaedroho's LOD plugin. I have heard some good things about it, I just never got it myself; you might want to check it out to see which suits you best.


Looking good. Good luck to you.

LB

sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 30th Jan 2011 06:09 Edited at: 30th Jan 2011 09:46
@ LBFN can you see the image now? I swear TGC doesn't like me posting images.

I will add them as a downloads from now on, and just copy form the view screen, and see if they stay for longer, lol, thanks for the help LBFN, and every one else, can't wait to get this project off the ground, will make a wip nearer to the time, of completion.

by the way what dose your name LBFN mean?

LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th Jan 2011 07:04
Yeah, the image shows up fine now and it looks good to me. I tried to post it myself, but had trouble too. I usually upload it to the forum, click on the VIEW button to get the address of it and then edit my post with the image. It seems to work pretty well that way.

You are welcome I'm glad to see you moving forward.

Quote: "by the way what dose your name LBFN mean?"

If I told you it was an acronym for Large Brain, Forgets Nothing, it would be incorrect, but it sounds good though.

sindore
22
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 30th Jan 2011 12:02
well that's good to know, I cant wait to see how this is going to work on a bigger scale

code darker and deeper, when the dream becomes reality

Login to post a reply

Server time is: 2026-07-16 12:20:12
Your offset time is: 2026-07-16 12:20:12