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 / I need with me polygon removal code

Author
Message
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 5th Oct 2012 03:11
Hi guys,

My poly removal code works. It shows the right places where the poly should be hidden. You should see a half sphere when you run it.

However, if I write vertices-1 or vertices-3 in the memblock it messes up.

Here is the code:



Also I made my own poly counter. Mine poly counter doesn't even pick up the sphere from when I rebuilt it. However, if you press spacekey it will create a new cube and it shows my poly counter works.

You think you can help me fix this guys thanks

darkvee
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Oct 2012 20:11
Quote: "My poly removal code works."


Quote: "However, if I write vertices-1 or vertices-3 in the memblock it messes up. "


What do you mean? If your code works why do you need to "fix" it?
darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 6th Oct 2012 03:34
Hi Green Gandalf

See after I shift the data on the memblock I need to down size the vertexCount by doing write vertices-1 or vertices-3. If I don't the memblock still has the vertex data in there by the same vertexCount.

You understand what I mean?
After I shift the data I need to do this

write memblock dword freeMem,8,numberOfVertices-3

So the memblock keeps up with the right vertex count when I make a object out of a mesh from the memblock.

Do you understand now? If you do can you help me fix this problem?

darkvee
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2012 17:29 Edited at: 6th Oct 2012 19:58
I think you need to think carefully what you are doing. For example, as far as I can see, your code seems to do exactly the same thing if I change this



to simply this:

[edited silly typo ]

Also, why do you use "freeMem" in some places and "1" in others when referring to memblocks? I think you need TWO memblocks: the original one and the new smaller one.

I don't think your code is removing polys at all - if I've understood it correctly it is simply overwriting certain existing vertex data with new values.

You should also ask yourself what are the values of things like myArray(c+1) in lines like this:



I suspect your code is just a complicated way of filling the first half of the vertex data with zeroes.

Edit Anyway, here's a simpler version of your function. This demo removes some polys randomly.

darkvee
20
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 8th Oct 2012 02:30
Wow! Green Gandalf thank's

I find it interesting you didn't have to use a for loop to loop through the stuff.

this code:
myArray(c).X = myArray(c+1).X
myArray(c).Y = myArray(c+1).Y
myArray(c).Z = myArray(c+1).Z

shifts the vertex position x,y,z to the end of the memblock
For example I have an array(max) = 1,2,3,4,5

for i = 3 to 5
array(i) = array(i+1)
next i

Now my array(max) is 1,2,4,5,3

That's why I had all that shifting to make sure it shift the right stuff.

but anyways thanks so much Green Gandalf

darkvee
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Oct 2012 18:40
Quote: "this code:
myArray(c).X = myArray(c+1).X
myArray(c).Y = myArray(c+1).Y
myArray(c).Z = myArray(c+1).Z

shifts the vertex position x,y,z to the end of the memblock
For example I have an array(max) = 1,2,3,4,5

for i = 3 to 5
array(i) = array(i+1)
next i

Now my array(max) is 1,2,4,5,3"


Er, no. Look at your original code again. Better still work through it line by line with a simple example of 4 polys so you would delete the first two.

First you assign the values to position "c" in your array, then you immediately overwrite them with the contents of position "c+1" but since that value hasn't been assigned yet (since the loop counter is still "c") it presumably contains either 0 or something fairly random depending on how DBPro initialises arrays in functions. So your array still contains zeroes and that's what get written to the memblock.

You could do it using arrays but you need to get the details right.

Quote: "That's why I had all that shifting to make sure it shift the right stuff."


I know that's what you tried to do but your code does something else.

Quote: "but anyways thanks so much Green Gandalf"


You're welcome.

Login to post a reply

Server time is: 2026-07-07 15:09:31
Your offset time is: 2026-07-07 15:09:31