Author Topic: Faces  (Read 53132 times)

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #100 on: June 24, 2011, 04:22:15 AM »
Strange... Got no idea why, the code seems legit :o

Unless: What is
PV2x = Px3 - Px1
PV2y = Py3 - Py1
PV2z = Pz3 - Pz1
?

Are they required there or?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #101 on: June 24, 2011, 04:23:53 AM »
Those are required.  They are converting 2 points into a vector.

I've worked out what the problem is caused by.  My code to select 3 vertices is erroneously assigning the same vertex ID to the 2nd and 3rd vertices.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #102 on: June 24, 2011, 04:31:06 AM »
Fixed!




Now vertices disappear when they go behind a face.  :>


This marks a huge milestone.  My face is pleased.  =)  Thanks to everyone who has helped or commented so far!

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #103 on: June 24, 2011, 05:26:48 AM »
Well, now to make the lines disappear properly?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #104 on: June 24, 2011, 05:37:01 AM »
Doing some tidying up of the existing code for now, tidying up the comments and linespacing and removing all the debugging commands and incorrect formulas.

Then, yes... it's time to make the edges disappear.  That will require pseudo-vertices, and arrays to store the enabled/disabled state of the vertices and pseudo-vertices.  Then the drawing rule is simply Draw, Don't Draw, according to my concept diagrams from way back on page 3..
I hope my conceptual model works..

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #105 on: June 24, 2011, 05:57:59 AM »
Sounds like alot of planning and works, what I wonder is how do you spot is two lines cross?

I've actually wondered about that since I was 8, one of my earliest philosophic questions xD

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #106 on: June 24, 2011, 06:00:51 AM »
The lines both have equations.  At the point where the lines meet, their equations will be equal.  Using this fact, you can figure out where the lines meet, or "intersect".

Oh, also, check this out:





The bottom-left-front vertex on the further away cube is hidden, so all the lines that connect to it are hidden too.  That's why it looks wrong.  Pseudo-vertices are what will fix this.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #107 on: June 24, 2011, 06:09:24 AM »
The last thing you said, I kinda knew already :P

But the equation for finding it, a human mind can figure out that lines cross by them self, but a computer struggles, and the code is what I wonder of...

If you remember I talked about WC3, well: I've been playiing that since I was around 7 and began making maps immediatly, I was doing so for a good time, til around theese days. So I've been wondering about alot of stuff, but never solved them :/

And I was coding in Eufloria along time before I released my first map, that's maybe why it seemed so advanced...

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #108 on: June 24, 2011, 06:15:09 AM »
And annikk, I'm guessing you're using Numpad++?

If so, how do you stop hotkeys?

I've been troubled along time since I started coding the Adventure map :/

Since the code is so d**n long, I have to close some(or alot) of the functions, so I can have is cleaner...

But since I use Caps Lock to make uppercased letters, I sometimes also open up some of the functions that are locked and begin to write a little until I see what I've done, then get annoyed, copy it to where it is supposed to be and then close it and then code more, open a new one by accident, etc...

Any idea? I've looked for this hotkey, but it's impossible to find among all the thousand others -.-'

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #109 on: June 24, 2011, 06:21:33 AM »
Not had that problem before, sorry..


Attached is a demo of the very basic edge-hiding functionality that I've got in place now there is an array to represent vertex visibility.  Pseudo-vertices next..

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #110 on: June 24, 2011, 06:28:15 AM »
Owww, d**n...

You don't even want to look at that code, it's a monster from somewhere deeper than hell >.<

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #111 on: June 24, 2011, 06:30:24 AM »
::evil laugh::

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #112 on: June 24, 2011, 06:32:33 AM »
Damn Cool, the current vertex remover works fine for self intersecting though, maybe you can get some performance boost from that?

And my code is 2.3k lines long, and I'm facing a problem that I am now supposed to fix...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #113 on: June 24, 2011, 06:37:07 AM »
Hmm, perhaps I can use that eventually, yus..
Efficiency stuff will mainly come after the base parts of the engine are in..

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #114 on: June 24, 2011, 06:41:05 AM »
I wish I was thinking like that, I'm always thinking performance >.<

I hope I fixed that thing now... It's about the rallying in the new CC :o

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #115 on: June 24, 2011, 06:38:15 PM »
So now I am wondering how to go about creating the pseudovertex arrays/matrices.
They need to be dynamically scalable so it can accept any number of pseudovertices per edge.
A pseudo-vertex is a property of a particular edge.  For each edge we draw, the number of pseudo-vertices, their active/inactive state, and the coordinates of their vertices must all be accessible.
« Last Edit: June 24, 2011, 06:46:27 PM by annikk.exe »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #116 on: June 24, 2011, 06:51:27 PM »
A little visualization for EXACTLY what you meant there??

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #117 on: June 24, 2011, 10:21:17 PM »
Supposing I have an edge containing 2 active vertices and 4 active pseudo-vertices like this:

Code: [Select]
V     P     P     P     P     V


When we draw between them, we start from the "From" vertex, and draw to the "To" vertex.  We use the rule: Draw, Don't Draw.

So draw..
Code: [Select]
V-----P     P     P     P     V
don't draw..
Code: [Select]
V-----P     P     P     P     V
Draw...
Code: [Select]
V-----P     P-----P     P     V
don't draw...
Code: [Select]
V-----P     P-----P     P     V
Draw...
Code: [Select]
V-----P     P-----P     P-----V


Hope that explains it.  :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #118 on: June 24, 2011, 10:26:39 PM »
I've drawn on 2 pseudo-vertices where they would naturally be on this image from earlier:




The orange circles are the pseudo-vertices.


Pseudo-vertices are created at any point where an edge goes behind a face or emerges from one.
They are there to mark the coordinates where we must stop drawing the edge.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #119 on: June 24, 2011, 10:31:08 PM »
Hmm...

That explains it :P

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #120 on: July 01, 2011, 06:37:34 PM »
So, what sort of data structure is require for pseudo-vertices?

Pseudo-vertices are properties of an edge.  When an edge is drawn, the number and coordinates of pseudo-vertices along its length must be known.
There are two ways I could store the coordinates.  I could either specify the X and Y coordinates individually in two seperate matrices (first box is the edge ID, second box is the ID of the pseudo-vertex, value is the coordinate).  Or, I could store a single value between 0 and 1 which represents the proportion of the length along the edge where the pseudo-vertex lies.

The latter approach results in one less matrix, but involves a lot more calculations as the proportion would need to be calculated once initially to establish the proportion, then again when it is rendering time to bounce out some actual coordinates.  I think an additional data structure is probably preferable here.

Now, when we're storing coordinates...what do we store?  Should it be 2D or 3D coordinates?
2D would be a cheaper calculation... but we want to calculate depth anyway to tell whether the pseudo-vertex should be disabled or not.  2D doesn't let us do that.... but still, I think 2D is the best approach.  We can follow it up with a line intersecting plane calculation to determine whether a face or a pseudo-vertex is closer, that allows us to calculate the enabled/disabled state.

So, that means we'd have the following:

Code: [Select]
pseudovertex2dX[edgeID][pseudovertexID] = X-coordinate
pseudovertex2dY[edgeID][pseudovertexID] = Y-coordinate

pseudovertexenabled[edgeID][pseudovertexID] = boolean
vertexenabled[vertexID] = boolean


A key property of this data structure is that it has to expand or contract in size dynamically from frame to frame.  In frame 200, there may be no overlapping edges at all, and thus no pseudo-vertices.  In frame 250, maybe there are a bunch of overlapping edges and edge ID's 3 and 4 have 4 pseudo-vertices each.  The engine must be able to handle this automatically.

How to do that?


Code: [Select]
for edgeID = 0,numberofedges do
-- check if any edges are overlapping any other edges
-- if found to overlap another edge, check that this edge is further away at the 2D point of overlap
-- assuming it IS further away, create a pseudo-vertex at the point where the overlap takes place
-- if it's not further away, don't create the pseudo-vertex for this edge (it will be created for the other edge instead when it is checked)

-- check if any edges are intersecting with a plane
-- if intersecting a plane, create a pseudo-vertex at the point of overlap
end

for pseudovertexID = 0,numberofpseudovertices do
-- check if this pseudo-vertex is inside a face
-- if not inside a face, set state to enabled.
-- if it IS inside a face, check if this pseudo-vertex is behind the face.  if behind, set state to disabled
-- if in front, set state to enabled
end



for i = 0,numberofedges do
if i == 0 then
-- DrawFrom = EdgeFrom
end

for j = 0,NumberOfPseudoVerticesInThisEdge do
if

Hmm, that last part is going to be tricky.  Not quite sure how to represent that in pseudo-code right now..

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #121 on: July 02, 2011, 09:13:07 AM »
Why bother storing disabled pseudo-vertices?  Why not just do the depth check whenever a potential pseudo-vertex is detected inside a face, and if it turns out it would be disabled anyway, just don't create it..

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #122 on: July 04, 2011, 06:18:21 PM »
Lets have another try...


Code: [Select]
for edgeID = 0,numberofedges do
-- check if any edges are overlapping any other edges
-- if found to overlap another edge, check that this edge is further away at the 2D point of overlap
-- assuming it IS further away, check that the point of intersection is not behind any other face
-- if it is not behind any other face, create a pseudo-vertex at the point where the overlap takes place
-- if it's not further away, don't create the pseudo-vertex for this edge (it will be created for the other edge instead when it is checked)

-- check if any edges are intersecting with a plane
-- if intersecting a plane, check if the point of intersection is behind any other faces
-- if the point of intersection is NOT behind any other face, create a pseudo-vertex at the point of overlap
end

finisheddrawing = true

for i = 0,numberofedges do
if i == 0 then
-- DrawFromX = EdgeFrom X
-- DrawFromY = EdgeFrom Y
end

if pseudovertex2dX[i][0] ~= nil then
DrawToX = pseudovertex2dX[i][0]
DrawToY = pseudovertex2dY[i][0]
-- Draw line from DrawFrom to DrawTo
finisheddrawing = false
else
DrawToX = EdgeTo X
DrawToY = EdgeTo Y
-- Draw line from DrawFrom to DrawTo
end

if finisheddrawing == false then
for j = 1, numberofpseudovertices do
if math.ceiling(j) ~= math.floor(j) then
DrawFromX = pseudovertex2dX[i][j]
DrawFromY = pseudovertex2dY[i][j]
if pseudovertex2dX[i][j] ~= nil then
DrawToX = pseudovertex2dX[i][j + 1]
DrawToY = pseudovertex2dX[i][j + 1]
else
DrawToX = EdgeToX
DrawToY = EdgeToY
end
end
end
end
end


That should do it!

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Faces
« Reply #123 on: August 01, 2011, 08:15:56 PM »
I started thinking about this again today and realised there is another problem with the pseudovertices implementation.

The problem is that when I generate the pseudovertices, I am checking edges according to their ID numbers.  So for example I pick Edge ID 0 first, and check it against Edge 1, then Edge 2, then Edge 3, and so on.

If pseudovertices are created as a result of this, they may not necessary appear in the correct order.  So as well as creating a list of pseudovertices, I will have to find a way to pick from them selectively according to whichever one is next closest as you proceed along the Checked Edge.

A method to do this is to check all the pseudovertices that belong to the edge each time the next pseudovertex is being selected, and choose the one that is next biggest according to its X value (or Y value if it's a perfectly vertical edge).  The next pseudovertex would be selected by looking for the nearest value of X that is still greater than the current value of X.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 30
  • Posts: 1,527
  • Eufloria: Yes
Re: Faces
« Reply #124 on: August 01, 2011, 08:45:55 PM »
Create a matrix as the pseudo and an array to count the amount of pheudo per edge!

Then run them when running the edges :)

Hope you know what I mean, unless thats not working :/