コード例 #1
0
ファイル: KochSegment.cpp プロジェクト: avshab/KochSnowflakes
KochSegment::KochSegment( const BasePoint& p1_, const BasePoint& p2_, int iter_order_ )
	: BaseSegment(p1_,p2_)
{
    BaseSegment sn( p1_, p2_ );
    seg.p1 = p1_;
    seg.p1.SetZ( 0.0 );
    seg.p5 = p2_; 
    seg.p5.SetZ( 0.0 );
    double k = 1.0 / 3.0;
    seg.p2 = GetMiddlePoint( seg.p1, seg.p5, k );
    seg.p4 = GetMiddlePoint( seg.p5, seg.p1, k );
    opposite_point = GetThirdPoint( &sn, eGrowthDirection::INSIDE );
    iter_order = ++iter_order_;
    was_iterating = false;
}
コード例 #2
0
ファイル: KochSegment.cpp プロジェクト: avshab/KochSnowflakes
KochSegment::KochSegment( const BaseSegment& s, int iter_order_ )
    : BaseSegment( s )
{
    SegmentBasePoints bp = GetBasePoints();
    BaseSegment sn = s;
    seg.p1 = bp.p1;
    seg.p1.SetZ( 0.0 );
    seg.p5 = bp.p2;
    seg.p5.SetZ( 0.0 );
    double k = 1.0 / 3.0;
    seg.p2 = GetMiddlePoint( seg.p1, seg.p5, k );
    seg.p4 = GetMiddlePoint( seg.p5, seg.p1, k );
    opposite_point = GetThirdPoint( &sn, eGrowthDirection::INSIDE );
    iter_order = ++iter_order_;
    was_iterating = false;
}
コード例 #3
0
ファイル: Camera.cpp プロジェクト: kemthichem/rockman-game
void CCamera::Update(D3DXVECTOR2 _pos, D3DXVECTOR2 _velloc)
{
	if (_velloc == D3DXVECTOR2(0,0) || g_IsMoving) 
		return;
	if (curIndex == m_countPoint-1) {
		m_pos.x = m_arrayPoint[curIndex].x - WIDTH_SCREEN/2;

		if (CPLayingGameState::g_Stage==3) //cheat 
			{
				m_pos.x += 10;
				m_pos.y =  m_arrayPoint[curIndex].y + HEIGHT_SCREEN/2;
			}
		goto updateViewport;
		return;
	}
	{
		POINT rPos = {_pos.x , _pos. y};
		//X
		if (_velloc.x != 0) {
			POINT pCur = m_arrayPoint[curIndex];

			bool isHaveNextX = (curIndex < m_countPoint -1) & (pCur.y == m_arrayPoint[curIndex+1].y);
			bool isHavePreX = (curIndex > 0) & (pCur.y == m_arrayPoint[curIndex-1].y);
			bool isNextMiddleX = false;
			GetMiddlePoint(curIndex + 1, &isNextMiddleX, NULL);
			bool isCurMiddleX = false;
			GetMiddlePoint(curIndex, &isCurMiddleX, NULL);

			if (isNextMiddleX || (isHaveNextX && curIndex==m_countPoint-2)) { 
				m_indexMoveTo = curIndex + 1; m_DirectMove = DIRECT_X;
			}

			if (_velloc.x > 0 && isHaveNextX) {
				int boundX = isNextMiddleX ? m_arrayPoint[curIndex + 1].x - WIDTH_SCREEN / 2 : m_arrayPoint[curIndex + 1].x;
				int temp = isCurMiddleX ? pCur.x + WIDTH_SCREEN/2 : pCur.x;

				if (rPos.x > temp && rPos.x < boundX) {
					m_pos.x = (float)_pos.x - WIDTH_SCREEN/2;
				}

				if (rPos.x > m_arrayPoint[curIndex + 1].x) {
					curIndex = curIndex + 1;
				}
			} else {
				if (_velloc.x < 0) {
					if ((isHavePreX && curIndex != m_countPoint-1) || isCurMiddleX) {
						if (rPos.x < pCur.x) {
							curIndex = curIndex -1;
						}
						if (isCurMiddleX) {
							if (rPos.x > pCur.x + WIDTH_SCREEN/2) {
								m_pos.x = (float)_pos.x - WIDTH_SCREEN/2;
							}
						}

					} else {
						int boundX = isNextMiddleX ? m_arrayPoint[curIndex + 1].x - WIDTH_SCREEN / 2 : m_arrayPoint[curIndex + 1].x;
						if (rPos.x > pCur.x && rPos.x < boundX && curIndex != m_countPoint-1) {
							//update
							m_pos.x = (float)_pos.x - WIDTH_SCREEN/2;
						}
					}
				}
			}
		}


		//Y
		if (_velloc.y != 0) {
			int nextIndexY = GetNextIndexY(rPos, _velloc.y);

			if (nextIndexY != -1) {
				if (_velloc.y > 0 && m_arrayPoint[nextIndexY].y - m_arrayPoint[curIndex].y < HEIGHT_SCREEN && !m_curIsBoundY) {
					curIndex = nextIndexY;
					nextIndexY = GetNextIndexY(rPos, _velloc.y);
				}

				char dirY = _velloc.y > 0 ? 1 : -1;
				long offsetY =  m_curIsBoundY ? HEIGHT_SCREEN / 2 + OFFSET_MAP_Y : 0;
				long temp = _velloc.y > 0 ? m_arrayPoint[curIndex].y + HEIGHT_SCREEN + OFFSET_MAP_Y - offsetY : m_arrayPoint[curIndex].y - offsetY;
				if ((_velloc.y < 0 ||_velloc.y > 0 && CRockman::m_IsClimbing) && _pos.y * dirY > (temp)* dirY) {
					if ((m_pos.x - m_arrayPoint[curIndex].x - WIDTH_SCREEN / 2) < 10) {
						m_indexMoveTo = nextIndexY;
						m_DirectMove = DIRECT_Y;
						MoveMap();
						return;
					}
				}
			}
		}
	}
updateViewport:
	m_viewPort.left = m_pos.x;
	m_viewPort.right = m_viewPort.left + WIDTH_SCREEN;
	m_viewPort.top = m_pos.y;
	m_viewPort.bottom =m_viewPort.top - HEIGHT_SCREEN;

	g_PosCamera = m_pos;
}
コード例 #4
0
//We're creating an Icosphere to avoid the density of vertices being greater around the poles like a UV sphere
//In an icosphere, its vertices are distributed evenly.
//http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html
void Sphere::CreateIcosphere(int refineLevel)
{
	//Start by creating the 12 vertices of an icosahedron
	//Phi is the golden ratio
	//http://paulbourke.net/geometry/platonic/
	float phi = (1.0f + sqrt(5.0f)) / 2.0f;

	_mCountVertex = 12;
	_mVertices = new vector<GLfloat>;
	_mVertices->push_back(-1); _mVertices->push_back( phi); _mVertices->push_back(0); //v0
	_mVertices->push_back( 1); _mVertices->push_back( phi); _mVertices->push_back(0); //v1
	_mVertices->push_back(-1); _mVertices->push_back(-phi); _mVertices->push_back(0); //v2
	_mVertices->push_back( 1); _mVertices->push_back(-phi); _mVertices->push_back(0); //v3

	_mVertices->push_back(0); _mVertices->push_back(-1); _mVertices->push_back( phi); //v4
	_mVertices->push_back(0); _mVertices->push_back( 1); _mVertices->push_back( phi); //v5
	_mVertices->push_back(0); _mVertices->push_back(-1); _mVertices->push_back(-phi); //v6
	_mVertices->push_back(0); _mVertices->push_back( 1); _mVertices->push_back(-phi); //v7

	_mVertices->push_back( phi); _mVertices->push_back(0); _mVertices->push_back(-1); //v8
	_mVertices->push_back( phi); _mVertices->push_back(0); _mVertices->push_back( 1); //v9
	_mVertices->push_back(-phi); _mVertices->push_back(0); _mVertices->push_back(-1); //v10
	_mVertices->push_back(-phi); _mVertices->push_back(0); _mVertices->push_back( 1); //v11

	//Normalize vertices to make sure they're on a unit sphere
	for (vector<GLfloat>::size_type i = 0; i < _mVertices->size(); i += 3)
	{
		GLfloat x = _mVertices->at(i + 0);
		GLfloat y = _mVertices->at(i + 1);
		GLfloat z = _mVertices->at(i + 2);
		float len = sqrt(x*x + y*y + z*z);

		_mVertices->at(i+0) /= len;
		_mVertices->at(i+1) /= len;
		_mVertices->at(i+2) /= len;
	}

	//then create the 20 triangles of the icosahedron (indices)
	//var faces = new List<TriangleIndices>();
	_mIndices = new vector<GLuint>;
	_mCountTriangle = 20;
	_mCountIndex = 20*3;

	//5 faces around point 0
	_mIndices->push_back(0); _mIndices->push_back(11); _mIndices->push_back( 5);
	_mIndices->push_back(0); _mIndices->push_back( 5); _mIndices->push_back( 1);
	_mIndices->push_back(0); _mIndices->push_back( 1); _mIndices->push_back( 7);
	_mIndices->push_back(0); _mIndices->push_back( 7); _mIndices->push_back(10);
	_mIndices->push_back(0); _mIndices->push_back(10); _mIndices->push_back(11);

	//5 adjacent faces
	_mIndices->push_back( 1); _mIndices->push_back( 5); _mIndices->push_back(9);
	_mIndices->push_back( 5); _mIndices->push_back(11); _mIndices->push_back(4);
	_mIndices->push_back(11); _mIndices->push_back(10); _mIndices->push_back(2);
	_mIndices->push_back(10); _mIndices->push_back( 7); _mIndices->push_back(6);
	_mIndices->push_back( 7); _mIndices->push_back( 1); _mIndices->push_back(8);

	//5 faces around point 3
	_mIndices->push_back(3); _mIndices->push_back(9); _mIndices->push_back(4);
	_mIndices->push_back(3); _mIndices->push_back(4); _mIndices->push_back(2);
	_mIndices->push_back(3); _mIndices->push_back(2); _mIndices->push_back(6);
	_mIndices->push_back(3); _mIndices->push_back(6); _mIndices->push_back(8);
	_mIndices->push_back(3); _mIndices->push_back(8); _mIndices->push_back(9);

	//5 adjacent faces
	_mIndices->push_back(4); _mIndices->push_back(9); _mIndices->push_back( 5);
	_mIndices->push_back(2); _mIndices->push_back(4); _mIndices->push_back(11);
	_mIndices->push_back(6); _mIndices->push_back(2); _mIndices->push_back(10);
	_mIndices->push_back(8); _mIndices->push_back(6); _mIndices->push_back( 7);
	_mIndices->push_back(9); _mIndices->push_back(8); _mIndices->push_back( 1);

	//Refine triangles
	int currentTriCount = _mCountTriangle;
	for (int r = 0; r < refineLevel; r++)
	{
		vector<GLuint> *indicesTemp = new vector<GLuint>;
		for (int t = 0, i = 0; t<currentTriCount; t++, i += 3)
		{
			//replace triangle by 4 triangles
			int a = GetMiddlePoint(_mIndices->at(i), _mIndices->at(i+1));
			int b = GetMiddlePoint(_mIndices->at(i+1), _mIndices->at(i+2));
			int c = GetMiddlePoint(_mIndices->at(i+2), _mIndices->at(i));

			//Add the new indices
			//T1
			indicesTemp->push_back(_mIndices->at(i));
			indicesTemp->push_back(a);
			indicesTemp->push_back(c);
			//T2
			indicesTemp->push_back(_mIndices->at(i + 1));
			indicesTemp->push_back(b);
			indicesTemp->push_back(a);
			//T3
			indicesTemp->push_back(_mIndices->at(i + 2));
			indicesTemp->push_back(c);
			indicesTemp->push_back(b);
			//T4
			indicesTemp->push_back(a);
			indicesTemp->push_back(b);
			indicesTemp->push_back(c);
		}

		//replace _mIndices with indicesTemp to keep the new index array
		_mIndices = indicesTemp;
		indicesTemp = NULL;

		//update triangle & indices count
		_mCountTriangle *= 4;
		_mCountIndex *= 4;
		currentTriCount = _mCountTriangle;
	}

	_mRotAngleX = 0.0;
	_mRotAngleY = 0.0;
	_mRotAngleZ = 0.0;
}