Skip to content

Instantly share code, notes, and snippets.

@ajweeks
Last active January 31, 2016 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajweeks/75e644952490af6d0454 to your computer and use it in GitHub Desktop.
Save ajweeks/75e644952490af6d0454 to your computer and use it in GitHub Desktop.
Second of Devember

Devember Day 02

Today, being a Wednesday, I have no problem whatsoever with both remembering and setting aside time to write code, since I have a programming class for 3 hours. I will some snippets of the code I wrote today along with this post, and some screenshots. However, I'm using my school's private game engine, and I can not post that code online.

So far we've only covered quite simple topics in class, this week we are learning about vectors. (C++ std::vectors to be specific). I did learn one interesting technique for calculating a equilateral triangle's third point, given the first two. Most of the rest of the code I wrote was very rudimentary vector manipulations, so I won't include it. (Min, max, number of occurrences, copying, reversing, etc.)

:::C++
void VectorLab1::FillEquilateralTriangle(const DOUBLE2 &p1Ref, const DOUBLE2 &p2Ref)
{
	std::vector<DOUBLE2> points;

	points.push_back(p1Ref);
	points.push_back(p2Ref);
	DOUBLE2 diff = (p2Ref - p1Ref);

    DOUBLE2 p3 = DOUBLE2(
		diff.x * cos(-M_PI / 3) - diff.y * sin(-M_PI / 3),
		diff.x * sin(-M_PI / 3) + diff.y * cos(-M_PI / 3));
    p3 += p1Ref;

    points.push_back(p3);

	GAME_ENGINE->FillPolygon(points, 3);
}

See you tomorrow!

Previous Entry | All Entries | Next Entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment