SRGBA CRGBAImplicitGrayscale::get(double x, double y, double z, double w, double u, double v)
    {
        if(m_source==0) return SRGBA(0,0,0,0);

        double val=m_source->get(x,y,z,w,u,v);
        return SRGBA((float)val,(float)val,(float)val,1.0f);
    }
    SRGBA CRGBAImplicitGrayscale::get(double x, double y)
    {
        if(m_source==0) return SRGBA(0,0,0,0);

        double val=m_source->get(x,y);
        return SRGBA((float)val,(float)val,(float)val,1.0f);
    }
Example #3
0
void CEffectsGame::CreateBoxesScene()
{
	float size = 60;

	// floor
	NewtonBody *bFloor = AddBox(pScene, pWorld, Vector3(0,-1,0), Vector3(10000,1,10000), Vector3());	
	NewtonBody *bCeiling = AddBox(pScene, pWorld, Vector3(0,size/2,0), Vector3(size,0.1,size), Vector3());	

	// walls
	AddBox(pScene, pWorld, Vector3(-size/2,size/4,0), Vector3(1,size/2,size), Vector3());	
	AddBox(pScene, pWorld, Vector3(+size/2,size/4,0), Vector3(1,size/2,size), Vector3());	
	AddBox(pScene, pWorld, Vector3(0,size/4,-size/2), Vector3(1,size/2,size), Vector3(0,90,0));	
	AddBox(pScene, pWorld, Vector3(0,size/4,+size/2), Vector3(1,size/2,size), Vector3(0,90,0));	

	// light
	//pScene->fog = new SFog(SRGBA(0,0,0,255), 3, 8);
	pScene->ambientColor = SRGBA(50,50,60,255);

	// create block
	float bias = 1.1f;
	for (int y=0; y<6; y++)
		for (int x=0; x<8; x++)
			for (int z=0; z<8; z++)			
			{
				NewtonBody *box = AddBox(pScene, pWorld, Vector3(-x*bias,y*bias+1,z*bias), Vector3(1,1,1), Vector3(), 100);
				DropDownBox(box);
			}

	pScene->Add( pLight = new CPointLight(Vector3(0,1,0), SRGBA(255,233,155,255)) );
	pLight->specular = SRGBA(255,255,255,100);
	pLight->range = 1;
	pLight->intensity = 1;

	pScene->Add( new CDirectionalLight(Vector3(1,-2,0.5), WHITE));
}
 SRGBA CRGBANormalize::get(double x, double y, double z, double w)
 {
     SRGBA s=m_source.get(x,y,z,w);
     float len=s[0]*s[0] + s[1]*s[1] + s[2]*s[2];
     if(len==0.0)
     {
         return SRGBA(0,0,0,0);
     }
     len=sqrtf(len);
     return SRGBA(s[0]/len, s[1]/len, s[2]/len, s[3]);
 }
 SRGBA CRGBANormalize::get(double x, double y, double z, double w, double u, double v)
 {
     SRGBA s=m_source.get(x,y,z,w,u,v);
     float len=s.rgba[0]*s.rgba[0] + s.rgba[1]*s.rgba[1] + s.rgba[2]*s.rgba[2];
     if(len==0.0)
     {
         return SRGBA(0,0,0,0);
     }
     len=sqrtf(len);
     return SRGBA(s.rgba[0]/len, s.rgba[1]/len, s.rgba[2]/len, s.rgba[3]);
 }
    SRGBA CRGBABlendOps::blendRGBAs(SRGBA &s1, SRGBA &s2)
    {
        float srcfactor, dstfactor;
        switch(m_src1blend)
        {
            case SRC1_ALPHA: srcfactor=s1[3]; break;
            case SRC2_ALPHA: srcfactor=s2[3]; break;
            case ONE_MINUS_SRC1_ALPHA: srcfactor=1.0f-s1[3]; break;
            case ONE_MINUS_SRC2_ALPHA: srcfactor=1.0f-s2[3]; break;
            case ONE: srcfactor=1.0f; break;
            case ZERO: srcfactor=0.0f; break;
            default: srcfactor=0.0f; break;
        };

        switch(m_src2blend)
        {
            case SRC1_ALPHA: dstfactor=s1[3]; break;
            case SRC2_ALPHA: dstfactor=s2[3]; break;
            case ONE_MINUS_SRC1_ALPHA: dstfactor=1.0f-s1[3]; break;
            case ONE_MINUS_SRC2_ALPHA: dstfactor=1.0f-s2[3]; break;
            case ONE: dstfactor=1.0f; break;
            case ZERO: dstfactor=1.0f; break;
            default: dstfactor=0.0f; break;
        };

        return SRGBA(s1[0]*srcfactor+s2[0]*dstfactor, s1[1]*srcfactor+s2[1]*dstfactor,
            s1[2]*srcfactor+s2[2]*dstfactor, s2[3]);
    }
    void calcNormalMap(CArray2Dd *map, CArray2Drgba *bump, double spacing, bool normalize, bool wrap)
    {
        if(!map || !bump) return;
        int mw=map->width(), mh=map->height();
        if(mw!=bump->width() || mh!=bump->height()) bump->resize(mw,mh);

        for(int x=0; x<mw; ++x)
        {
            for(int y=0; y<mh; ++y)
            {
                double n[3]={0.0, 1.0, 0.0};

                if(!wrap)
                {
                    if(x==0 || y==0 || x==mw-1 || y==mh-1)
                    {
                        n[0]=0.0;
                        n[2]=0.0;
                    }
                    else
                    {
                        n[0]=(map->get(x-1,y)-map->get(x+1,y)) / spacing;
                        n[2]=(map->get(x,y-1)-map->get(x,y+1)) / spacing;
                    }
                    normalizeVec3(n);
                }
                else
                {
                    int x1,x2,y1,y2;
                    if(x==0) x1=mw-1;
                    else x1=x-1;

                    if(y==0) y1=mh-1;
                    else y1=y-1;

                    if(x==mw-1) x2=0;
                    else x2=x+1;

                    if(y==mh-1) y2=0;
                    else y2=y+1;

                    n[0]=(map->get(x1,y)-map->get(x2,y)) / spacing;
                    n[2]=(map->get(x,y1)-map->get(x,y2)) / spacing;
                    normalizeVec3(n);
                }
                if(normalize)
                {
                    n[0]=n[0]*0.5 + 0.5;
                    n[1]=n[1]*0.5 + 0.5;
                    n[2]=n[2]*0.5 + 0.5;
                }
                bump->set(x,y,SRGBA((float)n[0], (float)n[1], (float)n[2], 1.0));
            }
        }
    }
    SRGBA CRGBABlend::get(ANLFloatType x, ANLFloatType y, ANLFloatType z, ANLFloatType w, ANLFloatType u, ANLFloatType v)
    {
        SRGBA low=m_low.get(x,y,z,w,u,v);
        SRGBA high=m_high.get(x,y,z,w,u,v);
        ANLFloatType control=m_control.get(x,y,z,w,u,v);

        return SRGBA(
            (float)(low[0]+control*(high[0]-low[0])),
            (float)(low[1]+control*(high[1]-low[1])),
            (float)(low[2]+control*(high[2]-low[2])),
            (float)(low[3]+control*(high[3]-low[3])));
    }
 SRGBA CRGBACompositeChannels::get(double x, double y, double z, double w)
 {
     float r=(float)m_c1.get(x,y,z,w);
     float g=(float)m_c2.get(x,y,z,w);
     float b=(float)m_c3.get(x,y,z,w);
     float a=(float)m_c4.get(x,y,z,w);
     if(m_mode==RGB) return SRGBA(r,g,b,a);
     else
     {
         SRGBA hsv(r,g,b,a);
         SRGBA rgb;
         HSVtoRGBA(hsv,rgb);
         return rgb;
     }
 }
    void CRGBABufferImplicitBufferAdapter::get(CArray2Drgba &out)
    {
        if(!m_source) return;
        CArray2Dd tmp;
        tmp.resize(out.width(), out.height());
        m_source->get(tmp);

        for(int x=0; x<out.width(); ++x)
        {
            for(int y=0; y<out.height(); ++y)
            {
                ANLFloatType v=tmp.get(x,y);
                out.set(x,y,SRGBA(v,v,v,1));
            }
        }
    }
    void multRGBAByDouble(CArray2Drgba *rgba, CArray2Dd *map)
    {
        if(!rgba || !map) return;

        int mw=rgba->width(), mh=rgba->height();
        if(mw!=map->width() || mh!=map->height()) return;

        for(int x=0; x<mw; ++x)
        {
            for(int y=0; y<mh; ++y)
            {
                double v=map->get(x,y);
                SRGBA c=rgba->get(x,y);
                rgba->set(x,y,SRGBA(c[0]*v, c[1]*v, c[2]*v, c[3]));
            }
        }
    }
    SRGBA CRGBARotateColor::get(ANLFloatType x, ANLFloatType y, ANLFloatType z, ANLFloatType w, ANLFloatType u, ANLFloatType v)
    {
        SRGBA s=m_source.get(x,y,z,w,u,v);
        calculateRotMatrix(x,y,z,w,u,v);

        s[0]=s[0]*2.0f-1.0f;
        s[1]=s[1]*2.0f-1.0f;
        s[2]=s[2]*2.0f-1.0f;


        s=SRGBA(
            (float)((m_rotmatrix[0][0]*s[0]) + (m_rotmatrix[1][0]*s[1]) + (m_rotmatrix[2][0]*s[2])),
            (float)((m_rotmatrix[0][1]*s[0]) + (m_rotmatrix[1][1]*s[1]) + (m_rotmatrix[2][1]*s[2])),
            (float)((m_rotmatrix[0][2]*s[0]) + (m_rotmatrix[1][2]*s[1]) + (m_rotmatrix[2][2]*s[2])),
            s[3]);

        s[0]=(float)clamp(s[0]*0.5+0.5,0.0,1.0);
        s[1]=(float)clamp(s[1]*0.5+0.5,0.0,1.0);
        s[2]=(float)clamp(s[2]*0.5+0.5,0.0,1.0);

        return s;
    }
Example #13
0
    SRGBA CRGBASelect::get(double x, double y, double z)
    {
        SRGBA s1=m_low.get(x,y,z);
        SRGBA s2=m_high.get(x,y,z);
        double control=m_control.get(x,y,z);
        double threshold=m_threshold.get(x,y,z);
        double falloff=m_falloff.get(x,y,z);

        if(falloff>0.0)
        {
            if(control<threshold-falloff)
            {
                return s1;
            }
            else if(control>threshold+falloff)
            {
                return s2;
            }
            else
            {
                double lower=threshold-falloff;
                double upper=threshold+falloff;
                double t=quintic_blend((control-lower)/(upper-lower));
                return SRGBA(
                    (float)(s1[0]+t*(s2[0]-s1[0])),
                    (float)(s1[1]+t*(s2[1]-s1[1])),
                    (float)(s1[2]+t*(s2[2]-s1[2])),
                    (float)(s1[3]+t*(s2[3]-s1[3])));
            }
        }
        else
        {
            if(control<threshold) return s1;
            else return s2;
        }
    }
 void CRGBACurve::pushPoint(double t,float r, float g, float b, float a)
 {
     m_curve.pushPoint(t,SRGBA(r,g,b,a));
 }
Example #15
0
void CEffectsGame::DoPicking()
{
	bool hit = false;
	Vector3 tileHitPos;
	SMapTile *tileHit;
	Vector3 start = pCamera->GetWorldPosition();
	Vector3 end = start + pCamera->forward * 1000.0f;
	Vector3 pos;

	pLevel->UnHighlightTile();

	// find tile we are pointing at
	if (hit = pLevel->CastRay(start, end, OUT tileHitPos, OUT &tileHit, OUT &pos))
	{
		pLevel->HighlightTile(tileHitPos.x, tileHitPos.y, tileHitPos.z);		
	}

	static float force = 10;
	if (gInput.WasKeyPressed(K_PGUP)) force += 5.0f;
	if (gInput.WasKeyPressed(K_PGDN)) force -= 5.0f;
	//gVGUI.AddTextMessage(300,200,WHITE,"Force: %f",force);

	//car->pBarrel->DrawAxis();

	// shooting - delete tile
	if (gInput.IsKeydown(K_MOUSE1))
	{
		static float delay = 0;
		delay += frametime;
		if (delay > 0.05f)
		{
			
			// shoot a bullet
			CreateBullet(car->pBarrel->GetWorldPosition(), car->pBarrel->up);

			float puffSpeed = 0.35;

			// add puff effect
			for (int i = 0; i<3; i++)
			{					
				static CTexture *puffTex = new CTexture("particles/explosion4.dds");
				CParticle *p = new CParticle(puffTex);
				p->size = Vector2(0.15, 0.15);
				p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2;
				p->velocity = Vector3( frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed)+1, frand(-puffSpeed,puffSpeed) );
				//p->gravity = -10;
				p->lifetime = 0.25;
				p->color = SRGBA(255,255,255,50);
				p->sizeVel = Vector2(1,1);
				p->colorChange = SRGBA(255,255,255,0);
				particles->Add(p);
			}

			// add muzzle flash
			static CTexture *muzzleTex[] = {
				new CTexture("particles/flame1.dds"),
				new CTexture("particles/explosion1.dds")				
			};
		
			{
				CParticle *p = new CParticle(muzzleTex[rand()%2]);
				p->size = Vector2(0.7, 0.7);
				p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2;								
				p->lifetime = 0.01;
				p->additive = true;
				//p->color = SRGBA(255,255,255,50);
				//p->sizeVel = Vector2(1,1);
				//p->colorChange = SRGBA(255,255,255,0);
				particles->Add(p);
			}

			
			delay = 0;

			// if hit a tile, destroy it
	/*		if (hit)
			{
				EnterCriticalSection(&renderCS);
				tileHit->type = 0;
				LeaveCriticalSection(&renderCS);

				SMapChunk *chunk = pLevel->GetChunk(
					floor(tileHitPos.x/SMapChunk::Size),
					floor(tileHitPos.y/SMapChunk::Size),
					floor(tileHitPos.z/SMapChunk::Size) );

				chunk->dirtyBody = true;
				chunk->dirty = true;

				//pLevel->UpdateTile(tileHitPos.x, tileHitPos.y, tileHitPos.z);

				SSpawnTile s;
				s.pos = tileHitPos;
				s.vel = pCamera->forward * force;
				boxesToSpawn.push(s);
			
				// create a physical entity in this place
				/*NewtonBody *box = AddBox(pScene, pWorld, tileHitPos+Vector3(0.5, 0.5, 0.5), Vector3(0.95f,0.95f,0.95f), Vector3(), 100);

				// add some velocity
				Vector3 vel = pCamera->forward * force;
				Vector3 pos;
				NewtonBodySetVelocity(box, &vel[0]);*/				
		//	}
		}
	}

	static float lastRocketFire = -100;

	if (gInput.WasKeyPressed(K_MOUSE2) )
	{
		float r = 3;
		int x = tileHitPos.x;
		int y = tileHitPos.y;
		int z = tileHitPos.z;

		if (lastRocketFire + 0 < realtime)
		{
			Debug("Create rocket!");
			lastRocketFire = realtime;

			if (!hit)
			{
				CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, car->pBarrel->up);
			}
			else
			{
				Vector3 dir = (p os-(car->pBarrel->GetWorldPosition() + Vector3(0,10,0))).Normalize();
				if (dir.y < -0.25) 
				{
					dir.y = -0.25;
					dir.Normalize();
				}
				CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, dir );
			}
			
		}
	
	}


	// show car meshes
	if (car)
	{
		CArray<CObject3D*> meshes;
		GetMeshesList(car, meshes);

		float minT = 99999.0f;

		static int current = 0;
		if (KeyPressed(']')) { meshes[current]->color = WHITE; current++; if (current == meshes.Size()) current = 0; meshes[current]->color = RED;  }
		if (KeyPressed('[')) { meshes[current]->color = WHITE; current--; if (current < 0) current = meshes.Size()-1; meshes[current]->color = RED; }
		//gVGUI.AddTextMessage(200,90,YELLOW,"%d",current);

		car->aimTarget = end;
	}
}
Example #16
0
void CEffectsGame::UpdateBullets( float frametime )
{
	for (int i=0; i<MAX_BULLETS; i++) 
	{
		if (bullets[i] == NULL) continue;;

		CSprite3D *bullet = bullets[i];

		Vector3 move = bullet->velocity * frametime;
		Vector3 start = bullet->GetPosition();
		bullet->Move(move.x, move.y, move.z);
		bullet->velocity.y -= frametime * cv_bulletGravity.GetFloat();

		bullet->lockedAxis = bullet->velocity;
		bullet->lockedAxis.Normalize();

		Vector3 v = bullet->velocity;
		v.Normalize();
		gRenderer.AddLine(bullet->GetPosition(), bullet->GetPosition() + v, SRGBA(255,230,180,180));


		if (bullet->GetWorldPosition().y < 0) 
		{
			RemoveBullet(i);
		}

		SMapTile *tileHit;
		Vector3 tileHitPos;
		Vector3 pos;
		bool hit = false;
		if (hit = pLevel->CastRay(start, bullet->GetPosition(), OUT tileHitPos, OUT &tileHit, OUT &pos))
		{			
				EnterCriticalSection(&renderCS);
				tileHit->type = 0;
				LeaveCriticalSection(&renderCS);

				// remove tile from the level and mark for update
				SMapChunk *chunk = pLevel->GetChunk(
					floor(tileHitPos.x/SMapChunk::Size),
					floor(tileHitPos.y/SMapChunk::Size),
					floor(tileHitPos.z/SMapChunk::Size) );

				chunk->dirtyBody = true;
				chunk->dirty = true;
				
				// add a box to spawn list
				SSpawnTile s;
				s.pos = tileHitPos;
				s.vel = v * cv_bulletforce.GetFloat();
				boxesToSpawn.push(s);			
				
				// remove bullet
				RemoveBullet(i);

				float puffSpeed = 0.5;

				// add puff effect
				for (int i = 0; i<6; i++)
				{					
					static CTexture *puffTex = new CTexture("particles/explosion4.dds");
					CParticle *p = new CParticle(puffTex);
					p->size = Vector2(1.35, 1.35);
					p->position = pos;
					p->velocity = Vector3( frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed) );
					p->lifetime = 1;
					//p->color = SRGBA(155,155,155,255);
					p->color = SRGB(clamp(pos.x*255.0f/32.0f,0,255)*0.9f, clamp(pos.y*255.0f/32.0f,0,255)*0.9f, clamp(pos.z*255.0f/32.0f,0,255)*0.9f);
					p->colorChange = p->color;// SRGBA(255,255,255,0);
					p->colorChange.a = 0;
					p->colorTime = 1;
					p->sizeVel = Vector2(0.85,0.85);
					particles->Add(p);
				}
		}		
	
	}

	//PrintText("Bullets: %d", bulletsNum);
}
Example #17
0
void CEffectsGame::CreateScene()
{
	pScene->CreateSkybox("clear");

	NewtonBody *bFloor = AddBox(pScene, pWorld, Vector3(0,-0.5,0), Vector3(1000,1,1000), Vector3());	
	NewtonCollision *col = NewtonCreateTreeCollision(pWorld, 0);
	NewtonTreeCollisionBeginBuild(col);
	Vector3 v[4] = {
		Vector3(-1000,0.5f,-1000),
		Vector3(-1000,0.5f,+1000),
		Vector3(+1000,0.5f,+1000),
		Vector3(+1000,0.5f,-1000)
	};
	NewtonTreeCollisionAddFace(col, 4, &v[0][0], sizeof(Vector3), 1);
	NewtonTreeCollisionEndBuild(col, 0);

	



	NewtonBodySetCollision(bFloor, col);

	CObject3D *f = (CObject3D*)NewtonBodyGetUserData(bFloor);
	f->visible = false;

	NewtonBodySetMaterialGroupID(bFloor, gLevelChunksMaterialID);

	// floor
	static CTexture *floorTex = new CTexture("textures/512.png");
	CMaterial *floorMat = new CMaterial();
	floorMat->features = EShaderFeature::LIGHT | EShaderFeature::FOG | EShaderFeature::SHADOW | EShaderFeature::TEXTURE;
	CPlaneGeometry *floorGeom = new CPlaneGeometry(1000,1000);
	CObject3D *floor = new CMesh( floorGeom, floorMat );
	floor->geometry->materials.AddToTail(floorMat);
	floorMat->pTexture = floorTex;
	floorGeom->SetTextureScale(40,40);
	floor->SetPosition(-500, 0, -500);
	pScene->Add(floor);

	

	pLevel = new CLevel(pScene, pWorld);
	pLevel->Create(32,80,32);

	int width = 24;
	int depth = 24;
	int storeys = 8;
	int storyHeight = 8;

	for (int y=0; y<storeys*storyHeight; y++)
		for (int x=0; x<width; x++)
			for (int z=0; z<depth; z++)
			{
				int block = 0;
				if (x==0 || z==0 || x==width-1 || z==depth-1) block = 1;
				if (y%storyHeight == storyHeight-1) block = 1;
				if (x>5 && z>5 && x<width-5 && z<depth-5) block = 0;

				if (y%storyHeight > 2 && y%storyHeight <= 4) 
				{
					if (x%8 >= 2 && x%8 < 7) block = 0;
					if (z%8 >= 2 && z%8 < 7) block = 0;
				}

				if ((x==5 && z==5) || (x==width-5 && z==depth-5) || (x==5 && z==depth-5) || (x==width-5 && z==5) ) block = 4;

				
				if (block > 0)	block = 4;
				pLevel->GetTile(x,y,z)->type = block;
			}

	int sx = 55;
	int sz = 55;
	



	pLevel->Recreate();

	for (int x=0; x<pLevel->chunksX; x++)
		for (int y=0; y<pLevel->chunksY; y++)
			for (int z=0; z<pLevel->chunksZ; z++)
			{
				pLevel->GetChunk(x,y,z)->RecreateCollision();
			}	

	// once the map has been created, creatie bodies that will collide
	/*for (int x=0; x<pLevel->sizeX; x++)
		for (int y=0; y<pLevel->sizeY; y++)
			for (int z=0; z<pLevel->sizeZ; z++)
			{
				if (pLevel->GetTile(x,y,z)->type == 0) continue;

				CObject3D *o = new CObject3D();
				o->SetPosition(Vector3(x+0.5, y+0.5, z+0.5));
				
				NewtonBody *box = CPhysics::CreateBox(pWorld, o, 1,1,1, 0);
				NewtonBodySetFreezeState(box, 1);

				delete o;
			}*/

	// let's create a collision tree for each chunk
/*	for (int x=0; x<pLevel->chunksX; x++)
		for (int y=0; y<pLevel->chunksY; y++)
			for (int z=0; z<pLevel->chunksZ; z++)
			{
				NewtonCollision * col = NewtonCreateTreeCollision(pWorld, 0);
				NewtonTreeCollisionBeginBuild(col);

				CArray<Vector3> &verts = pLevel->GetChunk(x,y,z)->pMesh->geometry->vertices;
				for (int i=0; i<pLevel->GetChunk(x,y,z)->pMesh->geometry->faces.Size(); i++)
				{
					Face3 face = pLevel->GetChunk(x,y,z)->pMesh->geometry->faces[i];
					Vector3 v[] = { verts[face.a], verts[face.b], verts[face.c] };
					NewtonTreeCollisionAddFace(col, 3, &v[0][0], sizeof(Vector3), 1);
				}
				NewtonTreeCollisionEndBuild(col, 1);

				// create body
				float m[16] = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
				NewtonBody *body = NewtonCreateBody(pWorld, col, &m[0]);
				NewtonReleaseCollision(pWorld, col);
				NewtonBody
			}
*/
	/*
	CreateBuilding(0,0,0, 3,8,3);
	CreateBuilding(20,0,-10, 2,4,6);
	CreateBuilding(-5,0,-20, 5,2,3);
	*/

	// point light that will circle the building
	pLight = new CPointLight(Vector3(), SRGBA(255,200,50));
	pLight->range = 8.0f;
	pLight->overbright = true;
	pScene->Add(pLight);

	pScene->fog = new SFog( SRGBA(172,201,241, 255), 200, 500);

	// point light at 0,1,0
	CLight *pLight = new CPointLight(Vector3(0,1,0), RED);//SRGBA(255,233,155,255));
	//pScene->Add( pLight );
	pLight->specular = pLight->color;//SRGBA(255,255,255,100);
	pLight->range = 1;
	pLight->intensity = 1;	

	// directional Sun light
	CDirectionalLight *pDirLight = new CDirectionalLight(Vector3(0,0,0), SRGBA(255,225,175,255));
	pDirLight->SetPosition(+70,90,-70);
	pDirLight->LookAt(Vector3());
	pDirLight->UpdateMatrixWorld(true);
	pDirLight->shadowNear = 20;
	pDirLight->shadowFar = 200;
	pDirLight->castShadow = true;
	float aspect = (float)gEngine.width / gEngine.height;
	pDirLight->width = 200.0f;
	pDirLight->height = pDirLight->width / aspect;
	pScene->Add( pDirLight );
	
	// ambient light
	pScene->ambientColor = SRGBA(200,200,255,255);

	pCamera->LookAt(Vector3());
}
 void CRGBACurve::pushPoint(ANLFloatType t,float r, float g, float b, float a)
 {
     m_curve.pushPoint(t,SRGBA(r,g,b,a));
 }
Example #19
0
void CRocket::Update( float frametime )
{
	Vector3 pos = this->GetPosition();			// start position

	CEntity::Update(frametime);
	
	Vector3 end = this->GetPosition();

	if (followTarget)
	{
		this->LookAt(pTarget->GetWorldPosition());
		this->acceleration = forward * 5.0f;
		this->acceleration.y -= 1;
	}
	
	
	// engine
	static CTexture *muzzleTex = CTexture::Get("particles/flamer.dds");
	static CTexture *smokeTex = CTexture::Get("particles/explosion2.dds");
	
	// create particle effect for the engine flame
	{
		CParticle *p = new CParticle(muzzleTex);
		p->size = Vector2(0.7, 0.7);
		p->position = pos + forward*(-0.6);								
		p->lifetime = 0.01;

		float s = frand(1, 1.3);
		p->size = Vector2(s,s);
		p->rotation = frand(0,90);
		p->depthWrite = false;

		p->additive = true;
		//p->color = SRGBA(255,255,255,50);
		//p->sizeVel = Vector2(1,1);
		//p->colorChange = SRGBA(255,255,255,0);
		pGame->particles->Add(p);
	}

	static float smokeAcc = 0;

	// create smoke trail particles
	smokeAcc += frametime;
	if (smokeAcc > 0.02 )
	{
		CParticle *p = new CParticle(smokeTex);
		p->size = Vector2(0.35, 0.35);
		p->position = this->GetWorldPosition() + forward*(-0.7);			
		//p->velocity = -this->velocity * 2;
		p->lifetime = 5;

		//float s = frand(1, 1.3);
		//p->size = Vector2(s,s);
		p->rotation = frand(0,90);
		p->depthWrite = false;

		//p->additive = true;
		p->color = SRGBA(255,255,255,100);
		p->sizeVel = Vector2(0.65,0.65);		
		p->colorChange = SRGBA(0,0,0,0);
		p->colorTime = 5;

		pGame->particles->Add(p);

		smokeAcc = 0;		
	}

	// check if rocket is leaving the world	
	//if (pos.x < -bounds || pos.x > bounds || pos.y < 0 || pos.y > bounds || pos.z < -bounds || pos.z > bounds )
	if ((position - pGame->pCamera->GetWorldPosition()).Length() > 500)
	{
		this->deleteMe = true;
		this->Remove(light);
	}

	// check collision of the rocket with the world	
	SRayCastResult rc;
	if (pGame->CastRay(pos, end, RC_VOXEL | RC_TERRAIN | RC_OBJECTS, OUT rc))
	{
		if (!(rc.type == RC_OBJECTS && rc.object == (CObject3D*)((CTestGame*)pGame)->pCar)) 
		{
			if (!(rc.type == RC_OBJECTS && rc.object->GetType() == "Rocket"))
			{
				Explode();
				deleteMe = true;

				if (rc.type == RC_VOXEL)
					((CTestGame*)pGame)->ExplodeTiles(rc.tilePos, 1.8f);

				if (rc.type == RC_OBJECTS)
					rc.object->hp -= 75;
			}
		}		
	}
}
Example #20
0
void CRocket::Explode()
{
	Vector3 pos = GetPosition();
	int x = pos.x;
	int y = pos.y;
	int z = pos.z;

	int r = 3;

	this->Remove(light);

	CArray<CEntity*> enemies; 
	pGame->FindEntitiesByTypeInRange("Enemy", GetWorldPosition(), 5, OUT enemies);
	for (int i=0; i<enemies.Size(); i++)
		enemies[i]->hp -= 80;
	
	// destroy tiles in the area
	/*for (int ix = x, xsign = 1, xstep = 1; 
		(ix >= x - r) && (ix <= x + r);
		ix += xsign * xstep, xsign = -xsign, xstep++)
		for (int iy = y, ysign = 1, ystep = 1; 
			(iy >= y - r) && (iy <= y + r);
			iy += ysign * ystep, ysign = -ysign, ystep++)
			for (int iz = z, zsign = 1, zstep = 1; 
				(iz >= z - r) && (iz <= z + r);
				iz += zsign * zstep, zsign = -zsign, zstep++)
			{
				SMapTile *tile = NULL;
				if ((tile = pLevel->GetTile(ix,iy,iz)) == NULL) continue;

				if (tile->type == 0) continue;

				tile->type = 0;

				SMapChunk *chunk = pLevel->GetChunk(
					floor((float)ix/SMapChunk::Size),
					floor((float)iy/SMapChunk::Size),
					floor((float)iz/SMapChunk::Size) );

				chunk->dirtyBody = true;
				chunk->dirty = true;

				SSpawnTile s;
				s.pos = Vector3(ix,iy,iz);
				s.vel = (Vector3(ix+frand(-0.25f,+0.25),iy+frand(-0.25f,+0.25),iz+frand(-0.25f,+0.25)) - pos).Normalize() * cv_explosionout.GetFloat() + (-forward)*cv_explosionforce.GetFloat();
				

				//CEffectsGame::pInstance->SpawnTile(s);

				
			}
	*/		

	// add particle effect
	static CTexture *expTex = CTexture::Get("particles/flamer.dds");

	CParticle *p = new CParticle(expTex);
	p->position = pos;
	p->size = Vector2(10,10);
	p->sizeVel = Vector2(15,15);
	p->rotationVel = 90;
	p->colorChange = SRGBA(255,255,255,100);
	p->colorTime = 10;
	p->lifetime = 5;
	p->additive = true;
	p->depthWrite = false;
	pGame->particles->Add(p);

	p = new CParticle(expTex);
	p->position = pos;
	p->size = Vector2(8,8);
	p->sizeVel = Vector2(10,10);
	p->rotationVel = 90;
	p->colorChange = SRGBA(22,22,22,100);
	p->colorTime = 5;
	p->lifetime = 5;
	p->additive = true;
	p->depthWrite = false;
	pGame->particles->Add(p);
}