Exemplo n.º 1
0
void animate(void){
 int i;
 for(i=object_count-1;i>=0;i--){
  x_put_pbm(objects[i].XOtherPage,objects[i].YOtherPage,
	 HiddenPageOffs,objects[i].bgOtherPage);
 }
 for(i=0;i<object_count;i++){
  MoveObject(&objects[i]);

  x_get_pbm(objects[i].X,objects[i].Y,
	(unsigned)objects[i].Width,objects[i].Height,HiddenPageOffs,
	objects[i].bg);
  x_put_masked_pbm(objects[i].X,objects[i].Y,HiddenPageOffs,
	objects[i].Image);
 }
}
//----------------------------------------------------------------------------
void FreeFormDeformation::OnIdle ()
{
    MeasureTime();

    bool needsCulling = false;
    if (MoveCamera())
    {
        needsCulling = true;
    }

    if (MoveObject())
    {
        mScene->Update();
        needsCulling = true;
        mCuller.ComputeVisibleSet(mScene);
    }

    if (mDoRandom)
    {
        // Deform the mesh no faster than 30 frames per second.
        float time = (float)GetTimeInSeconds();
        if (time - mLastUpdateTime >= 0.0333333f)
        {
            mLastUpdateTime = time;
            DoRandomControlPoints();
            mScene->Update();
            needsCulling = true;
        }
    }

    if (needsCulling)
    {
        mCuller.ComputeVisibleSet(mScene);
    }

    // Draw the scene as fast as possible (not limited to 30 fps).
    if (mRenderer->PreDraw())
    {
        mRenderer->ClearBuffers();
        mRenderer->Draw(mCuller.GetVisibleSet());
        DrawFrameRate(8, GetHeight()-8, mTextColor);
        mRenderer->PostDraw();
        mRenderer->DisplayColorBuffer();
    }

    UpdateFrameCount();
}
Exemplo n.º 3
0
//----------------------------------------------------------------------------
void ScreenPolygons::OnIdle ()
{
	MeasureTime();

	if (MoveCamera())
	{
		mCuller.ComputeVisibleSet(mScene);
	}

	if (MoveObject())
	{
		mScene->Update();
		mCuller.ComputeVisibleSet(mScene);
	}

	mRenderer->ClearDepthBuffer();
	mRenderer->ClearColorBuffer();
	if (mRenderer->PreDraw())
	{
		// Draw the background and middle polygons.
		mRenderer->SetCamera(mScreenCamera);
		mRenderer->Draw(mBackPoly);
		mRenderer->Draw(mMidPoly);

		// Draw the biped.
		mRenderer->SetCamera(mCamera);
		mRenderer->Draw(mCuller.GetVisibleSet());

		// Draw the foreground polygon last since it has transparency.
		mRenderer->SetCamera(mScreenCamera);
		mRenderer->Draw(mForePoly);

		// Text goes on top of foreground polygon.
		mRenderer->SetCamera(mCamera);
		DrawFrameRate(8, GetHeight()-8, mTextColor);

		char message[128];
		sprintf(message, "linear z = %f , perspective z = %f", mLinearZ,
		        mDepthZ);
		mRenderer->Draw(8, 16, mTextColor, message);

		mRenderer->PostDraw();
		mRenderer->DisplayColorBuffer();
	}

	UpdateFrameCount();
}
Exemplo n.º 4
0
//----------------------------------------------------------------------------
void SimplePendulumFriction::OnIdle ()
{
	MeasureTime();

	MoveCamera();
	if (MoveObject())
	{
		mScene->Update();
	}

#ifndef SINGLE_STEP
	PhysicsTick();
#endif
	GraphicsTick();

	UpdateFrameCount();
}
Exemplo n.º 5
0
//----------------------------------------------------------------------------
void RoughPlaneSolidBox::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
    }

#ifndef SINGLE_STEP
    PhysicsTick();
#endif
    GraphicsTick();

    UpdateFrameCount();
}
//----------------------------------------------------------------------------
void IntersectingBoxes::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
    }

#ifndef SINGLE_STEP
    PhysicsTick();
#endif

    GraphicsTick();

    UpdateFrameCount();
}
Exemplo n.º 7
0
void E_Tortoise_Fly::Update(float gameTime)
{
    if (timelife > 0)
        timelife++;
    if (timelife == 150) {
        timelife = 0;
        status = 0;
        m_hSpeed.x = vx;
    }
    Object::Update(gameTime);
    if (IsControl)
        SetControl();
    else
        MoveObject();
    Collision_Shell_Object();
    CollistionWithObject();
    SetSprite();
    DelayNext(3);
}
Exemplo n.º 8
0
//----------------------------------------------------------------------------
void VolumeFog::OnIdle ()
{
    MeasureTime();

    bool fogNeedsUpdate = false;
    if (MoveCamera())
    {
        mCuller.ComputeVisibleSet(mScene);
        fogNeedsUpdate = true;
    }

    if (MoveObject())
    {
        mScene->Update();
        mCuller.ComputeVisibleSet(mScene);
        fogNeedsUpdate = true;
    }

    if (fogNeedsUpdate)
    {
        UpdateFog();
    }

    if (mRenderer->PreDraw())
    {
        mRenderer->ClearDepthBuffer();

        // Draw fogged terrain.
        mRenderer->SetCamera(mCamera);
        mRenderer->Draw(mCuller.GetVisibleSet());

        // Draw background image.
        mRenderer->SetCamera(mScreenCamera);
        mRenderer->Draw(mScreenPolygon);

        DrawFrameRate(8, GetHeight()-8, mTextColor);

        mRenderer->PostDraw();
        mRenderer->DisplayColorBuffer();
    }

    UpdateFrameCount();
}
Exemplo n.º 9
0
//----------------------------------------------------------------------------
void Polylines::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if ( MoveObject() )
        m_spkScene->UpdateGS(0.0f);

    ms_spkRenderer->ClearBuffers();
    if ( ms_spkRenderer->BeginScene() )
    {
        ms_spkRenderer->Draw(m_spkScene);
        DrawFrameRate(8,GetHeight()-8,ColorRGB::WHITE);
        ms_spkRenderer->EndScene();
    }
    ms_spkRenderer->DisplayBackBuffer();

    UpdateClicks();
}
Exemplo n.º 10
0
//----------------------------------------------------------------------------
void PointInPolyhedron::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    MoveObject();
    mScene->Update(GetTimeInSeconds());
    mCuller.ComputeVisibleSet(mScene);

    if (mRenderer->PreDraw())
    {
        mRenderer->ClearBuffers();
        mRenderer->Draw(mCuller.GetVisibleSet());
        DrawFrameRate(8, GetHeight()-8, mTextColor);
        mRenderer->PostDraw();
        mRenderer->DisplayColorBuffer();
    }

    UpdateFrameCount();
}
Exemplo n.º 11
0
//----------------------------------------------------------------------------
void IntersectInfiniteCylinders::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
    }

    if (mRenderer->PreDraw())
    {
        mRenderer->ClearBuffers();
        mRenderer->Draw(mVisible);
        DrawFrameRate(8, GetHeight()-8, mTextColor);
        mRenderer->PostDraw();
        mRenderer->DisplayColorBuffer();
    }

    UpdateFrameCount();
}
Exemplo n.º 12
0
//----------------------------------------------------------------------------
void Rope::OnIdle ()
{
    MeasureTime();

    MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
    }

    float currIdle = (float)GetTimeInSeconds();
    float diff = currIdle - mLastIdle;
    if (diff >= 0.001f)
    {
        mLastIdle = currIdle;
        PhysicsTick();
        GraphicsTick();
    }

    UpdateFrameCount();
}
Exemplo n.º 13
0
/* ---------------------------------------------------------------------------
 * removes a line point, or a line if the selected point is the end
 */
static void *
RemoveLinePoint (LayerTypePtr Layer, LineTypePtr Line, PointTypePtr Point)
{
  PointType other;
  struct rlp_info info;
  if (&Line->Point1 == Point)
    other = Line->Point2;
  else
    other = Line->Point1;
  info.line = Line;
  info.point = Point;
  if (setjmp (info.env) == 0)
    {
      r_search (Layer->line_tree, (const BoxType *) Point, NULL, remove_point,
		&info);
      return RemoveLine (Layer, Line);
    }
  MoveObject (LINEPOINT_TYPE, Layer, info.line, info.point,
	      other.X - Point->X, other.Y - Point->Y);
  return (RemoveLine (Layer, Line));
}
Exemplo n.º 14
0
//----------------------------------------------------------------------------
void RenderToTexture::OnIdle ()
{
	MeasureTime();

	if (MoveCamera())
	{
		mCuller.ComputeVisibleSet(mScene);
	}

	if (MoveObject())
	{
		mScene->Update();
		mCuller.ComputeVisibleSet(mScene);
	}

	if (mRenderer->PreDraw())
	{
		// Draw the scene to a render target.
		mRenderer->Enable(mRenderTarget);
		mRenderer->SetClearColor(mClearWhite);
		mRenderer->ClearBuffers();
		mRenderer->Draw(mCuller.GetVisibleSet());
		mRenderer->Disable(mRenderTarget);

		// Draw the scene to the main window and also to a regular screen
		// polygon, placed in the lower-left corner of the main window.
		mRenderer->SetClearColor(mClearGray);
		mRenderer->ClearBuffers();
		mRenderer->Draw(mCuller.GetVisibleSet());
		mRenderer->SetCamera(mScreenCamera);
		mRenderer->Draw(mScreenPolygon);

		mRenderer->SetCamera(mCamera);
		DrawFrameRate(8, 16, mTextColor);
		mRenderer->PostDraw();
		mRenderer->DisplayColorBuffer();
	}

	UpdateFrameCount();
}
Exemplo n.º 15
0
//----------------------------------------------------------------------------
void DefaultShader::OnIdle()
{
    MeasureTime();

    // Rotate the box.
    static double dCurTime = 0.0f;
    static double dLastTime = 0.0f;
    dCurTime = SESystem::SE_GetTime();
    if( dCurTime - dLastTime > 0.01f )
    {
        dLastTime = dCurTime;

        SEMatrix3f mat3fRot(SEVector3f::UNIT_Z, -0.01f);
        m_spMesh->Local.SetRotate(m_spMesh->Local.GetRotate()*mat3fRot);
        m_spMesh->UpdateGS();
    }

    if( MoveCamera() )
    {
        m_Culler.ComputeUnculledSet(m_spScene);
    }

    if( MoveObject() )
    {
        m_spScene->UpdateGS();
        m_Culler.ComputeUnculledSet(m_spScene);
    }

    m_pRenderer->ClearBuffers();
    if( m_pRenderer->BeginScene() )
    {
        m_pRenderer->DrawScene(m_Culler.GetVisibleSet());
        DrawFrameRate(8, 20, SEColorRGBA::SE_RGBA_WHITE);
        m_pRenderer->EndScene();
    }
    m_pRenderer->DisplayBackBuffer();

    UpdateFrameCount();
}
Exemplo n.º 16
0
//----------------------------------------------------------------------------
void GelatinCube::OnIdle ()
{
    MeasureTime();

    bool needSort = MoveCamera();
    if (MoveObject())
    {
        mScene->Update();
        needSort = true;
    }
    if (needSort)
    {
        mBox->SortFaces(mCamera->GetDVector());
    }

#ifndef SINGLE_STEP
    PhysicsTick();
#endif

    GraphicsTick();

    UpdateFrameCount();
}
Exemplo n.º 17
0
//----------------------------------------------------------------------------
void Cloth::OnIdle ()
{
    MeasureTime();
    MoveCamera();

    if ( MoveObject() )
        m_spkScene->UpdateGS(0.0f);

#ifndef SINGLE_STEP
    DoPhysical();
#endif

    ms_spkRenderer->ClearBuffers();
    if ( ms_spkRenderer->BeginScene() )
    {
        ms_spkRenderer->Draw(m_spkScene);
        DrawFrameRate(8,GetHeight()-8,ColorRGB::BLACK);
        ms_spkRenderer->EndScene();
    }
    ms_spkRenderer->DisplayBackBuffer();

    UpdateClicks();
}
Exemplo n.º 18
0
//----------------------------------------------------------------------------
void RipplingOcean::OnIdle ()
{
    MeasureTime();
    MoveCamera();

    if ( m_bVertexShader )
    {
        SetupShaders();
    }

    if ( MoveObject() )
        m_spkScene->UpdateGS(0.0f);

    ms_spkRenderer->ClearBuffers();
    if ( ms_spkRenderer->BeginScene() )
    {
        if ( m_bInitialized )
        {
            ms_spkRenderer->Draw(m_spkScene);
            DrawFrameRate(8,GetHeight()-8,ColorRGB::WHITE);
        }
        else
        {
            ms_spkRenderer->Draw(8,32,ColorRGB::WHITE,
                "Load of ripple.{wvs,wps}, sky.mif, watergradient.mif"\
                " or plasa.mif failed.  ");
            ms_spkRenderer->Draw(8,48,ColorRGB::WHITE,
                "Make sure these files are in the same directory as the "
                "executable.");
        }
        ms_spkRenderer->EndScene();
    }
    ms_spkRenderer->DisplayBackBuffer();

    UpdateClicks();
}
Exemplo n.º 19
0
/*
 * AlignText(X, [Lefts/Rights/Centers, [First/Last/Crosshair/Average[, Gridless]]])
 * AlignText(Y, [Tops/Bottoms/Centers, [First/Last/Crosshair/Average[, Gridless]]])
 *
 *	X or Y		- Select which axis will move, other is untouched
 *	Lefts, Rights,
 *	Tops, Bottoms,
 *	Centers         - Pick alignment point within each element.
 *	                  NB: text objects have no Mark
 *	First, Last, 
 *	Crosshair, 
 *	Average		- Alignment reference, First=Topmost/Leftmost,
 *			  Last=Bottommost/Rightmost, Average or Crosshair point
 *	Gridless	- Do not force results to align to prevailing grid
 *
 * Defaults are Lefts/Tops, First
 */
static int
aligntext(int argc, char **argv, Coord x, Coord y)
{
	int dir;
	int point;
	int reference;
	int gridless;
	Coord q;
	Coord p, dp, dx, dy;
	int changed = 0;

	if (argc < 1 || argc > 4) {
		AFAIL(aligntext);
	}

	/* parse direction arg */
	switch ((dir = keyword(ARG(0)))) {
	case K_X:
	case K_Y:
		break;
	default:
		AFAIL(aligntext);
	}

	/* parse point (within each element) which will be aligned */
	switch ((point = keyword(ARG(1)))) {
	case K_Centers:
		break;
	case K_Lefts:
	case K_Rights:
		if (dir == K_Y) {
			AFAIL(aligntext);
		}
		break;
	case K_Tops:
	case K_Bottoms:
		if (dir == K_X) {
			AFAIL(aligntext);
		}
		break;
	case K_none:
		/* default value */
		if (dir == K_X) {
			point = K_Lefts;
		} else {
			point = K_Tops;
		}
		break;
	default:
		AFAIL(aligntext);
	}

	/* parse reference which will determine alignment coordinates */
	switch ((reference = keyword(ARG(2)))) {
	case K_First:
	case K_Last:
	case K_Average:
	case K_Crosshair:
		break;
	case K_none:
		reference = K_First;	/* default value */
		break;
	default:
		AFAIL(aligntext);
	}

	/* optionally work off the grid (solar cells!) */
	switch (keyword(ARG(3))) {
	case K_Gridless:
		gridless = 1;
		break;
	case K_none:
		gridless = 0;
		break;
	default:
		AFAIL(aligntext);
	}

	SaveUndoSerialNumber();

	/* find the final alignment coordinate using the above options */
	q = reference_coord(K_aligntext, Crosshair.X, Crosshair.Y,
				dir, point, reference);

	/* move all selected elements to the new coordinate */

	/* selected text part of an element */
	ELEMENT_LOOP(PCB->Data);
	{
		TextType *text;
		text = &(element)->Name[NAME_INDEX(PCB)];
		if (! TEST_FLAG (SELECTEDFLAG, text))
			continue;
		/* find delta from reference point to reference point */
		p = coord(text, dir, point);
		dp = q - p;
		/* ...but if we're gridful, keep the mark on the grid */
		/* TODO re-enable for text, need textcoord()
		if (! gridless) {
			dp -= (coord(text, dir, K_Marks) + dp)
					% (long) (PCB->Grid);
		}
		*/
		if (dp) {
			/* move from generic to X or Y */
			dx = dy = dp;
			if (dir == K_X)
				dy = 0;
			else
				dx = 0;
			MoveObject(ELEMENTNAME_TYPE, element, text, text, dx, dy);
			changed = 1;
		}
	}
	END_LOOP;

	/* Selected bare text objects */
	ALLTEXT_LOOP (PCB->Data);
	{
	  if (TEST_FLAG (SELECTEDFLAG, text))
	    {
		/* find delta from reference point to reference point */
		p = coord(text, dir, point);
		dp = q - p;
		/* ...but if we're gridful, keep the mark on the grid */
		/* TODO re-enable for text, need textcoord()
		if (! gridless) {
			dp -= (coord(text, dir, K_Marks) + dp)
					% (long) (PCB->Grid);
		}
		*/
		if (dp) {
			/* move from generic to X or Y */
			dx = dy = dp;
			if (dir == K_X)
				dy = 0;
			else
				dx = 0;
			MoveObject(TEXT_TYPE, layer, text, text, dx, dy);
			changed = 1;
		}
	    }
	}
	ENDALL_LOOP;

	if (changed) {
		RestoreUndoSerialNumber();
		IncrementUndoSerialNumber();
		Redraw();
		SetChangedFlag(true);
	}

	free_texts_by_pos();

	return 0;
}
Exemplo n.º 20
0
void CClientMgr::RelocateObject(LTObject *pObject)
{
    MoveObject( pObject, &pObject->GetPos(), LTTRUE );
}
Exemplo n.º 21
0
void World::Wiggle() {
	for( int i=0; i<renObjs.size(); i++ ) {
		MoveObject( renObjs[i], glm::vec4( (float)rand()/RAND_MAX - .5, (float)rand()/RAND_MAX - .5, (float)rand()/RAND_MAX - .5, 0.0f ) );
	}
}
Exemplo n.º 22
0
void MovePlayer(const int frameTicks)
{
	if(player.isAlive)
	{
		//Check to see if the player was struck by an enemy bullet
		Bullet* currentBullet;
		for(int i = 0; i < MAX_ENEMY_BULLET; i++)
		{
			currentBullet = &enemyBullets[i];
			if(currentBullet->isAlive)
			{
				if(currentBullet->isOverlapping(player))
				{
					currentBullet->isAlive = false;

					//The player only can take damage every 300ms
					if(frameTicks - player.lastHitTicks > 300)
					{
						if(player.hitPoints > 1)
						{
							player.lastHitTicks = frameTicks;
							player.hitPoints -= 1;
							Mix_PlayChannel(-1, whackSound, 0);
						}
						else
						{
							player.hitPoints -= 1;
							player.isAlive = false;						
							Mix_PlayChannel(-1, splatSound, 0);
						}
					}
				}
			}
		}

		if(player.isAlive)
		{
			//Move the player.	
			//First check to see if it has an acceleration.
			//If so, apply it to the velocity
			if(player.xAccel != 0.0)
			{
				player.xVel = player.xAccel;
				player.xAccel = 0.0;
			}
			if(player.yAccel != 0.0)
			{
				player.yVel = player.yAccel;
				player.yAccel = 0.0;
			}

			//Move the player according to its velocity
			double xVel, yVel;
			xVel = yVel = 0.0;

			//If moving diagonal, sync the move ticks to prevent the player from zooming
			if(player.keyDownTicks[0] > 0 && player.keyDownTicks[1] > 0 && player.keyDownTicks[0] != player.keyDownTicks[1])
			{
				int min = std::min(player.keyDownTicks[0], player.keyDownTicks[1]);
				player.keyDownTicks[0] = min;
				player.keyDownTicks[1] = min;
			}

			//We don't want to move too fast, so we check the current time against
			//the time the key was first pressed.
			if(player.keyDownTicks[0] > 0 && (frameTicks == player.keyDownTicks[0]))
			{
				xVel = player.xVel;
			}
			else if(player.keyDownTicks[0] > 0 && (frameTicks - player.keyDownTicks[0]) > PLAYER_ACCEL_TIME)
			{
				xVel = player.xVel;
				player.keyDownTicks[0] = frameTicks;
			}

			if(player.keyDownTicks[1] > 0 && (frameTicks == player.keyDownTicks[1]))
			{
				yVel = player.yVel;
			}
			else if(player.keyDownTicks[1] > 0 && (frameTicks - player.keyDownTicks[1]) > PLAYER_ACCEL_TIME)
			{
				yVel = player.yVel;
				player.keyDownTicks[1] = frameTicks;
			}

			if(xVel != 0.0 || yVel != 0.0)
			{
				MoveObject(player, xVel, yVel);
			}
		}
	}
}
Exemplo n.º 23
0
void Hex::removeMoveObject()
{
	for (Direction direction : BTech::directions)
		moveObject[direction] = MoveObject(BTech::MovementAction::Idle);
	currentMovementObjectNumber = 0;
}
Exemplo n.º 24
0
//----------------------------------------------------------------------------
void GeodesicHeightField::OnIdle ()
{
	MeasureTime();

	if (MoveCamera())
	{
		mCuller.ComputeVisibleSet(mScene);
	}

	if (MoveObject())
	{
		mScene->Update();
		mCuller.ComputeVisibleSet(mScene);
	}

	if (mSelected == 2)
	{
		int currQuantity = mGeodesic->GetCurrentQuantity();
		if (currQuantity == 0)
		{
			currQuantity = mPQuantity;
		}

		// Clear the texture image to white.
		memset(mTexture->GetData(0), 0xFF, mTexture->GetNumLevelBytes(0));

		// Draw the approximate path.
		int bound0 = mTexture->GetDimension(0, 0);
		int bound1 = mTexture->GetDimension(1, 0);
		int x0 = (int)(bound0*mPath[0][0] + 0.5);
		int y0 = (int)(bound1*mPath[0][1] + 0.5);
		for (int i = 1; i < currQuantity; ++i)
		{
			int x1 = (int)(bound0*mPath[i][0] + 0.5);
			int y1 = (int)(bound1*mPath[i][1] + 0.5);
			Line2D(x0, y0, x1, y1, DrawCallback);
			x0 = x1;
			y0 = y1;
		}

		mTexture->GenerateMipmaps();
	}

	if (mRenderer->PreDraw())
	{
		mRenderer->ClearBuffers();
		mRenderer->Draw(mCuller.GetVisibleSet());
		DrawFrameRate(8, GetHeight()-8, mTextColor);

		char message[256];
		sprintf(message,
		        "sub = %d, ref = %d, len = %15.12lf, avgcrv = %15.12lf",
		        mGeodesic->GetSubdivisionStep(),
		        mGeodesic->GetRefinementStep(),
		        mDistance, mCurvature/mDistance);
		mRenderer->Draw(8, 16, mTextColor, message);

		mRenderer->PostDraw();
		mRenderer->DisplayColorBuffer();
	}

	UpdateFrameCount();
}
Exemplo n.º 25
0
//----------------------------------------------------------------------------
//#define DUMP_RENDER_TARGETS
//----------------------------------------------------------------------------
void ShadowMaps::OnIdle ()
{
    MeasureTime();

    if (MoveCamera())
    {
        mCuller.ComputeVisibleSet(mScene);
    }

    if (MoveObject())
    {
        mScene->Update();
        mCuller.ComputeVisibleSet(mScene);
    }

    if (mRenderer->PreDraw())
    {
        // Draw the scene from the light's perspective, writing the depths
        // from the light into the render target.
        mRenderer->Enable(mShadowTarget);
        mRenderer->SetClearColor(mShadowClear);
        mRenderer->ClearBuffers();
        mRenderer->Draw(mCuller.GetVisibleSet(), mShadowEffect);
        mRenderer->Disable(mShadowTarget);
#ifdef DUMP_RENDER_TARGETS
        Texture2D* texture = mRenderer->Read(mShadowTarget);
        texture->SaveWMTF("ShadowTarget.wmtf");
        delete0(texture);
#endif

        // Draw the scene from the camera's perspective, using projected
        // texturing of the shadow map and determining which pixels are lit
        // and which are shadowed.
        mRenderer->ClearBuffers();
        mRenderer->Enable(mUnlitTarget);
        mRenderer->SetClearColor(mUnlitClear);
        mRenderer->ClearBuffers();
        mRenderer->Draw(mCuller.GetVisibleSet(), mUnlitEffect);
        mRenderer->Disable(mUnlitTarget);
#ifdef DUMP_RENDER_TARGETS
        texture = mRenderer->Read(mUnlitTarget);
        texture->SaveWMTF("UnlitTarget.wmtf");
        delete0(texture);
#endif

        // Do screen space drawing.
        mRenderer->SetCamera(mScreenCamera);

        // Horizontally blur the unlit render target.
        mScreenPolygon->SetEffectInstance(mHBlurInstance);
        mRenderer->Enable(mHBlurTarget);
        mRenderer->Draw(mScreenPolygon);
        mRenderer->Disable(mHBlurTarget);
#ifdef DUMP_RENDER_TARGETS
        texture = mRenderer->Read(mHBlurTarget);
        texture->SaveWMTF("HBlurTarget.wmtf");
        delete0(texture);
#endif

        // Vertically blur the horizontal blur render target.
        mScreenPolygon->SetEffectInstance(mVBlurInstance);
        mRenderer->Enable(mVBlurTarget);
        mRenderer->Draw(mScreenPolygon);
        mRenderer->Disable(mVBlurTarget);
#ifdef DUMP_RENDER_TARGETS
        texture = mRenderer->Read(mVBlurTarget);
        texture->SaveWMTF("VBlurTarget.wmtf");
        delete0(texture);
#endif

        // Draw the scene using regular textures, combining the shadow
        // information with the scene.
        mRenderer->SetCamera(mCamera);
        mRenderer->SetClearColor(mClearColor);
        mRenderer->ClearBuffers();
        mRenderer->Draw(mCuller.GetVisibleSet());
        DrawFrameRate(8, GetHeight()-8, mTextColor);
        mRenderer->PostDraw();
        mRenderer->DisplayColorBuffer();
    }

    UpdateFrameCount();
}
Exemplo n.º 26
0
//----------------------------------------------------------------------------
void BillboardNodes::OnIdle ()
{
    MeasureTime();

    // Update set of visible objects.
    if (MoveCamera())
    {
        mBillboard0->Update();
        mBillboard1->Update();
        mCuller.ComputeVisibleSet(mScene);
    }
    if (MoveObject())
    {
        mScene->Update();
        mCuller.ComputeVisibleSet(mScene);
    }

#ifdef DEMONSTRATE_VIEWPORT_BOUNDING_RECTANGLE
    // Compute the bounding rectangle for the torus.
    VertexBuffer* vbuffer = mTorus->GetVertexBuffer();
    char* vertices = vbuffer->GetData();
    int numVertices = vbuffer->GetNumElements();
    int stride = mTorus->GetVertexFormat()->GetStride();
    const HMatrix& worldMatrix = mTorus->WorldTransform.Matrix();

    float xmin, xmax, ymin, ymax;
    mCamera->ComputeBoundingAABB(numVertices, vertices, stride,
        worldMatrix, xmin, xmax, ymin, ymax);

    // Convert the normalized display coordinates to [0,1]^2 window
    // coordinates.
    xmin = 0.5f*(1.0f + xmin);
    xmax = 0.5f*(1.0f + xmax);
    ymin = 0.5f*(1.0f + ymin);
    ymax = 0.5f*(1.0f + ymax);

    // Update the screen rectangle.
    VertexBufferAccessor vba(mSSRectangle);
    vba.Position<Float3>(0) = Float3(xmin, ymin, 0.0f);
    vba.Position<Float3>(1) = Float3(xmax, ymin, 0.0f);
    vba.Position<Float3>(2) = Float3(xmax, ymax, 0.0f);
    vba.Position<Float3>(3) = Float3(xmin, ymax, 0.0f);
    mRenderer->Update(mSSRectangle->GetVertexBuffer());
#endif

    // Draw the scene.
    if (mRenderer->PreDraw())
    {
        mRenderer->ClearBuffers();
        mRenderer->Draw(mCuller.GetVisibleSet());

#ifdef DEMONSTRATE_VIEWPORT_BOUNDING_RECTANGLE
        // Draw the screen rectangle.
        mRenderer->SetCamera(mSSCamera);
        mCullState->Enabled = false;
        mRenderer->Draw(mSSRectangle);
        mCullState->Enabled = true;
        mRenderer->SetCamera(mCamera);
#endif

        DrawFrameRate(8, GetHeight()-8, mTextColor);

        mRenderer->PostDraw();
        mRenderer->DisplayColorBuffer();
    }

    UpdateFrameCount();
}
Exemplo n.º 27
0
static void EndRubberBand ( Widget    w,
                            XtPointer clientData,
                            XEvent   *event,
                            Boolean   *flag )
{

   /*
    * Finalize the operation begun with StartRubberBand(). If there 
    * a current drawing function, clear the last XOR image and draw
    * the final figure. 
    */

    if ( currentFunction && 
         event->xbutton.button == Button1 )
    {
        /*
         * Erase the XOR image. 
         */
        
         ( * ( currentFunction ) ) ( XtWindow ( w ), xorGC,
                                     startX, startY, 
                                     lastX,  lastY );
        
        /*
         * Draw the figure using the normal GC. 
         */
        
         ( * ( currentFunction ) ) ( XtWindow ( w ), currentGC,
                                     startX, startY, 
                                     event->xbutton.x, 
                                     event->xbutton.y );
        
        /*
         * Update the data, and store the object in 
         * the display list.
         */
        
        lastX = event->xbutton.x;
        lastY = event->xbutton.y;
        
        StoreObject();
        
        currentObject = PickObject ( event->xbutton.x,
                                     event->xbutton.y );

    }
    else if  ( currentObject    && 
               !currentFunction && 
               event->xbutton.button == Button1 )
    {

       /*
        * If the operation was a drag, move the figure
        * to its final position.
        */

        MoveObject ( currentObject, 
                     event->xbutton.x - lastX,  
                     event->xbutton.y - lastY );

       /*
        * Force a complete redraw.
        */
        
        XClearArea ( display, XtWindow ( w ), 0, 0, 0, 0, TRUE );
    }
}
Exemplo n.º 28
0
void UpdateState()
{
  //If player is still, center it
  if(player.speed.x == 0)
    { player.center.x = TILE_CENTER_X; }
  
  //Stop player if he hits a wall
  if((player.speed.x >= 0 && atRightWall(&player)) ||
     (player.speed.x <= 0 && atLeftWall(&player)))
    {
      if(player.speed.x < 0)
	{ blocked_right = TRUE; }
      else if(player.speed.x > 0)
	{ blocked_left = TRUE; }
      StopObject(&player,HORIZONTAL);
    }
  
  //Keep player from going through ceilings
  if(player.speed.y >= 0 && atCeiling(&player))
    { StopObject(&player,VERTICAL); }
  //Create gravity for player
  if(player.speed.y <= 0 && onFloor(&player))
    { StopObject(&player,VERTICAL); }
  else if(player.speed.y > -0.5)
    { player.speed.y -= 0.05; }
  else if(player.speed.y == 0)
    { player.center.y = TILE_CENTER_Y; }
  
  //Make sure player doesn't go diagonally through corners
  if(atCorner(&player,player.speed) && !(player.speed.x == 0 && player.speed.y == 0))
    {
      if(abs(player.speed.x) > abs(player.speed.y))
	{ StopObject(&player,HORIZONTAL); }
      else
	{ StopObject(&player,VERTICAL); }
    }
  
  //Detect collisions between player and monsters:
  //Kill the monster if the player lands on it, but kill the player
  //otherwise.
  if(grid[player.location.x][player.location.y-1] != NULL &&
     grid[player.location.x][player.location.y-1]->type == MONSTER)
    {
      grid[player.location.x][player.location.y-1]->alive = FALSE;
      grid[player.location.x][player.location.y-1] = NULL;
    }
  else if((player.location.y != TOP &&
	   grid[player.location.x][player.location.y+1] != NULL &&
	   grid[player.location.x][player.location.y+1]->type == MONSTER) ||
	  (player.location.x != LEFT &&
	   grid[player.location.x-1][player.location.y] != NULL &&
	   grid[player.location.x-1][player.location.y]->type == MONSTER) ||
	  (player.location.x != RIGHT &&
	   grid[player.location.x+1][player.location.y] != NULL &&
	   grid[player.location.x+1][player.location.y]->type == MONSTER))
    { player.alive = FALSE; }
  
  //Every second, spawn a new monster in one of the top two corners
  static time_t last_time = 0;
  time_t now = time(NULL);
  if (difftime(now, last_time) > 1)
    {
      struct point center = {TILE_CENTER_X, TILE_CENTER_Y};
      struct vector speed = {0, 0};
      struct point location = {LEFT,TOP};
      if(rand()%10 >= 5)
	{ location.x = RIGHT; }
      CreateObject(&g_monsters, location, center, speed, &monster_icon, MONSTER);
      last_time = time(NULL);
    }
  
  //update the monsters
  UpdateMonsters();
  
  //change the player's location
  MoveObject(&player, &player.speed);
  
  //change the monsters' locations
  for(struct object_list *monsterp = g_monsters; monsterp != NULL; monsterp = monsterp->next_object)
    {
      if(monsterp->object.alive)
	{ MoveObject(&(monsterp->object), &(monsterp->object.speed)); }
    }
}
Exemplo n.º 29
0
// the 'cmdsrun' parameter counts how many commands are run.
// if a 'Inv Item Was Used' check does not pass, it doesn't count
// so cmdsrun remains 0 if no inventory items matched
int run_interaction_commandlist (InteractionCommandList *nicl, int *timesrun, int*cmdsrun) {
    size_t i;

    if (nicl == NULL)
        return -1;

    for (i = 0; i < nicl->Cmds.size(); i++) {
        cmdsrun[0] ++;
        int room_was = play.room_changes;

        switch (nicl->Cmds[i].Type) {
      case 0:  // Do nothing
          break;
      case 1:  // Run script
          { 
              TempEip tempip(4001);
              RuntimeScriptValue rval_null;
              update_mp3();
                  if ((strstr(evblockbasename,"character")!=0) || (strstr(evblockbasename,"inventory")!=0)) {
                      // Character or Inventory (global script)
                      const char *torun = make_ts_func_name(evblockbasename,evblocknum,nicl->Cmds[i].Data[0].Value);
                      // we are already inside the mouseclick event of the script, can't nest calls
                      QueueScriptFunction(kScInstGame, torun);
                  }
                  else {
                      // Other (room script)
                      const char *torun = make_ts_func_name(evblockbasename,evblocknum,nicl->Cmds[i].Data[0].Value);
                      QueueScriptFunction(kScInstRoom, torun);
                  }
                  update_mp3();
                      break;
          }
      case 2:  // Add score (first time)
          if (timesrun[0] > 0)
              break;
          timesrun[0] ++;
      case 3:  // Add score
          GiveScore (IPARAM1);
          break;
      case 4:  // Display Message
          /*        if (comprdata<0)
          display_message_aschar=evb->data[ss];*/
          DisplayMessage(IPARAM1);
          break;
      case 5:  // Play Music
          PlayMusicResetQueue(IPARAM1);
          break;
      case 6:  // Stop Music
          stopmusic ();
          break;
      case 7:  // Play Sound
          play_sound (IPARAM1);
          break;
      case 8:  // Play Flic
          play_flc_file(IPARAM1, IPARAM2);
          break;
      case 9:  // Run Dialog
          { int room_was = play.room_changes;
          RunDialog(IPARAM1);
          // if they changed room within the dialog script,
          // the interaction command list is no longer valid
          if (room_was != play.room_changes)
              return -1;
          }
          break;
      case 10: // Enable Dialog Option
          SetDialogOption (IPARAM1, IPARAM2, 1);
          break;
      case 11: // Disable Dialog Option
          SetDialogOption (IPARAM1, IPARAM2, 0);
          break;
      case 12: // Go To Screen
          Character_ChangeRoomAutoPosition(playerchar, IPARAM1, IPARAM2);
          return -1;
      case 13: // Add Inventory
          add_inventory (IPARAM1);
          break;
      case 14: // Move Object
          MoveObject (IPARAM1, IPARAM2, IPARAM3, IPARAM4);
          // if they want to wait until finished, do so
          if (IPARAM5)
              GameLoopUntilEvent(UNTIL_MOVEEND,(long)&objs[IPARAM1].moving);
          break;
      case 15: // Object Off
          ObjectOff (IPARAM1);
          break;
      case 16: // Object On
          ObjectOn (IPARAM1);
          break;
      case 17: // Set Object View
          SetObjectView (IPARAM1, IPARAM2);
          break;
      case 18: // Animate Object
          AnimateObject (IPARAM1, IPARAM2, IPARAM3, IPARAM4);
          break;
      case 19: // Move Character
          if (IPARAM4)
              MoveCharacterBlocking (IPARAM1, IPARAM2, IPARAM3, 0);
          else
              MoveCharacter (IPARAM1, IPARAM2, IPARAM3);
          break;
      case 20: // If Inventory Item was used
          if (play.usedinv == IPARAM1) {
              if (game.options[OPT_NOLOSEINV] == 0)
                  lose_inventory (play.usedinv);
              if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun))
                  return -1;
          }
          else
              cmdsrun[0] --;
          break;
      case 21: // if player has inventory item
          if (playerchar->inv[IPARAM1] > 0)
              if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun))
                  return -1;
          break;
      case 22: // if a character is moving
          if (game.chars[IPARAM1].walking)
              if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun))
                  return -1;
          break;
      case 23: // if two variables are equal
          if (IPARAM1 == IPARAM2)
              if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun))
                  return -1;
          break;
      case 24: // Stop character walking
          StopMoving (IPARAM1);
          break;
      case 25: // Go to screen at specific co-ordinates
          NewRoomEx (IPARAM1, IPARAM2, IPARAM3);
          return -1;
      case 26: // Move NPC to different room
          if (!is_valid_character(IPARAM1))
              quit("!Move NPC to different room: invalid character specified");
          game.chars[IPARAM1].room = IPARAM2;
          break;
      case 27: // Set character view
          SetCharacterView (IPARAM1, IPARAM2);
          break;
      case 28: // Release character view
          ReleaseCharacterView (IPARAM1);
          break;
      case 29: // Follow character
          FollowCharacter (IPARAM1, IPARAM2);
          break;
      case 30: // Stop following
          FollowCharacter (IPARAM1, -1);
          break;
      case 31: // Disable hotspot
          DisableHotspot (IPARAM1);
          break;
      case 32: // Enable hotspot
          EnableHotspot (IPARAM1);
          break;
      case 33: // Set variable value
          get_interaction_variable(nicl->Cmds[i].Data[0].Value)->Value = IPARAM2;
          break;
      case 34: // Run animation
          scAnimateCharacter(IPARAM1, IPARAM2, IPARAM3, 0);
          GameLoopUntilEvent(UNTIL_SHORTIS0,(long)&game.chars[IPARAM1].animating);
          break;
      case 35: // Quick animation
          SetCharacterView (IPARAM1, IPARAM2);
          scAnimateCharacter(IPARAM1, IPARAM3, IPARAM4, 0);
          GameLoopUntilEvent(UNTIL_SHORTIS0,(long)&game.chars[IPARAM1].animating);
          ReleaseCharacterView (IPARAM1);
          break;
      case 36: // Set idle animation
          SetCharacterIdle (IPARAM1, IPARAM2, IPARAM3);
          break;
      case 37: // Disable idle animation
          SetCharacterIdle (IPARAM1, -1, -1);
          break;
      case 38: // Lose inventory item
          lose_inventory (IPARAM1);
          break;
      case 39: // Show GUI
          InterfaceOn (IPARAM1);
          break;
      case 40: // Hide GUI
          InterfaceOff (IPARAM1);
          break;
      case 41: // Stop running more commands
          return -1;
      case 42: // Face location
          FaceLocation (IPARAM1, IPARAM2, IPARAM3);
          break;
      case 43: // Pause command processor
          scrWait (IPARAM1);
          break;
      case 44: // Change character view
          ChangeCharacterView (IPARAM1, IPARAM2);
          break;
      case 45: // If player character is
          if (GetPlayerCharacter() == IPARAM1)
              if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun))
                  return -1;
          break;
      case 46: // if cursor mode is
          if (GetCursorMode() == IPARAM1)
              if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun))
                  return -1;
          break;
      case 47: // if player has been to room
          if (HasBeenToRoom(IPARAM1))
              if (run_interaction_commandlist (nicl->Cmds[i].Children.get(), timesrun, cmdsrun))
                  return -1;
          break;
      default:
          quit("unknown new interaction command");
          break;
        }

        // if the room changed within the action, nicl is no longer valid
        if (room_was != play.room_changes)
            return -1;
    }
    return 0;

}
Exemplo n.º 30
0
// Collides the two solid objects using WorldModel physics for the one that is a WorldModel.
static LTBOOL DoSolidWMCollision
(
	MoveState*	pState,
	LTObject*	pTestObj,
	LTVector&	startPos,
	LTVector&	destPos,
	LTBOOL&		bCollision
)
{
	LTVector pos1, pos2, vecTo, vDir;
	LTBOOL bWorldModel;
	MoveState moveState;
	LTVector minBox, maxBox;

	bCollision = false;

	// Worldmodel moving into an object...
	if( HasWorldModel(pState->m_pObj) )
	{
		// pInputObj is pushing pTestObj.
		pos2 = pTestObj->GetPos();
		
		vecTo = destPos - startPos;
		pos1 = pos2 + vecTo;
		
		vDir = vecTo;
		vDir.Norm();
		pos1 += vDir * 0.5f; // Move a little further back.

		// See if the blocker collides with the mover at any point during the move...
		if( CollideAgainstWorld(pState,
								pState->m_pObj->ToWorldModel()->m_pValidBsp, 
								pState->m_pObj,
								pTestObj,
								pos1,
								pos2, 
								!(pState->m_pObj->m_Flags & FLAG_NOSLIDING) ) )
		{
			bCollision = true;

			if(pState->m_pAbstract->ShouldPushObject(pState, pState->m_pObj, pTestObj))
			{
				// There is a collision, so move the blocker to its new position...
				moveState.Inherit(pState, pTestObj);
				MoveObject(&moveState, pos2, MO_DETACHSTANDING|MO_SETCHANGEFLAG|MO_MOVESTANDINGONS);

				// If they're still intersecting, go to the below area where the pusher is stopped
				// by the blocker.  Only consider it crushing if there is significant penetration, otherwise
				// it's just date-crushing.
				minBox = pTestObj->m_MinBox;
				minBox.x += 0.1f;
				minBox.y += 0.1f;
				minBox.z += 0.1f;
				
				maxBox = pTestObj->m_MaxBox;
				maxBox.x -= 0.1f;
				maxBox.y -= 0.1f;
				maxBox.z -= 0.1f;

				if( DoObjectsIntersect( pState->m_pObj, pTestObj, 
					&pState->m_pObj->m_MinBox, &pState->m_pObj->m_MaxBox, 
					&minBox, &maxBox, 
					pState->m_pObj->GetPos(), pState->m_pObj->GetPos(), 
					0.1f, &bWorldModel) )
				{
					// Still intersecting.. send a crush message to pTestObj.
					pState->m_pAbstract->DoCrush(pTestObj, pState->m_pObj);
				}
				else
				{
					// Mover wasn't blocked...
					return false;
				}
			}

			// mover had a lower blocking priority or the blocker couldn't be pushed out of the way...

			// Get the amount the worldobject has to move back by...
			vecTo = pTestObj->GetPos() - pos2;

			// Move the worldobject back a little...
			destPos += vecTo;

			// Mover was blocked...
			return true;
		}
	}
	// Object moving into a worldmodel...
	else
	{
		ASSERT(HasWorldModel(pTestObj));

		pos2 = destPos;

		// Move the object into the worldobject to see how far it can get...
		if( CollideAgainstWorld(pState, 
								pTestObj->ToWorldModel()->m_pValidBsp, 
								pTestObj,
								pState->m_pObj,
								startPos, pos2, 
								!(pState->m_pObj->m_Flags & FLAG_NOSLIDING) ) )
		{
			// There was a hit...
			bCollision = true;

			if(pState->m_pAbstract->ShouldPushObject(pState, pState->m_pObj, pTestObj))
			{
				vecTo = destPos - pos2;
				pos1 = pTestObj->GetPos() + vecTo;

				// There is a collision, so move the blocker to its new position...
				moveState.Inherit(pState, pTestObj);
				MoveObject( &moveState, pos1, MO_DETACHSTANDING | MO_SETCHANGEFLAG | MO_MOVESTANDINGONS );

				minBox = pTestObj->m_MinBox;
				minBox.x += 0.1f;
				minBox.y += 0.1f;
				minBox.z += 0.1f;
				
				maxBox = pTestObj->m_MaxBox;
				maxBox.x -= 0.1f;
				maxBox.y -= 0.1f;
				maxBox.z -= 0.1f;

				// If they're still intersecting, go to the below area where the pusher is stopped
				// by the blocker.  Only consider it crushing if there is significant penetration, otherwise
				// it's just date-crushing.
				if(	DoObjectsIntersect( pState->m_pObj,
										pTestObj,
										&pState->m_pObj->m_MinBox,
										&pState->m_pObj->m_MaxBox, 
										&minBox,
										&maxBox,
										pState->m_pObj->GetPos(),
										pState->m_pObj->GetPos(),
										0.1f,
										&bWorldModel ) )
				{
					// Still intersecting.. send a crush message to pTestObj.
					pState->m_pAbstract->DoCrush( pTestObj, pState->m_pObj );

					// Get the amount the mover has to move back by...
					vecTo = pTestObj->GetPos() - pos1;

					// Move the mover back a little...
					destPos += vecTo;

					// Mover blocked...
					return true;
				}
			}
			else
			{
				// If the blocking priority is lower, then collideAgainstWorld finds our final position...
				destPos = pos2;

				// Mover blocked...
				return true;
			}

			// Mover not blocked...
			return false;
		}
	}

	// Mover not blocked...
	return false;
}