Пример #1
0
//------------------------------------------------------------------------------
void PlayScene::create()
{
	World& world = getSceneManager().getWorld();

	// Camera
	Transform* transCamera = DG_NEW(Transform, world.getLinearArena());
	transCamera->position = vmVector3(0.0f, 3.4f, 0.0f);

	Camera* camera = DG_NEW(Camera, world.getLinearArena());
	camera->fov = 0.9f;

	world.getEntity(0).addComponent(transCamera);
	world.getEntity(0).addComponent(camera);

	// Light
	Transform* transLight = DG_NEW(Transform,  world.getLinearArena());
	transLight->position = vmVector3(0, 10, 0);

	Light* light = DG_NEW(Light, world.getLinearArena())(0);
	light->lightType = LT_DIRECTIONAL;
	light->direction = vmVector3(0.0f, 0.9f, 1.0f);

	//Material matCube;
	//matCube.ambient = vmVector4(0.7f, 0.7f, 0.7f, 1.f);
	//matCube.diffuse = vmVector4(0.7f, 0.7f, 0.7f, 1.f);
	//matCube.textureFiles.push_back("tiles.png");

	//Mesh* meshCube = DG_NEW(Mesh, world.getLinearArena());
	//meshCube->file = "../media/cube.x";
	//meshCube->materials.push_back(matCube);

	world.getEntity(1).addComponent(transLight);
	world.getEntity(1).addComponent(light);
	//world.getEntity(1).addComponent(meshCube);

	// Set active camera and light
	world.getSystemManager().getSystem<MeshSystem>()->setCamera(camera);
	world.getSystemManager().getSystem<MeshSystem>()->setLight(light);

	// Sky
	Transform* transSky = DG_NEW(Transform,  world.getLinearArena());
	transSky->position = vmVector3(0, 0, 0);

	Material matSky;
	matSky.textureFiles.push_back("NoiseVolume.dds");

	Mesh* meshSky = DG_NEW(Mesh, world.getLinearArena());
	meshSky->file = "../media/sphere_inverted.x";
	meshSky->effectFile = "../media/sky.cg";
	meshSky->materials.push_back(matSky);

	world.getEntity(2).addComponent(transSky);
	world.getEntity(2).addComponent(meshSky);
	
	// Terrain
	Transform* transTerrain = DG_NEW(Transform,  world.getLinearArena());
	transTerrain->position = vmVector3(0, 0, 0);

	Material matTerrain;
	matTerrain.ambient = vmVector4(0.2f, 0.2f, 0.2f, 1.f);
	matTerrain.diffuse = vmVector4(0.7f, 0.7f, 0.7f, 1.f);
	matTerrain.textureFiles.push_back("grass.jpg");

	Mesh* meshTerrain = DG_NEW(Mesh, world.getLinearArena());
	meshTerrain->file = "../media/TerrainTextured.x";
	meshTerrain->effectFile = "../media/terrain.cg";
	meshTerrain->materials.push_back(matTerrain);

	world.getEntity(3).addComponent(transTerrain);
	world.getEntity(3).addComponent(meshTerrain);

	// Water
	Transform* transWater = DG_NEW(Transform, world.getLinearArena());
	transWater->position = vmVector3(0, -2, 0);
	transWater->scale = vmVector3(130, 1, 130);

	Material matWater;
	matWater.ambient = vmVector4(0.0f, 0.5459f, 0.8496f, 1.f);
	matWater.diffuse = vmVector4(0.0f, 0.5459f, 0.8496f, 0.5f);

	Mesh* meshWater = DG_NEW(Mesh,  world.getLinearArena());
	meshWater->file = "../media/quad.x";
	meshWater->effectFile = "../media/water.cg";
	meshWater->materials.push_back(matWater);

	world.getEntity(4).addComponent(transWater);
	world.getEntity(4).addComponent(meshWater);

	// Copter
	Transform* transCopter = DG_NEW(Transform, world.getLinearArena());
	transCopter->position = vmVector3(0, 0, 0);

	Material matCopter;
	Material matCopter2;
	matCopter2.ambient = vmVector4(0.2f, 0.2f, 0.2f, 1.f);
	matCopter2.diffuse = vmVector4(0.7f, 0.7f, 0.7f, 1.f);
	matCopter2.textureFiles.push_back("copter_diffuse.png");
	matCopter2.textureFiles.push_back("copter_normal.png");
	//matCopter2.textureFiles.push_back("tiles.png");
	//matCopter2.textureFiles.push_back("tiles_normal.png");

	Mesh* meshCopter = DG_NEW(Mesh,  world.getLinearArena());
	meshCopter->file = "../media/copter.x";
	meshCopter->effectFile = "../media/copter.cg";
	meshCopter->materials.push_back(matCopter);
	meshCopter->materials.push_back(matCopter2);

	world.getEntity(5).addComponent(transCopter);
	world.getEntity(5).addComponent(meshCopter);

	// Initialise all systems
	world.getSystemManager().initialiseAll();

	// Test physics
	PxMaterial* material = &mPhysXWorld.getDefaultMaterial();
	material->setRestitution(0.5f);
	material->setStaticFriction(1.0f);
	material->setDynamicFriction(1.0f);

	//mActor = mPhysXWorld.getScene("Main")->createRigidDynamic(
		//physx::PxConvexMeshGeometry(PhysXCooker::createPxConvexMesh(*mPhysXWorld.getPxPhysics(), *mPhysXWorld.getCookingInterface(), 
		//world.getSystemManager().getSystem<MeshSystem>()->getVertices(world.getEntity(3)))), 20.0f, *material);
	/*mActor = mPhysXWorld.getScene("Main")->createRigidDynamic(
		PhysXGeometry::boxGeometry(world.getEntity(2), *world.getSystemManager().getSystem<MeshSystem>()), 10.0f, *material);
	mPhysXWorld.getScene("Main")->createRenderedActorBinding(mActor, 
		DG_NEW(PhysXEntityRenderable, world.getLinearArena())(&world.getEntity(2)));
	mActor.setGlobalPosition(vmVector3(0.0f, 20.0, 0.0f));*/

	//PhysXActor<PxRigidDynamic> actor1 = mPhysXWorld.getScene("Main")->createRigidDynamic(
		//physx::PxConvexMeshGeometry(PhysXCooker::createPxConvexMesh(*mPhysXWorld.getPxPhysics(), *mPhysXWorld.getCookingInterface(), 
		//world.getSystemManager().getSystem<MeshSystem>()->getVertices(world.getEntity(4)))), 20.0f, *material);
	mActor = mPhysXWorld.getScene("Main")->createRigidDynamic(
		PhysXGeometry::boxGeometry(world.getEntity(5), *world.getSystemManager().getSystem<MeshSystem>()), 1.f, *material);
	mPhysXWorld.getScene("Main")->createRenderedActorBinding(mActor, 
		DG_NEW(PhysXEntityRenderable, world.getLinearArena())(&world.getEntity(5)));
	mActor.setGlobalPosition(vmVector3(-3.0f, 0.0f, 0.0f));
	mActor.getPxActor()->setLinearDamping(0.8f);
	mActor.getPxActor()->setAngularDamping(1.0f);

	PhysXActor<PxRigidStatic> actor2 = mPhysXWorld.getScene("Main")->createRigidStatic(
		physx::PxTriangleMeshGeometry(PhysXCooker::createPxTriangleMesh(*mPhysXWorld.getPxPhysics(), *mPhysXWorld.getCookingInterface(), 
		world.getSystemManager().getSystem<MeshSystem>()->getIndices(world.getEntity(3)),
		world.getSystemManager().getSystem<MeshSystem>()->getVertices(world.getEntity(3)))), *material);

	mInput.subscribeKeyboard(*this);
	mInput.subscribeMouse(*this);
}
Пример #2
0
//------------------------------------------------------------------------------
void PlayScene::update()
{
	World& world = getSceneManager().getWorld();

	Real speed = 2000.0f;

	// Lock orientation
	mActor.setGlobalOrientation(vmQuat(0.0f, 0.0f, 0.0f, 1.0f));

	if (mInput.getKeyboard()->isKeyDown(OIS::KC_UP))
	{
		mActor.getPxActor()->addForce(PxVec3(0.0f, 0.0f , speed));
	}
	else if (mInput.getKeyboard()->isKeyDown(OIS::KC_DOWN))
	{
		mActor.getPxActor()->addForce(PxVec3(0.0f, 0.0f , -speed));
	}
	if (mInput.getKeyboard()->isKeyDown(OIS::KC_LEFT))
	{
		mActor.getPxActor()->addForce(PxVec3(-speed, 0.0f , 0.0f));
	}
	else if (mInput.getKeyboard()->isKeyDown(OIS::KC_RIGHT))
	{
		mActor.getPxActor()->addForce(PxVec3(speed, 0.0f , 0.0f));
	}
	if (mInput.getKeyboard()->isKeyDown(OIS::KC_SPACE))
	{
		mActor.getPxActor()->addForce(PxVec3(0.0f, speed / 2, 0.0f));
	}
	if (mInput.getKeyboard()->isKeyDown(OIS::KC_H))
	{
		mActor.setGlobalPosition(vmVector3(-3.0f, 0.0, 0.0f));
		mActor.getPxActor()->setLinearVelocity(PxVec3(0));
	}

	// TODO: Day/night cycle
	vmVector3 centre = vmVector3(0.0f, 0.0f, 0.0f);
	vmVector3 point = vmVector3(10.0f, 0.0f, 0.0f);
	vmVector3 axis = vmVector3(0.0f, 1.0f, 0.0f);
	//mAngle += 0.1f;
	Real mAngle = 45.0f;

	vmVector3 pos = centre - point;
	Real cosTheta = cos(mAngle * D3DX_PI / Real(180.0));
	Real sinTheta = sin(mAngle * D3DX_PI / Real(180.0));
	
	vmVector3 newPos;
	// Find the new x position for the new rotated point.
	newPos.setX((cosTheta + (1 - cosTheta) * axis.getX() * axis.getX()) * pos.getX());
	newPos.setX(newPos.getX() + ((1 - cosTheta) * axis.getX() * axis.getY() - axis.getZ() * sinTheta) * pos.getY());
	newPos.setX(newPos.getX() + ((1 - cosTheta) * axis.getX() * axis.getZ() + axis.getY() * sinTheta) * pos.getZ());
	
	// Find the new y position for the new rotated point.
	newPos.setY(((1 - cosTheta) * axis.getX() * axis.getY() + axis.getZ() * sinTheta) * pos.getX());
	newPos.setY(newPos.getY() + (cosTheta + (1 - cosTheta) * axis.getY() * axis.getY()) * pos.getY());
	newPos.setY(newPos.getY() + ((1 - cosTheta) * axis.getY() * axis.getZ() - axis.getX() * sinTheta) * pos.getZ());
	
	// Find the new z position for the new rotated point.
	newPos.setZ(((1 - cosTheta) * axis.getZ() * axis.getZ() - axis.getY() * sinTheta) * pos.getX());
	newPos.setZ(newPos.getZ() + ((1 - cosTheta) * axis.getY() * axis.getZ() + axis.getX() * sinTheta) * pos.getY());
	newPos.setZ(newPos.getZ() + (cosTheta + (1 - cosTheta) * axis.getZ() * axis.getZ()) * pos.getZ());
	
	//world.getEntity(1).getComponent<Transform>()->position = newPos + point;
	//world.getEntity(1).getComponent<Light>()->direction = normalize(centre - world.getEntity(1).getComponent<Transform>()->position);
	
	// Camera translation
	float moveSpeed = 0.1f;
	if (mInput.getKeyboard()->isKeyDown(OIS::KC_A))
	{
		world.getSystemManager().getSystem<CameraSystem>()->moveRight(world.getEntity(0), -(moveSpeed / 2));
	}
	else if (mInput.getKeyboard()->isKeyDown(OIS::KC_D))
	{
		world.getSystemManager().getSystem<CameraSystem>()->moveRight(world.getEntity(0), (moveSpeed / 2));
	}
	if (mInput.getKeyboard()->isKeyDown(OIS::KC_S))
	{
		world.getSystemManager().getSystem<CameraSystem>()->moveForward(world.getEntity(0), -moveSpeed);
	}
	else if (mInput.getKeyboard()->isKeyDown(OIS::KC_W))
	{
		world.getSystemManager().getSystem<CameraSystem>()->moveForward(world.getEntity(0), moveSpeed);
	}
	else if (mInput.getKeyboard()->isKeyDown(OIS::KC_R))
	{
		world.getEntity(1).getComponent<Light>()->direction += vmVector3(0.0f, 0.001f, 0.0f);
	}
	else if (mInput.getKeyboard()->isKeyDown(OIS::KC_E))
	{
		world.getEntity(1).getComponent<Light>()->direction += vmVector3(0.0f, -0.001f, 0.0f);
	}
}
Пример #3
0
  ColorRGBAf::ColorRGBAf(ui32 rgba)
    : vmVector4(
      UI8_AS_R32((ui8)((rgba & 0xFF000000) >> 24)), 
      UI8_AS_R32((ui8)((rgba & 0x00FF0000) >> 16)), 
      UI8_AS_R32((ui8)((rgba & 0x0000FF00) >> 8)),
      UI8_AS_R32((ui8)((rgba & 0x000000FF) >> 0)))
  {
  }

  /*static*/ ColorRGBAf ColorRGBAf::Blend(const ColorRGBAf& left, const ColorRGBAf& right, BlendingMode blendRGB/*= BlendingMode_Normal*/, BlendingMode alphaBlend /*= BlendingMode_Normal*/)
  {
    return ColorRGBAi::Blend(left.GetColorRGBAi(), right.GetColorRGBAi(), blendRGB, alphaBlend).GetColorRGBAf();
  }

  ////////////////////////////////////////////////////////////////////////////////////////////// ColorHSLf
  ColorHSLf::ColorHSLf()
    : vmVector3(0.0f, 0.0f, 0.0f)
  {
  }

  ColorHSLf::ColorHSLf(r32 h, r32 s, r32 l)
    : vmVector3(h, s, l)
  {
  }

  ////////////////////////////////////////////////////////////////////////////////////////////// ColorRGBf
  ColorRGBf::ColorRGBf()
    : vmVector3(0.0f, 0.0f, 0.0f)
  {
  }

  ColorRGBf::ColorRGBf(r32 r, r32 g, r32 b)
    : vmVector3(r, g, b)
  {
  }

  ColorRGBf::ColorRGBf(ui32 xrgb)
    : vmVector3(
      UI8_AS_R32((ui8)((xrgb & 0x00FF0000) >> 16)), 
      UI8_AS_R32((ui8)((xrgb & 0x0000FF00) >> 8)), 
      UI8_AS_R32((ui8)((xrgb & 0x000000FF) >> 0)))
  {
  }

  ////////////////////////////////////////////////////////////////////////////////////////////// ColorHSLi
  ColorHSLi::ColorHSLi()
    : h(0)
    , s(0)
    , l(0)
  {
  }

  ColorHSLi::ColorHSLi(ui8 h, ui8 s, ui8 l)
    : h(h)
    , s(s)
    , l(l)
  {
  }

  ////////////////////////////////////////////////////////////////////////////////////////////// ColorRGBi
  ColorRGBi::ColorRGBi()
    : r(0)
    , g(0)
    , b(0)
  {
  }

  ColorRGBi::ColorRGBi( ui8 r, ui8 g, ui8 b)
    : r(r)
    , g(g)
    , b(b)
  {
  }

  ColorRGBi::ColorRGBi( ui32 xrgb )
    : r((ui8)((xrgb & 0x00FF0000) >> 16))
    , g((ui8)((xrgb & 0x0000FF00) >> 8))
    , b((ui8)((xrgb & 0x000000FF) >> 0))
  {
  }

  /*static*/ ColorRGBi ColorRGBi::Blend(const ColorRGBi& left, const ColorRGBi& right, BlendingMode blendingMode /*= BlendingMode_Normal*/)
  {
    switch(blendingMode)
    {
    default:
      return ColorRGBi(gBlend(left.r, right.r, blendingMode), gBlend(left.g, right.g, blendingMode), gBlend(left.b, right.b, blendingMode));
    case BlendingMode_Hue:
    {
      ColorRGBi out(0, 0, 0);
      ChannelBlend_BlendHue(left, right, out, GetColorRGBi);
      return out;
    }
    case BlendingMode_Saturation:
    {
      ColorRGBi out(0, 0, 0);
      ChannelBlend_BlendSaturation(left, right, out, GetColorRGBi);
      return out;
    }
    case BlendingMode_Color:
    {
      ColorRGBi out(0, 0, 0);
      ChannelBlend_BlendColor(left, right, out, GetColorRGBi);
      return out;
    }
    case BlendingMode_Luminosity:
    {
      ColorRGBi out(0, 0, 0);
      ChannelBlend_BlendLuminosity(left, right, out, GetColorRGBi);
      return out;
    }
    }
    return right;
  }

  ////////////////////////////////////////////////////////////////////////////////////////////// ColorRGBiImage
  ColorRGBiImage::ColorRGBiImage()
    : data(NULL)
    , width(0)
    , height(0)
  {
  }

  ColorRGBiImage::ColorRGBiImage(ui32 width, ui32 height, ColorRGBi data[])
    : data(data)
    , width(width)
    , height(height)
  {
  }

  ColorRGBiImage::~ColorRGBiImage()
  {
  }

  /*static*/ ColorRGBiImage ColorRGBiImage::Blend(const ColorRGBiImage& left, const ColorRGBiImage& right, ui32 x, ui32 y, BlendingMode blendingMode /*= BlendingMode_Normal*/)
  {
    ColorRGBiImage blended;
    blended.data = (ColorRGBi*)malloc(sizeof(ColorRGBi)*left.width*left.height);
    blended.width = left.width;
    blended.height = left.height;

    for(ui32 i = 0; i < left.width; ++i)
    {
      for(ui32 j = 0; j < left.height; ++j)
      {
        if(i < x || j < y)
        {
          // Just pick the left image for these pixels.
          ui32 index = i + (j*left.width);
          blended.data[index] = left.data[index];
          continue;
        }

        if(i-x > right.width || j-y > right.height)
          continue;
        ui32 index = i + (j*left.width);
        ui32 rindex = (i-x) + ((j-y)*right.width);
        blended.data[index] = ColorRGBi::Blend(left.data[index], right.data[rindex], blendingMode);
      }
    }
    return blended;
  }
Пример #4
0
	//---------------------------------------------------------------------
	vmVector3 MappingsD3D9::convertD3DXVector3(const D3DXVECTOR3& v)
	{
		return vmVector3(v.x, v.y, v.z);
	}
Пример #5
0
VertexBFaceATest(
	bool & inVoronoi,
	float & t0,
	float & t1,
	const vmVector3 & hA,
	PE_REF(vmVector3) faceOffsetAB,
	PE_REF(vmVector3) faceOffsetBA,
	const vmMatrix3 & matrixAB,
	const vmMatrix3 & matrixBA,
	PE_REF(vmVector3) signsB,
	PE_REF(vmVector3) scalesB )
{
	// compute a corner of box B in A's coordinate system

	vmVector3 corner =
		vmVector3( faceOffsetAB + matrixAB.getCol0() * scalesB.getX() + matrixAB.getCol1() * scalesB.getY() );

	// compute the parameters of the point on A, closest to this corner

	t0 = corner[0];
	t1 = corner[1];

	if ( t0 > hA[0] )
		t0 = hA[0];
	else if ( t0 < -hA[0] )
		t0 = -hA[0];
	if ( t1 > hA[1] )
		t1 = hA[1];
	else if ( t1 < -hA[1] )
		t1 = -hA[1];