Advanced Lesson 10 (study group)

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Advanced Lesson 10 (study group)

Post by LuX » September 7th, 2014, 11:57 am

Interesting, so if I understood correctly, you first check if the previous and next corner are intersected by other lines, and then check that the line is inside the object? Something like that anyway.

Seems a like it's more sophisticated then my code anyway: [ snip ]

Code: Select all

// Begin looking for first corner which's previous can see its next corner
				{
					for ( int n = 0; n < object.size( ); n ++ )
					{
						Point TPm_b, TPp_a;		// Points of previous, current, next
						int	  nm, np;			// Indexes of n_minus: previous, and n_plus: next

						// Set previous and next transformed point
						{
							nm = ( ( n == 0 ) ? ( object.size( ) - 1 ) : ( n - 1 ) );
							np = ( ( n == object.size( ) - 1 ) ? ( 0 ) : ( n + 1 ) );

							TPm_b = object[ nm ].t_point_b;

							TPp_a = object[ np ].t_point_a;
						}

						bool collide = false;
						
						// Check if line from previous t_point to next t_point is cut off by wall ( c_points )
						{
							for ( int w = 0; w < object.size( ); w ++ )
							{
								int w2 = ( ( w == object.size( ) - 1 ) ? ( 0 ) : ( w + 1 ) );		// Set index of next wall

								if ( LineIntersectBool( object[ w ].c_point, object[ w2 ].c_point, TPm_b, TPp_a, Point( ) ) )
								{
									collide = true;	// Collides; break
									break;
								}
							}
						}

						if ( !collide )		// If doesn't collide: good for triangle. Start over.
						{
							out.push_back( LTri( object[ np ].areaIndex, object[ n ].areaIndex, object[ nm ].areaIndex ) );
							object.erase( object.begin( ) + n );
							goto BEGIN_SCAN;
						}

						if ( n == object.size( ) - 1 )	// If no cornerpoints match, no roof; return
						{
							return;
						}

					}
				}
ʕ •ᴥ•ʔ

1rg3ndw3r
Posts: 9
Joined: February 23rd, 2013, 2:11 pm
Location: Germany
Contact:

Re: Advanced Lesson 10 (study group)

Post by 1rg3ndw3r » September 7th, 2014, 12:22 pm

:oops:
I forgot to say that you need to run the CodeConverter.exe from cmd like this:

Code: Select all

cd 'folder from the CodeConverter.exe file'
CodeConverter.exe quell ziel

1rg3ndw3r
Posts: 9
Joined: February 23rd, 2013, 2:11 pm
Location: Germany
Contact:

Re: Advanced Lesson 10 (study group)

Post by 1rg3ndw3r » September 7th, 2014, 1:04 pm

I think you understood correctly LuX.
Its hard to explain how my program works.
Generally it does the following things:

Code: Select all

 -loop through all points of the polygon
 .  -check if the line between the next and the previous point is inside of the polygon
 .  .  -true:
 .  .  .  -add the point to a new triangle list
 .  .  .  -loop from this point through the points of the polygon into both directions
 .  .  .  .  -check if the line between the new two points is inside of the polygon
 .  .  .  .  .  -true:
 .  .  .  .  .  .  -add the points to the triangle list 
 .  .  .  .  .  -false:
 .  .  .  .  .  .  -end the triangle list
 .  .  -false:
 .  .  .  -skip this point
 -look for the greatest triangle list and save it
 -cut the the points inside the triangle list off from the polygon
 -do the same thing until there are no more points in the polygon

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Advanced Lesson 10 (study group)

Post by LuX » September 8th, 2014, 10:27 am

Alright. What I was more interested in was how you check if the line is inside/outside the object. Well, I guess I can just study the code or look it up online, but that's the only difference I see between our codes really. What I left out from my snip code was the overly complex way of setting test points for the corners towards the inside of the object, so that if the test line runs outside the object it will have to move through it's own line and will be detected, as opposed to if I used the corner point itself it wouldn't, because then it would be already on top of it's own line. If that makes any sense.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Advanced Lesson 10 (study group)

Post by chili » September 8th, 2014, 11:51 am

Looks like a good algorithm irgendwer, sounds a little more complicated that what I did, but might yield fewer strips/polygon on average too (I just did simple ear trimming).

Would you mind testing something out for me?
Chili

1rg3ndw3r
Posts: 9
Joined: February 23rd, 2013, 2:11 pm
Location: Germany
Contact:

Re: Advanced Lesson 10 (study group)

Post by 1rg3ndw3r » September 8th, 2014, 4:05 pm

First the program checks if the line is a border line of the Polygon.
(like if there ar only 3 points in the Polygon)
My program uses this Algorithm to check if a single point is inside of a polygon.
This will be done for every point on the line. There is probably a better way of proving it, but I was lazy.

What shall I test for you Chili?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Advanced Lesson 10 (study group)

Post by chili » September 9th, 2014, 2:10 pm

I see that you have 2D triangle texturing functions in your framework there. I'd like to see a demo of it in action. If you could upload a zipped .exe + texture image in a folder that'd be sweet.
Chili

1rg3ndw3r
Posts: 9
Joined: February 23rd, 2013, 2:11 pm
Location: Germany
Contact:

Re: Advanced Lesson 10 (study group)

Post by 1rg3ndw3r » September 9th, 2014, 5:15 pm

Here is a texture demo program.
There was actually a little error in the framework (Model2D.cpp line 229 'low' instead of 'hight') but I fixed it. :oops:
Attachments
TexturDemoBuild.zip
(5.44 MiB) Downloaded 285 times

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Advanced Lesson 10 (study group)

Post by chili » September 15th, 2014, 12:33 pm

That looks pretty good man. Hard to tell for sure because the texture is doesn't have a lot of straight lines, but doesn't seem to be any distortion or crawling. Thanks for posting.

Check this dumb shit out. Arrow keys to rotate. I have to figure out exactly why it doesn't work, but I keep finding other things I'd rather be doing.
Attachments
Dumb.zip
(59.66 KiB) Downloaded 172 times
Chili

1rg3ndw3r
Posts: 9
Joined: February 23rd, 2013, 2:11 pm
Location: Germany
Contact:

Re: Advanced Lesson 10 (study group)

Post by 1rg3ndw3r » September 15th, 2014, 6:10 pm

Hmm.
I had the same problem at first. Mayby you have a few wrong + or -1 in your code?
I solved the problem by deleting all + or -1 in my texture drawing code. ;)

Post Reply