Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CEnvHypercube : public CBaseEntity {
- DECLARE_CLASS( CEnvHypercube, CBaseEntity );
- public:
- DECLARE_DATADESC();
- virtual void Precache();
- virtual void Spawn();
- void UpdateSprites();
- void InputAlpha( inputdata_t &inputdata );
- void InputColor( inputdata_t &inputdata );
- private:
- void doEdge(int& index,
- int ax, int ay, int az, int aw,
- int bx, int by, int bz, int bw);
- EHANDLE m_hSprites[2][2][2][2];
- EHANDLE m_hBeams[32];
- };
- BEGIN_DATADESC( CEnvHypercube )
- DEFINE_THINKFUNC( UpdateSprites ),
- DEFINE_ARRAY( m_hSprites, FIELD_EHANDLE, 16 ),
- DEFINE_ARRAY( m_hBeams, FIELD_EHANDLE, 32 ),
- DEFINE_INPUTFUNC( FIELD_INTEGER, "Alpha", InputAlpha ),
- DEFINE_INPUTFUNC( FIELD_COLOR32, "Color", InputColor ),
- END_DATADESC()
- LINK_ENTITY_TO_CLASS( env_hypercube, CEnvHypercube );
- // PASS COLOR TO SPRITES AND BEAMS
- void CEnvHypercube::InputColor( inputdata_t &inputdata ) {
- for (int x = 0 ; x < 2 ; x++)
- for (int y = 0 ; y < 2 ; y++)
- for (int z = 0 ; z < 2 ; z++)
- for (int w = 0 ; w < 2 ; w++) {
- CSprite* sprite = (CSprite*) m_hSprites[x][y][z][w].Get();
- if (!sprite) continue;
- sprite->InputColor(inputdata);
- }
- for (int i = 0 ; i < 32 ; i++) {
- CBeam* beam = (CBeam*) m_hBeams[i].Get();
- if (!beam) continue;
- beam->InputColor(inputdata);
- }
- }
- // PASS ALPHA TO SPRITES AND BEAMS
- void CEnvHypercube::InputAlpha( inputdata_t &inputdata ) {
- for (int x = 0 ; x < 2 ; x++)
- for (int y = 0 ; y < 2 ; y++)
- for (int z = 0 ; z < 2 ; z++)
- for (int w = 0 ; w < 2 ; w++) {
- CSprite* sprite = (CSprite*) m_hSprites[x][y][z][w].Get();
- if (!sprite) continue;
- sprite->InputAlpha(inputdata);
- }
- for (int i = 0 ; i < 32 ; i++) {
- CBeam* beam = (CBeam*) m_hBeams[i].Get();
- if (!beam) continue;
- beam->InputAlpha(inputdata);
- }
- }
- // HELPER FUNCTION TO SPAWN EDGE
- void CEnvHypercube::doEdge(int& index,
- int ax, int ay, int az, int aw,
- int bx, int by, int bz, int bw) {
- CBaseEntity* a = m_hSprites[ax][ay][az][aw];
- CBaseEntity* b = m_hSprites[bx][by][bz][bw];
- CBeam* beam = CBeam::BeamCreate( "sprites/grenade/grenade_laser.vmt", 16.0f );
- beam->PointEntInit( a->GetAbsOrigin(), b );
- beam->SetWidth( 16.0f );
- beam->SetEndWidth( 16.0f );
- beam->SetRenderMode( kRenderTransAdd );
- beam->SetRenderColor(255, 200, 255, 255);
- beam->SetStartEntity(a);
- beam->SetEndEntity(b);
- beam->SetNoise(0.0f);
- beam->Spawn();
- m_hBeams[index++] = beam;
- }
- // SPAWN
- void CEnvHypercube::Spawn() {
- BaseClass::Spawn();
- Precache();
- // create the vertices
- for (int x = 0 ; x < 2 ; x++)
- for (int y = 0 ; y < 2 ; y++)
- for (int z = 0 ; z < 2 ; z++)
- for (int w = 0 ; w < 2 ; w++) {
- CSprite* sprite = CSprite::SpriteCreate( "sprites/grenade/grenade_glow.vmt", GetAbsOrigin(), true );
- sprite->SetScale( 2.0f );
- sprite->SetRenderMode( kRenderTransAdd );
- sprite->SetRenderColor(255, 200, 255, 255);
- sprite->Spawn();
- m_hSprites[x][y][z][w] = sprite;
- }
- int i = 0;
- // line
- doEdge(i, 0, 0, 0, 0, 1, 0, 0, 0);
- // square
- doEdge(i, 0, 1, 0, 0, 1, 1, 0, 0);
- doEdge(i, 0, 0, 0, 0, 0, 1, 0, 0);
- doEdge(i, 1, 0, 0, 0, 1, 1, 0, 0);
- // cube
- doEdge(i, 0, 0, 1, 0, 1, 0, 1, 0);
- doEdge(i, 0, 1, 1, 0, 1, 1, 1, 0);
- doEdge(i, 0, 0, 1, 0, 0, 1, 1, 0);
- doEdge(i, 1, 0, 1, 0, 1, 1, 1, 0);
- doEdge(i, 0, 0, 0, 0, 0, 0, 1, 0);
- doEdge(i, 0, 1, 0, 0, 0, 1, 1, 0);
- doEdge(i, 1, 0, 0, 0, 1, 0, 1, 0);
- doEdge(i, 1, 1, 0, 0, 1, 1, 1, 0);
- // hypercube
- doEdge(i, 0, 0, 0, 1, 1, 0, 0, 1);
- doEdge(i, 0, 1, 0, 1, 1, 1, 0, 1);
- doEdge(i, 0, 0, 0, 1, 0, 1, 0, 1);
- doEdge(i, 1, 0, 0, 1, 1, 1, 0, 1);
- doEdge(i, 0, 0, 1, 1, 1, 0, 1, 1);
- doEdge(i, 0, 1, 1, 1, 1, 1, 1, 1);
- doEdge(i, 0, 0, 1, 1, 0, 1, 1, 1);
- doEdge(i, 1, 0, 1, 1, 1, 1, 1, 1);
- doEdge(i, 0, 0, 0, 1, 0, 0, 1, 1);
- doEdge(i, 0, 1, 0, 1, 0, 1, 1, 1);
- doEdge(i, 1, 0, 0, 1, 1, 0, 1, 1);
- doEdge(i, 1, 1, 0, 1, 1, 1, 1, 1);
- doEdge(i, 0, 0, 0, 0, 0, 0, 0, 1);
- doEdge(i, 0, 0, 1, 0, 0, 0, 1, 1);
- doEdge(i, 0, 1, 0, 0, 0, 1, 0, 1);
- doEdge(i, 0, 1, 1, 0, 0, 1, 1, 1);
- doEdge(i, 1, 0, 0, 0, 1, 0, 0, 1);
- doEdge(i, 1, 0, 1, 0, 1, 0, 1, 1);
- doEdge(i, 1, 1, 0, 0, 1, 1, 0, 1);
- doEdge(i, 1, 1, 1, 0, 1, 1, 1, 1);
- // start rotating right away
- SetThink( &CEnvHypercube::UpdateSprites );
- SetNextThink( gpGlobals->curtime + 0.05f );
- }
- // PRECACHE
- void CEnvHypercube::Precache() {
- BaseClass::Precache();
- PrecacheModel( "sprites/grenade/grenade_glow.vmt" );
- PrecacheModel( "sprites/grenade/grenade_laser.vmt" );
- }
- // UPDTATE SPRITES POSITIONS
- void CEnvHypercube::UpdateSprites() {
- // update right after
- SetNextThink( gpGlobals->curtime + 0.05f );
- // rotate in 4D
- float ro = gpGlobals->curtime*-0.5f;
- float cro = cosf(ro);
- float sro = sinf(ro);
- Vector forward, right, up;
- GetVectors( &forward, &right, &up );
- // update vertices
- for (int x = 0 ; x < 2 ; x++)
- for (int y = 0 ; y < 2 ; y++)
- for (int z = 0 ; z < 2 ; z++)
- for (int w = 0 ; w < 2 ; w++) {
- CSprite* sprite = (CSprite*) m_hSprites[x][y][z][w].Get();
- if (!sprite) continue;
- // find out 4D position
- Vector pos3D = Vector(x - 0.5f, y - 0.5f, z - 0.5f)*2.0f;
- float posW = (w - 0.5f)*2.0f;
- // rotate
- float temp = pos3D.x * cro - posW * sro;
- posW = pos3D.x * sro + posW * cro;
- pos3D.x = temp;
- // project to 3D space
- pos3D = 2.0*pos3D/(3.0+posW) * 750.0f;
- sprite->SetAbsOrigin(GetAbsOrigin() + forward*pos3D.x + right*pos3D.y + up*pos3D.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement