예제 #1
0
	cResourceImage::cResourceImage(tString asName,cFrameTexture *apFrameTex,
		cFrameBitmap *apFrameBmp, cRect2l aRect,
		cVector2l avSrcSize, int alHandle) : iResourceBase(asName,0)
	{
		mpFrameTexture = apFrameTex;
		mpFrameBitmap = apFrameBmp;
		mRect = aRect;
		mvSourceSize = avSrcSize;
		mlHandle = alHandle;

		cVector2f vTexSize = cVector2f((float)mRect.w,(float)mRect.h ) /
								cVector2f((float)mvSourceSize.x,(float)mvSourceSize.y);
		cVector2f vTexPos = cVector2f((float)mRect.x,(float)mRect.y ) /
								cVector2f((float)mvSourceSize.x,(float)mvSourceSize.y);

		mvVtx.push_back(cVertex(cVector3f(0,0,0),
						cVector3f(vTexPos.x+kContractSize, vTexPos.y+kContractSize,0), cColor(1)));

		mvVtx.push_back(cVertex(cVector3f((float)mRect.w,0,0),
						cVector3f(vTexPos.x+vTexSize.x-kContractSize, vTexPos.y+kContractSize,0),
						cColor(1)));

		mvVtx.push_back(cVertex(cVector3f((float)mRect.w,(float)mRect.h,0),
						cVector3f(vTexPos.x+vTexSize.x-kContractSize, vTexPos.y+vTexSize.y-kContractSize,0),
						cColor(1)));

		mvVtx.push_back(cVertex(cVector3f(0,(float)mRect.h,0),
						cVector3f(vTexPos.x+kContractSize, vTexPos.y+vTexSize.y-kContractSize,0),
						cColor(1)));
	}
 void CQTOpenGLEPuck::RenderLED() {
    /* Side surface */
    CVector2 cVertex(BODY_RADIUS, 0.0f);
    CRadians cAngle(CRadians::TWO_PI / m_unVertices);
    CVector2 cNormal(1.0f, 0.0f);
    glBegin(GL_QUAD_STRIP);
    for(GLuint i = 0; i <= m_unVertices / 8; i++) {
       glNormal3f(cNormal.GetX(), cNormal.GetY(), 0.0f);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), LED_ELEVATION + LED_HEIGHT);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), LED_ELEVATION);
       cVertex.Rotate(cAngle);
       cNormal.Rotate(cAngle);
    }
    glEnd();
    /* Top surface  */
    cVertex.Set(BODY_RADIUS, 0.0f);
    CVector2 cVertex2(LED_UPPER_RING_INNER_RADIUS, 0.0f);
    glBegin(GL_QUAD_STRIP);
    glNormal3f(0.0f, 0.0f, 1.0f);      
    for(GLuint i = 0; i <= m_unVertices / 8; i++) {         
       glVertex3f(cVertex2.GetX(), cVertex2.GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
       cVertex.Rotate(cAngle);
       cVertex2.Rotate(cAngle);
    }
    glEnd();
 }
예제 #3
0
   void CQTOpenGLUserFunctions::DrawCircle(const CVector3& c_position,
                                           const CQuaternion& c_orientation,
                                           Real f_radius,
                                           const CColor& c_color,
                                           const bool b_fill,
                                           GLuint un_vertices) {
      /* Save attributes and current matrix */
      glPushAttrib(GL_POLYGON_BIT);
      /* Set color */
      SetColor(c_color);
      /* Disable face culling, to make the triangle visible from any angle */
	    glDisable(GL_CULL_FACE);
      /* Set polygon attributes */
	    glEnable(GL_POLYGON_SMOOTH);
      glPolygonMode(GL_FRONT_AND_BACK, b_fill ? GL_FILL : GL_LINE);
      /* Set position/orientation */
      Rototranslate(c_position, c_orientation);
      /*  Draw */
	    CVector2 cVertex(f_radius, 0.0f);
	    CRadians cAngle(CRadians::TWO_PI / un_vertices);
      glBegin(GL_POLYGON);
      glNormal3f(0.0f, 0.0f, 1.0f);
      for(size_t i = 0; i < un_vertices; ++i) {
         glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
         cVertex.Rotate(cAngle);
      }
      glEnd();
      /* Restore saved stuff */
      glPopAttrib();
   }
예제 #4
0
void cMesh2D::CreateVertexVec()
{
    for(int i=0; i<(int)mvPos.size(); i++)
        {
            mvVtx[0].push_back(cVertex(cVector3f(mvPos[i].x,mvPos[i].y,0),mvTexCoord[i],mvColor[i]));
        }

    CalculateEdges(eTileRotation_0,mvVtx[0],mvEdgeIndex);
}
예제 #5
0
파일: bomb.cpp 프로젝트: bihai/bomberman
bool cBombContainer::blowCheckSpot(int x, int y, std::deque<ptl::cParticle> &newPtls)
{
    cMap &map = getMapRef();
    cRect &mapBounds = map.getBounderies();

    if((x < 0) || (x >= this->w) || (y < 0) || (y >= this->h))
    {
        return false;
    }
    if(map(x, y).object == cMap::BOMB)
    {
        blow(x, y);
    }
    if(map(x, y).blowable)
    {
        int mx = (int)(x + mapBounds.x1);
        int my = (int)(y + mapBounds.y1);
        for(int p = 0; p < OPT_NUM_EXPLO_PTLS / (12/2); p ++)
        {
            ptl::cParticle newPtl(  getRndFloat(0.5, 1.0),
                                    getRndFloat(0.5, 1.0), getRndFloat(0.0, 0.5), getRndFloat(0.0, 0.2),
                                    cVertex(getRndFloat(mx, mx + 1), 0.3, getRndFloat(-my, -my - 1)),
                                    cVertex(getRndFloat(-cos(p), cos(p)), getRndFloat(4.0, 10.0), getRndFloat(-sin(p), sin(p))),
                                    cVertex(0, -0.1, 0)
                                );
            newPtls.push_back(newPtl);
        }
        if(map(x, y).object != cMap::NOTHING)
        {
            if (! map.createPwrUp(x, y))
            {
                map(x, y).walkable = true;
                map(x, y).object = cMap::NOTHING;
            }
            return false;
        }
    }
    else
    {
        return false;
    }
    return true;
}
예제 #6
0
	cGfxObject::cGfxObject(iMaterial* apMat,const tString& asFile, bool abIsImage)
	{
		mpMat = apMat;

		msSourceFile = asFile;

		mbIsImage = abIsImage;
	
		if(mbIsImage)
		{
			mvVtx = apMat->GetImage(eMaterialTexture_Diffuse)->GetVertexVecCopy(0,-1);
		}
		else
		{
			mvVtx.push_back(cVertex(cVector3f(0,0,0),cVector2f(0,0),cColor(1,1)) );
			mvVtx.push_back(cVertex(cVector3f(1,0,0),cVector2f(1,0),cColor(1,1)) );
			mvVtx.push_back(cVertex(cVector3f(1,1,0),cVector2f(1,1),cColor(1,1)) );
			mvVtx.push_back(cVertex(cVector3f(0,1,0),cVector2f(0,1),cColor(1,1)) );
		}
	}
예제 #7
0
	//TODO: Z might have to be some standard value...
	//Has 100 right now, this should be in some global value..
	int cLight2DPoint::Render(iLowLevelGraphics* apLowLevel, int alFirstIndex)
	{
		//make the center vetrex:
		cVector3f vTex(0);
		cVector3f vPos;
		cVector3f vLightPos = GetWorldPosition();
		vLightPos.z = 100;
		float fRadius = GetFarAttenuation();

		cColor Col = GetDiffuseColor()*mfIntensity;
		Col.a =0;
		cVertex Vtx = cVertex(vLightPos,vTex,Col);
		apLowLevel->AddVertexToBatch(&Vtx); //index 0!

		Col = cColor(0,0);
		int idx=alFirstIndex+1;
		for(float fAngle=0;fAngle<=k2Pif;fAngle+=k2Pif/32)
		{
			vPos.x = vLightPos.x + fRadius * cos(fAngle);//*0.5;
			vPos.y = vLightPos.y + fRadius * sin(fAngle);//*0.5;
			vPos.z = 100;
			Vtx = cVertex(vPos,vTex,Col);
			apLowLevel->AddVertexToBatch(&Vtx);
			if(idx>0) {
				apLowLevel->AddIndexToBatch(alFirstIndex);     //The center
				apLowLevel->AddIndexToBatch(idx);   //The current point
				apLowLevel->AddIndexToBatch(idx-1); //The previous  point
			}
			idx++;
		}
		apLowLevel->AddIndexToBatch(alFirstIndex);     //The center
		apLowLevel->AddIndexToBatch(alFirstIndex+1);     //The current point
		apLowLevel->AddIndexToBatch(idx-1); //The previous  point

		return idx;
	}
예제 #8
0
   void CQTOpenGLUserFunctions::DrawTriangle(const CVector3& c_center_offset,
                                             const CColor& c_color,
                                             const bool b_fill,
                                             const CQuaternion& c_orientation,
                                             Real f_base,
                                             Real f_height) {

	    glDisable(GL_LIGHTING);
	    glDisable(GL_CULL_FACE);

	    glColor3ub(c_color.GetRed(),
                 c_color.GetGreen(),
                 c_color.GetBlue());

      if(b_fill) {
         glBegin(GL_POLYGON);
      }
      else {
         glBegin(GL_LINE_LOOP);
      }
      CVector3 cNormalDirection(0.0f, 0.0f, 1.0f);
      cNormalDirection.Rotate(c_orientation);
      glNormal3f(cNormalDirection.GetX(),
                 cNormalDirection.GetY(),
                 cNormalDirection.GetZ());

      CVector3 cVertex(f_height * 0.5f, 0.0f, 0.0f);
      cVertex.Rotate(c_orientation);
      glVertex3f(cVertex.GetX() + c_center_offset.GetX(),
                 cVertex.GetY() + c_center_offset.GetY(),
                 cVertex.GetZ() + c_center_offset.GetZ());

      cVertex.Set(-f_height * 0.5f, f_base * 0.5f, 0.0f);
      cVertex.Rotate(c_orientation);
      glVertex3f(cVertex.GetX() + c_center_offset.GetX(),
                 cVertex.GetY() + c_center_offset.GetY(),
                 cVertex.GetZ() + c_center_offset.GetZ());

      cVertex.Set(-f_height * 0.5f, -f_base * 0.5f, 0.0f);
      cVertex.Rotate(c_orientation);
      glVertex3f(cVertex.GetX() + c_center_offset.GetX(),
                 cVertex.GetY() + c_center_offset.GetY(),
                 cVertex.GetZ() + c_center_offset.GetZ());
      glEnd();

      glEnable(GL_CULL_FACE);
      glEnable(GL_LIGHTING);
   }
예제 #9
0
   void CQTOpenGLCylinder::MakeBody() {
      /* Since this shape can be stretched,
         make sure the normal vectors are unit-long */
      glEnable(GL_NORMALIZE);

      /* Set the material */
      glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SPECULAR);
      glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, SHININESS);
      glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, EMISSION);

      /* Let's start the actual shape */
      /* Side surface */
      CVector2 cVertex(1.0f, 0.0f);
      CRadians cAngle(CRadians::TWO_PI / m_unVertices);
      glBegin(GL_QUAD_STRIP);
      for(GLuint i = 0; i <= m_unVertices; i++) {
         glNormal3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
         glVertex3f(cVertex.GetX(), cVertex.GetY(), 1.0f);
         glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
         cVertex.Rotate(cAngle);
      }
      glEnd();
      /* Top disk */
      cVertex.Set(1.0f, 0.0f);
      glBegin(GL_POLYGON);
      glNormal3f(0.0f, 0.0f, 1.0f);
      for(GLuint i = 0; i <= m_unVertices; i++) {
         glVertex3f(cVertex.GetX(), cVertex.GetY(), 1.0f);
         cVertex.Rotate(cAngle);
      }
      glEnd();
      /* Bottom disk */
      cVertex.Set(1.0f, 0.0f);
      cAngle = -cAngle;
      glBegin(GL_POLYGON);
      glNormal3f(0.0f, 0.0f, -1.0f);
      for(GLuint i = 0; i <= m_unVertices; i++) {
         glVertex3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
         cVertex.Rotate(cAngle);
      }
      glEnd();
      /* The shape definition is finished */

      /* We don't need it anymore */
      glDisable(GL_NORMALIZE);

   }
예제 #10
0
   void CQTOpenGLUserFunctions::DrawCircle(Real f_radius,
                                           const CVector3& c_center_offset,
                                           const CColor& c_color,
                                           const bool b_fill,
                                           const CQuaternion& c_orientation,
                                           GLuint un_vertices) {

	    glDisable(GL_LIGHTING);
	    glDisable(GL_CULL_FACE);

	    glColor3ub(c_color.GetRed(),
                 c_color.GetGreen(),
                 c_color.GetBlue());

	    CVector3 cVertex(f_radius, 0.0f, 0.0f);
	    CRadians cAngle(CRadians::TWO_PI / un_vertices);

      if(b_fill) {
         glBegin(GL_POLYGON);
      }
      else {
         glBegin(GL_LINE_LOOP);
      }
      CVector3 cNormalDirection(0.0f, 0.0f, 1.0f);
      cNormalDirection.Rotate(c_orientation);
      glNormal3f(cNormalDirection.GetX(),
                 cNormalDirection.GetY(),
                 cNormalDirection.GetZ());

      /* Compute the quaternion defining the rotation of the vertices used to draw the circle. */
      CQuaternion cVertexRotation;
      CVector3 cVertexRotationAxis(0.0f, 0.0f, 1.0f);
      cVertexRotationAxis.Rotate(c_orientation);
      cVertexRotation.FromAngleAxis(cAngle, cVertexRotationAxis);

	    cVertex.Rotate(c_orientation);
      for(GLuint i = 0; i <= un_vertices; i++) {
         glVertex3f(cVertex.GetX() + c_center_offset.GetX(),
                    cVertex.GetY() + c_center_offset.GetY(),
                    cVertex.GetZ() + c_center_offset.GetZ());
         cVertex.Rotate(cVertexRotation);
      }
      glEnd();

      glEnable(GL_CULL_FACE);
      glEnable(GL_LIGHTING);
   }
예제 #11
0
 void CQTOpenGLUserFunctions::DrawCylinder(const CVector3& c_position,
                                           const CQuaternion& c_orientation,
                                           Real f_radius,
                                           Real f_height,
                                           const CColor& c_color,
                                           GLuint un_vertices) {
    /* Save current matrix */
    glPushMatrix();
    /* Set color */
    SetColor(c_color);
    /* Set position/orientation */
    Rototranslate(c_position, c_orientation);
    /* Draw side surface */
    Real fHalfHeight = f_height * 0.5f;
    CVector2 cVertex(1.0f, 0.0f);
    CRadians cAngle(CRadians::TWO_PI / un_vertices);
    glBegin(GL_QUAD_STRIP);
    for(GLuint i = 0; i <= un_vertices; i++) {
       glNormal3f(cVertex.GetX(), cVertex.GetY(), 0.0f);
       glVertex3f(cVertex.GetX() * f_radius, cVertex.GetY() * f_radius,  fHalfHeight);
       glVertex3f(cVertex.GetX() * f_radius, cVertex.GetY() * f_radius, -fHalfHeight);
       cVertex.Rotate(cAngle);
    }
    glEnd();
    /* Draw top disk */
    cVertex.Set(f_radius, 0.0f);
    glBegin(GL_POLYGON);
    glNormal3f(0.0f, 0.0f, 1.0f);
    for(GLuint i = 0; i <= un_vertices; i++) {
       glVertex3f(cVertex.GetX(), cVertex.GetY(), fHalfHeight);
       cVertex.Rotate(cAngle);
    }
    glEnd();
    /* Draw bottom disk */
    cVertex.Set(f_radius, 0.0f);
    cAngle = -cAngle;
    glBegin(GL_POLYGON);
    glNormal3f(0.0f, 0.0f, -1.0f);
    for(GLuint i = 0; i <= un_vertices; i++) {
       glVertex3f(cVertex.GetX(), cVertex.GetY(), -fHalfHeight);
       cVertex.Rotate(cAngle);
    }
    glEnd();
    /* Restore saved matrix */
    glPopMatrix();
 }
예제 #12
0
 void CQTOpenGLEPuck::RenderWheel() {
    /* Set material */
    SetRedPlasticMaterial();
    /* Right side */
    CVector2 cVertex(WHEEL_RADIUS, 0.0f);
    CRadians cAngle(CRadians::TWO_PI / m_unVertices);
    CVector3 cNormal(-1.0f, -1.0f, 0.0f);
    cNormal.Normalize();
    glBegin(GL_POLYGON);
    for(GLuint i = 0; i <= m_unVertices; i++) {
       glNormal3f(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
       glVertex3f(cVertex.GetX(), -HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.GetY());
       cVertex.Rotate(cAngle);
       cNormal.RotateY(cAngle);
    }
    glEnd();
    /* Left side */
    cVertex.Set(WHEEL_RADIUS, 0.0f);
    cNormal.Set(-1.0f, 1.0f, 0.0f);
    cNormal.Normalize();
    cAngle = -cAngle;
    glBegin(GL_POLYGON);
    for(GLuint i = 0; i <= m_unVertices; i++) {
       glNormal3f(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
       glVertex3f(cVertex.GetX(), HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.GetY());
       cVertex.Rotate(cAngle);
       cNormal.RotateY(cAngle);
    }
    glEnd();
    /* Tire */
    cNormal.Set(1.0f, 0.0f, 0.0f);
    cVertex.Set(WHEEL_RADIUS, 0.0f);
    cAngle = -cAngle;
    glBegin(GL_QUAD_STRIP);
    for(GLuint i = 0; i <= m_unVertices; i++) {
       glNormal3f(cNormal.GetX(), cNormal.GetY(), cNormal.GetZ());
       glVertex3f(cVertex.GetX(), -HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.GetY());
       glVertex3f(cVertex.GetX(),  HALF_WHEEL_WIDTH, WHEEL_RADIUS + cVertex.GetY());
       cVertex.Rotate(cAngle);
       cNormal.RotateY(cAngle);
    }
    glEnd();
 }
예제 #13
0
 void CQTOpenGLEPuck::RenderBody() {
    /* Set material */
    SetGreenPlasticMaterial();
    CVector2 cVertex(BODY_RADIUS, 0.0f);
    CRadians cAngle(-CRadians::TWO_PI / m_unVertices);
    /* Bottom part */
    glBegin(GL_POLYGON);
    glNormal3f(0.0f, 0.0f, -1.0f);
    for(GLuint i = 0; i <= m_unVertices; i++) {
       glVertex3f(cVertex.GetX(), cVertex.GetY(), BODY_ELEVATION);
       cVertex.Rotate(cAngle);
    }
    glEnd();
    /* Side surface */
    cAngle = -cAngle;
    CVector2 cNormal(1.0f, 0.0f);
    cVertex.Set(BODY_RADIUS, 0.0f);
    glBegin(GL_QUAD_STRIP);
    for(GLuint i = 0; i <= m_unVertices; i++) {
       glNormal3f(cNormal.GetX(), cNormal.GetY(), 0.0f);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), BODY_ELEVATION + BODY_HEIGHT);
       glVertex3f(cVertex.GetX(), cVertex.GetY(), BODY_ELEVATION);
       cVertex.Rotate(cAngle);
       cNormal.Rotate(cAngle);
    }
    glEnd();
    /* Top part */
    glBegin(GL_POLYGON);
    cVertex.Set(LED_UPPER_RING_INNER_RADIUS, 0.0f);
    glNormal3f(0.0f, 0.0f, 1.0f);
    for(GLuint i = 0; i <= m_unVertices; i++) {
       glVertex3f(cVertex.GetX(), cVertex.GetY(), BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT);
       cVertex.Rotate(cAngle);
    }
    glEnd();
    /* Triangle to set the direction */
    SetLEDMaterial(1.0f, 1.0f, 0.0f);
    glBegin(GL_TRIANGLES);
    glVertex3f( BODY_RADIUS * 0.7,               0.0f, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
    glVertex3f(-BODY_RADIUS * 0.7,  BODY_RADIUS * 0.3, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
    glVertex3f(-BODY_RADIUS * 0.7, -BODY_RADIUS * 0.3, BODY_ELEVATION + BODY_HEIGHT + LED_HEIGHT + 0.001f);
    glEnd();
 }
예제 #14
0
    void cCylinder::Build()
    {                               // surface_QUADS + bound1_TRI + bound2_TRI
        unsigned int numVertices = 4 * mNrMesh + 3 * mNrMesh + 3 * mNrMesh;
        unsigned int numIndices = 6 * mNrMesh + 3 * mNrMesh + 3 * mNrMesh;

        mpSolidVertexBuffer->Clear();

        mpSolidVertexBuffer->ReserveVertices(numVertices);
        mpSolidVertexBuffer->ReserveIndices(numIndices);

        float dth = 0;
        if (mNrMesh != 0)
            dth = 2 * PI / mNrMesh;
        unsigned int ind = 0;

        tVertexVec rect;
        rect.resize(4);

        tVertexVec triangle;
        triangle.resize(3);

        // surface

        float th = 0;
        int n = 0;

        while (n < mNrMesh)
        {
            float vtx = mRadius*cos(th);
            float vty = mRadius*sin(th);

            float vdx = mRadius*cos(th+dth);
            float vdy = mRadius*sin(th+dth);

            float l = mLength;

                                                     // GetSurfaceNormal(p)
            rect[0] = cVertex( cVector3f(vtx,vty,0), cVector3f(vtx,vty,0), mColor );
            rect[1] = cVertex( cVector3f(vdx,vdy,0), cVector3f(vdx,vdy,0), mColor );
            rect[2] = cVertex( cVector3f(vdx,vdy,l), cVector3f(vdx,vdy,0), mColor );
            rect[3] = cVertex( cVector3f(vtx,vty,l), cVector3f(vtx,vty,0), mColor );

            for (int i = 0; i < 4; i++)
                rect[i].nor.Normalize();

            AddTriangle(rect[0], rect[1], rect[2]);
            AddTriangle(rect[0], rect[2], rect[3]);

            for (int i = 0; i < 6; i++)
                mpSolidVertexBuffer->AddIndex(ind++);

            n++;
            th = th + dth;
        }

        // bound (z = 0)

        th = 0;
        n = 0;

        while (n < mNrMesh)
        {
            float vtx = mRadius*cos(th);
            float vty = mRadius*sin(th);

            float vdx = mRadius*cos(th+dth);
            float vdy = mRadius*sin(th+dth);

            triangle[0] = cVertex( cVector3f(0,0,0),     cVector3f(0,0,-1), mColor );
            triangle[1] = cVertex( cVector3f(vdx,vdy,0), cVector3f(0,0,-1), mColor );
            triangle[2] = cVertex( cVector3f(vtx,vty,0), cVector3f(0,0,-1), mColor );

            for (int i = 0; i < 3; i++)
                triangle[i].nor.Normalize();

            AddTriangle(triangle[0], triangle[1], triangle[2]);

            for (int i = 0; i < 3; i++)
                mpSolidVertexBuffer->AddIndex(ind++);

            n++;
            th = th + dth;
        }

        // bound (z = L)

        th = 0;
        n = 0;

        while (n < mNrMesh)
        {
            float vtx = mRadius*cos(th);
            float vty = mRadius*sin(th);

            float vdx = mRadius*cos(th+dth);
            float vdy = mRadius*sin(th+dth);

            float l = mLength;

            triangle[0] = cVertex( cVector3f(0,0,l),     cVector3f(0,0,1), mColor );
            triangle[1] = cVertex( cVector3f(vtx,vty,l), cVector3f(0,0,1), mColor );
            triangle[2] = cVertex( cVector3f(vdx,vdy,l), cVector3f(0,0,1), mColor );

            for (int i = 0; i < 3; i++)
                triangle[i].nor.Normalize();

            AddTriangle(triangle[0], triangle[1], triangle[2]);

            for (int i = 0; i < 3; i++)
                mpSolidVertexBuffer->AddIndex(ind++);

            n++;
            th = th + dth;
        }

        rect.clear();
        triangle.clear();

        // bounding volume

        mBoundingVolume.SetSize(cVector3f(-mRadius,-mRadius,0),
            cVector3f(mRadius,mRadius,mLength));

        mvSize.x = mRadius;
        mvSize.y = mRadius;
        mvSize.z = mLength;

        mpSolidVertexBuffer->RemoveDuplicateVertices();
    }
예제 #15
0
파일: Box.cpp 프로젝트: Gestalt/RFWaves
    void cBox::Build() // without mesh
    {
        unsigned int numVertices = 24;
        unsigned int numIndices = 36;

        mpSolidVertexBuffer->Clear();

        mpSolidVertexBuffer->ReserveVertices(numVertices);
        mpSolidVertexBuffer->ReserveIndices(numIndices);

        tVertexVec rect;
        rect.resize(4);

        float minX = 0;
        float minY = 0;
        float minZ = 0;

        float maxX = mWidth;
        float maxY = mHeight;
        float maxZ = mLength;

        // plane XY
        rect[0] = cVertex( cVector3f(minX,minY,minZ), cVector3f(0,0,-1), mColor );
        rect[1] = cVertex( cVector3f(minX,maxY,minZ), cVector3f(0,0,-1), mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,minZ), cVector3f(0,0,-1), mColor );
        rect[3] = cVertex( cVector3f(maxX,minY,minZ), cVector3f(0,0,-1), mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        rect[0] = cVertex( cVector3f(minX,minY,maxZ), cVector3f(0,0,1),  mColor );
        rect[1] = cVertex( cVector3f(maxX,minY,maxZ), cVector3f(0,0,1),  mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,maxZ), cVector3f(0,0,1),  mColor );
        rect[3] = cVertex( cVector3f(minX,maxY,maxZ), cVector3f(0,0,1),  mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        // plane YZ
        rect[0] = cVertex( cVector3f(minX,minY,minZ), cVector3f(-1,0,0), mColor );
        rect[1] = cVertex( cVector3f(minX,minY,maxZ), cVector3f(-1,0,0), mColor );
        rect[2] = cVertex( cVector3f(minX,maxY,maxZ), cVector3f(-1,0,0), mColor );
        rect[3] = cVertex( cVector3f(minX,maxY,minZ), cVector3f(-1,0,0), mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        rect[0] = cVertex( cVector3f(maxX,minY,minZ), cVector3f(1,0,0),  mColor );
        rect[1] = cVertex( cVector3f(maxX,maxY,minZ), cVector3f(1,0,0),  mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,maxZ), cVector3f(1,0,0),  mColor );
        rect[3] = cVertex( cVector3f(maxX,minY,maxZ), cVector3f(1,0,0),  mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        // plane XZ
        rect[0] = cVertex( cVector3f(minX,minY,minZ), cVector3f(0,-1,0), mColor );
        rect[1] = cVertex( cVector3f(maxX,minY,minZ), cVector3f(0,-1,0), mColor );
        rect[2] = cVertex( cVector3f(maxX,minY,maxZ), cVector3f(0,-1,0), mColor );
        rect[3] = cVertex( cVector3f(minX,minY,maxZ), cVector3f(0,-1,0), mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        rect[0] = cVertex( cVector3f(minX,maxY,minZ), cVector3f(0,1,0),  mColor );
        rect[1] = cVertex( cVector3f(minX,maxY,maxZ), cVector3f(0,1,0),  mColor );
        rect[2] = cVertex( cVector3f(maxX,maxY,maxZ), cVector3f(0,1,0),  mColor );
        rect[3] = cVertex( cVector3f(maxX,maxY,minZ), cVector3f(0,1,0),  mColor );

        AddTriangle(rect[0], rect[1], rect[2]);
        AddTriangle(rect[0], rect[2], rect[3]);

        unsigned int ind = 0;

        for (int i = 0; i < (int)numIndices; i++)
            mpSolidVertexBuffer->AddIndex(ind++);

        rect.clear();

        // bounding volume

        mBoundingVolume.SetSize( cVector3f(0,0,0), cVector3f(mWidth,mHeight,mLength) );

        mvSize.x = mWidth;
        mvSize.y = mHeight;
        mvSize.z = mLength;
    }
예제 #16
0
static void
idle(void)
{
    static float lastT = SDL_GetTicks();
    float ticks;
    ticks = SDL_GetTicks() - lastT;
    lastT = SDL_GetTicks();

    /*
    * WORLD HANDLING
    */
    ptl::tickParticles();
    prjctl::tickProjectiles(ticks / 100.0);
    rck::tickRocks(ticks / 1000.0);

    rect4f plLimits;
    switch(getPlayerState()) {
        case PLST_DEAD:
            setPlayerState(PLST_NEEDSPAWN);
            playerLives --;
            break;

        case PLST_NEEDSPAWN:
            plLimits = player.getLimits();
            for(int i=0; i < 10; i ++) {
                float x = getRndFloat(plLimits.x1, plLimits.x2);
                float y = getRndFloat(plLimits.y1, plLimits.y2);

                if(rck::closestRockDistance(pos2f(x, y)) > 4.0) {
                    player.setPos(pos2f(x, y));
                    player.setSpeed(vector2f(0.0, 0.0));
                    setPlayerState(PLST_NORMAL);
                }
            }
            break;

        default:
        case PLST_NORMAL:
            if(player.checkCollide()) {
                setPlayerState(PLST_DEAD);
            }

            player.updatePos(ticks / 10.0);
            player.dampenSpeed(ticks / 50000.0);
            break;
    }

    if(rck::getLiveRocks() == 0) {
        curLvl ++;
        snd::playSound(snd::NEXT_LEVEL);
        loadLevel(curLvl);
    }

    /*
    * KEY HANDLING
    */
    Uint8 *keys;
    keys = SDL_GetKeyState(NULL);

    if ( keys[SDLK_ESCAPE] ) {
      mainloopDone = 1;
    }
    if ( keys[SDLK_UP] ) {
        player.thrust(ticks / 10000.0);

        snd::startSoundOnce(snd::ENGINE);

        std::deque<ptl::cParticle> newPtls;
        for(int i = 0; i < 50; i ++)
        {
            float rndFloat = getRndFloat((player.getAngle()+200.0)*M_PI/180.0, (player.getAngle()+340.0)*M_PI/180.0);
            ptl::cParticle newPtl(  getRndFloat(0.2, 0.4),
                                    1.0, getRndFloat(0.0, 0.5), 0.0,
                                    cVertex(player.getPos().x + cos((player.getAngle()+90.0)*M_PI/180.0) * getRndFloat(1.1, 1.5), player.getPos().y + sin((player.getAngle()-90.0)*M_PI/180.0) * getRndFloat(1.1, 1.5),  - 0.5),
                                    cVertex(-player.getSpeed().x*10.0 + cos(rndFloat+M_PI) * 5, -player.getSpeed().y*10.0 + sin(rndFloat)*5, getRndFloat(-2.0, 0.0)),
                                    cVertex(0.0, 0.0, 0)
                                );
            newPtls.push_back(newPtl);
        }
        ptl::createParticles(newPtls);
    }
    if ( !keys[SDLK_UP] ) {
        snd::stopSound(snd::ENGINE);
    }
    if ( keys[SDLK_DOWN] ) {

    }
    if ( keys[SDLK_LEFT] ) {
        player.turn(LEFT, ticks / 5.0);
    }
    if ( keys[SDLK_RIGHT] ) {
        player.turn(RIGHT, ticks / 5.0);
    }
    if ( keys[SDLK_SPACE] ) {
        static float shotTimer = 0;

        if(SDL_GetTicks() - shotTimer > 500) {
            snd::playSound(snd::LASER);

            prjctl::cProjectile newPrjctl;
            std::deque<prjctl::cProjectile> newPrjctls;

            newPrjctl.setPos(pos2f(player.getPos().x - cos((player.getAngle()+90.0)*M_PI/180.0) * 1.3, player.getPos().y - sin((player.getAngle()-90.0)*M_PI/180.0) * 1.3));
            newPrjctl.setTtl(20.0);
            newPrjctl.setSpeed(vector2f(cos((player.getAngle()-90.0)*M_PI/180.0), sin((player.getAngle()+90.0)*M_PI/180.0)));
            newPrjctl.setAngle(player.getAngle());

            newPrjctls.push_back(newPrjctl);

            prjctl::createProjectiles(newPrjctls);

            shotTimer = SDL_GetTicks();
        }
    }
    if ( keys[SDLK_z] ) {

    }
}
예제 #17
0
파일: bomb.cpp 프로젝트: bihai/bomberman
void cBombContainer::blow(int x, int y)
{
    cMap &map = getMapRef();
    cRect &mapBounds = map.getBounderies();

    // Allow player to drop one more bomb now
    this->rejuvenateCount[this->bombs[y * this->w + x].playerId] ++;

    // Play sounds
    snd::Snd_Play(snd::SND_EXPLOSION);

    // Spawn particles
    float mx = x + mapBounds.x1;
    float my = y + mapBounds.y1;
    int blowLength = this->bombs[y * this->w + x].blowLength;
    std::deque<ptl::cParticle> newPtls;

    // Out going
    for(int i = 0; i < OPT_NUM_EXPLO_PTLS / (12/2); i ++)
    {
        ptl::cParticle newPtl(  getRndFloat(0.3, 0.7),
                                1.0, getRndFloat(0.0, 0.5), 0.0,
                                cVertex(mx + 0.5, 0.3, -my - 0.5),
                                cVertex(getRndFloat(-cos(i), cos(i)), getRndFloat(4.0, 10.0), getRndFloat(-sin(i), sin(i))),
                                cVertex(0, -0.1, 0)
                            );
        newPtls.push_back(newPtl);
    }

    // Left/Right going
    for(int i = 0; i < OPT_NUM_EXPLO_PTLS / (12/5); i ++)
    {
        ptl::cParticle newPtl(  getRndFloat(6.0 / blowLength, 6.0 / blowLength),
                                getRndFloat(0.5, 1.0), getRndFloat(0.0, 0.7), 0.0,
                                cVertex(mx + 0.5, 0.3, -my - 0.5),
                                cVertex(getRndFloat(-8.0, 8.0), getRndFloat(-0.1, 0.1), getRndFloat(-0.1, 0.1)),
                                cVertex(0, -0.1, 0)
                            );
        newPtls.push_back(newPtl);
    }

    // Up/Down going
    for(int i = 0; i < OPT_NUM_EXPLO_PTLS / (12/5); i ++)
    {
        ptl::cParticle newPtl(  getRndFloat(6.0 / blowLength, 6.0 / blowLength),
                                getRndFloat(0.5, 1.0), getRndFloat(0.0, 0.7), 0.0,
                                cVertex(mx + 0.5, 0.3, -my - 0.5),
                                cVertex(getRndFloat(-0.1, 0.1), getRndFloat(-0.1, 0.1), getRndFloat(-8.0, 8.0)),
                                cVertex(0, -0.1, 0)
                            );
        newPtls.push_back(newPtl);
    }


    // Remove stuff (crates, aso)
    this->bombs[y * this->w + x].free = true;
    this->bombs[y * this->w + x].playerId = -1;

    map(x, y).walkable = true;
    map(x, y).object = cMap::NOTHING;

    for(int i = x + 1; i <= x + this->bombs[y * this->w + x].blowLength; i ++)
    {
        if(blowCheckSpot(i, y, newPtls) == false)
        {
            break;
        }
    }

    for(int i = x - 1; i >= x - this->bombs[y * this->w + x].blowLength; i --)
    {
        if(blowCheckSpot(i, y, newPtls) == false)
        {
            break;
        }
    }

    for(int j = y + 1; j <= y + this->bombs[y * this->w + x].blowLength; j ++)
    {
        if(blowCheckSpot(x, j, newPtls) == false)
        {
            break;
        }
    }

    for(int j = y - 1; j >= y - this->bombs[y * this->w + x].blowLength; j --)
    {
        if(blowCheckSpot(x, j, newPtls) == false)
        {
            break;
        }
    }


    // Now create them all the particles
    ptl::createParticles(newPtls);
}
예제 #18
0
bool ompl::LTLVis::VRVPlanner::DijkstraSearch(const ompl::base::PlannerTerminationCondition &ptc, ompl::geometric::PathGeometric &solution)
{
  //update the value we use to check that a vertex has been initialized, or visited, in the current search
  ++crVisitation_;
  WorkingVertexVector pqueue;
  pqueue.clear();
  bool reachedGoal = false;
  bool goalDisconnected = false;

  ompl::LTLVis::tIndex goalIndexReached = 0;

  WorkingVertexVector pathCandidate;

  ompl::LTLVis::tIndex maxK = vertices_.size();
  for(ompl::LTLVis::tIndex k = 0; k < maxK; k++)
  {
    if(vertices_[k].getIsStart())
    {
      vertices_[k].setNegativeDistance(0);
      vertices_[k].setLastInitAlg(crVisitation_);
      pqueue.push_back(&vertices_[k]);
    }
  }
  make_heap(pqueue.begin(), pqueue.end(), VRVVertex::VRVVertexCompare);

  while(pqueue.size() && (ptc == false))
  {
    VRVVertex *cVertex(pqueue.front());
    pop_heap(pqueue.begin(), pqueue.end(), VRVVertex::VRVVertexCompare); pqueue.pop_back();

    if(cVertex->getLastVisitation() < crVisitation_)
    {
      cVertex->setLastVisitation(crVisitation_);
      if(cVertex->getIsGoal())
      {
        reachedGoal = true;
        goalIndexReached = cVertex->getIndex();
        break;
      }
      ompl::LTLVis::tIndex kMax = cVertex->getEdgeCount();
      for(ompl::LTLVis::tIndex k = 0; k < kMax; k++)
      {
        double weight;
        ompl::LTLVis::tIndex towards;
        cVertex->getEdge(k, weight, towards);
        VRVVertex *cTarget(&vertices_[towards]);
        if(cTarget->isInteresting())
        {
          //STL heap is a max heap, so we use negative edge weights to 'convert' it to a min-heap
          if(cTarget->getLastInitAlg() < crVisitation_)
          {
            cTarget->setLastInitAlg(crVisitation_);
            cTarget->setNegativeDistance(cVertex->getNegativeDistance() - weight - cTarget->getNodeCost());
            cTarget->setPreceding(cVertex->getIndex());
            cTarget->setPrecedingEdge(k);
            pqueue.push_back(cTarget); push_heap(pqueue.begin(), pqueue.end(), VRVVertex::VRVVertexCompare);
          }
          else
          {
            double negativeDist = cVertex->getNegativeDistance() - weight - cTarget->getNodeCost();
            if(negativeDist > cTarget->getNegativeDistance())
            {
              cTarget->setNegativeDistance(negativeDist);
              cTarget->setPreceding(cVertex->getIndex());
              cTarget->setPrecedingEdge(k);
              pqueue.push_back(cTarget); push_heap(pqueue.begin(), pqueue.end(), VRVVertex::VRVVertexCompare);
            }
          }
        }
      }
    }
  }

  if(reachedGoal)
  {
    pathCandidate.clear();
    ompl::LTLVis::tIndex cIndex = goalIndexReached;
    while(!vertices_[cIndex].getIsStart())
    {
      pathCandidate.push_back(&vertices_[cIndex]);
      cIndex = vertices_[cIndex].getPreceding();
    }
    pathCandidate.push_back(&vertices_[cIndex]);
    ompl::LTLVis::tIndex kMax = pathCandidate.size();
    for(ompl::LTLVis::tIndex k = 0, kPrev = 0; (k < kMax); k++)
    {
      if(0 < k)
      {
        if(0.000001 < si_->distance(pathCandidate[kMax - 1 - k]->getStateData(), pathCandidate[kMax - 1 - kPrev]->getStateData()))
        {
          solution.append(pathCandidate[kMax - 1 - k]->getStateData());
          kPrev = k;
        }
      }
      else
      {
        solution.append(pathCandidate[kMax - 1 - k]->getStateData());
      }
    }
    return true;
  }
  return false;
}