Exemplo n.º 1
0
void Scene::display() {
    // Set lighting
    light.setLighting();
    // Set background color
    glClearColor(backgroundColor[0],
                 backgroundColor[1],
                 backgroundColor[2],
                 backgroundColor[3]);
 	glColor3f(1,1,1);
    if (drawAxesOn) drawAxes(-(worldX/2)-5, -(worldY/2)-5, -(worldZ/2)-5);

    // Draw real time scene
    /*
    Thing thing;
    unsigned long nObjects = model.get_num_objects();
    Vec3 * p = 0;
    Vec3 * r = 0;
    double * a = 0;

    for (unsigned long i=0; i<nObjects; i++) {
        model.get_next_object_state(&p,&r,&a);
        if (p != 0) {
            thing.Cube(p->x, p->y, p->z,
                       0.4,0.4,0.4,
                       *a,p->x,p->y,p->z);
        }
        else { std::cout << "its zero" << std::endl;}
    }
    */
    // Draw box bounding the world
    WireframeCube(0,0,0,
                  worldX,worldY, worldZ,
                  0,0,0,0);

    // Draw recorded scene
    double radius = 1.0;
    FrameState * frame = reader.get_next_frame();
    if (frame != 0) {
        unsigned long nObjects = frame->get_num_objects();
        for (unsigned long i=0; i<nObjects; i++) {
            Object * o = frame->get_object(i);
            if (o != 0) {
                // Set color based on id
                int origin = o->getID() >> 28;
 	            glColor3f(colors[origin].x, colors[origin].y, colors[origin].z);


                // Draw an object from the animation record file
                //Cube(o->x(), o->y(), o->z(),
                //           0.4,0.4,0.4,
                //           o->a_r(),o->x_r(),o->y_r(),o->z_r());
                Sphere(o->x(), o->y(), o->z(), radius);
            }
        }
Exemplo n.º 2
0
TEST(IntersectTest, IntersectPTest) {

    Sphere sphere = Sphere(vec3(1,0,0), 1);

    Ray ray = Ray(vec3(-1,0,0), vec3(0,1,0), 0, 0, 100);
    EXPECT_FALSE(sphere.intersectP(ray));

    Ray ray2 = Ray(vec3(0,0,0), vec3(0,1,0), 0, 0, 100);
    EXPECT_TRUE(sphere.intersectP(ray2));

}
Exemplo n.º 3
0
void RayTracer::initVariables()
{
    // Camera
    CameraPositionPoint = vec3(0, 0, 0);
    CameraDirection = vec3(0, 0, -1);
    View_Plane = ViewPlane(-0.1, 0.1, -0.1, 0.1, 0.1);
    
    // World
    WorldDirection_u = vec3(1, 0, 0);
    WorldDirection_v = vec3(0, 1, 0);
    WorldDirection_w = vec3(0, 0, 1);
    
    // Object
    sphere01 = Sphere(vec3(-4, 0, -7), 1);
    sphere02 = Sphere(vec3(0, 0, -7), 2);
    sphere03 = Sphere(vec3(4, 0, -7), 1);
//    HorozonPlane = pla
    

}
Exemplo n.º 4
0
void FireFieldSpell::Update() {
	
	pPSStream.Update(g_framedelay);
	pPSStream1.Update(g_framedelay);
	
	EERIE_LIGHT * el = dynLightCreate(m_light);
	if(el) {
		el->pos = m_pos + Vec3f(0.f, -120.f, 0.f);
		el->intensity = 4.6f;
		el->fallstart = Random::getf(150.f, 180.f);
		el->fallend   = Random::getf(290.f, 320.f);
		el->rgb = Color3f(1.f, 0.8f, 0.6f) + Color3f(Random::getf(-0.1f, 0.f), 0.f, 0.f);
		el->duration = ArxDurationMs(600);
		el->extras=0;
	}
	
	if(VisibleSphere(Sphere(m_pos - Vec3f(0.f, 120.f, 0.f), 350.f))) {
		
		pPSStream.Render();
		pPSStream1.Render();
		
		float fDiff = g_framedelay / 8.f;
		int nTime = checked_range_cast<int>(fDiff);
		
		for(long nn=0;nn<=nTime+1;nn++) {
			
			PARTICLE_DEF * pd = createParticle();
			if(!pd) {
				break;
			}
			
			float t = Random::getf() * (glm::pi<float>() * 2.f) - glm::pi<float>();
			float ts = std::sin(t);
			float tc = std::cos(t);
			pd->ov = m_pos + Vec3f(120.f * ts, 15.f * ts, 120.f * tc) * randomVec();
			pd->move = Vec3f(2.f, 1.f, 2.f) + Vec3f(-4.f, -8.f, -4.f) * randomVec3f();
			pd->siz = 7.f;
			pd->tolive = Random::getu(500, 1500);
			pd->tc = fire2;
			pd->m_flags = ROTATING | FIRE_TO_SMOKE;
			pd->m_rotation = Random::getf(-0.1f, 0.1f);
			pd->scale = Vec3f(-8.f);
			
			PARTICLE_DEF * pd2 = createParticle();
			if(!pd2) {
				break;
			}
			
			*pd2 = *pd;
			pd2->delay = Random::getu(60, 210);
		}
		
	}
}
Exemplo n.º 5
0
void Extent::loadSphere( Iff & iff )
{
	iff.enterChunk(TAG_SPHR);

		Vector center = iff.read_floatVector();
		real radius = iff.read_float();

		setSphere( Sphere(center,radius) );

	iff.exitChunk(TAG_SPHR);
}
Exemplo n.º 6
0
EClipStatus CSensorVision::GetBoxClipStatus(CActor* pActor, const bbox3& Box) const
{
	//???check FOV too?
	sphere Sphere(pActor->Position, Radius);
	switch (Sphere.clipstatus(Box))
	{
		case sphere::Inside:	return Inside;
		case sphere::Clipped:	return Clipped;
		case sphere::Outside:
		default:				return Outside;
	}
}
Exemplo n.º 7
0
void test(){
  
  Sphere s = Sphere((vec3) {0.,0.,0}, 5., (Color) {100, 100, 100});
  Intersection i = s.intersects((vec3) {0,0,-10}, (vec3) {0,0,1});

  assertEqual(i.distance, 5., "Intersection distance");
  assertEqual(i.point, (vec3) {0,0,-5}, "Intersection point");
  assertEqual(i.normal, (vec3) {0,0,-1}, "Intersection normal");
  assertEqual(i.obj, &s, "Intersection object");
  

}
Exemplo n.º 8
0
    std::shared_ptr<RuntimeGameObject> RuntimeGameObject::Create(_In_ const std::shared_ptr<RuntimeGameWorld>& world, _In_ const std::map<std::wstring, std::wstring>& properties)
    {
        CHECK_NOT_NULL(g_gameObjectFactory);

        // Get details from the gameplay module
        GameObjectCreateParameters parameters = g_gameObjectFactory(world, properties);

        // Create base object with those parameters
        std::shared_ptr<RuntimeGameObject> object(GDKNEW RuntimeGameObject(world, parameters));

        // stash away these initial properties for later
        object->_initialProperties = properties;

        // do we have rigid body info? (requires a collision primitive)
        if (parameters.collisionPrimitive)
        {
            RigidBodyCreateParameters rigidBodyParams(parameters.position, 100.0f, parameters.collisionPrimitive.get());
            rigidBodyParams.type = PhysicsBodyTypeToRigidBodyType(parameters.physicsType);
            rigidBodyParams.gravityScale = (parameters.floating) ? 0.0f : 1.0f;
            object->_body = world->GetPhysicsWorld()->CreateBody(object, rigidBodyParams);
        }

        // if we're in the editor, let's create the picking mesh & sphere
        if (world->IsEditing())
        {
            std::vector<Triangle> triangles;
            Matrix identity = Matrix::Identity();

            auto& visuals = object->GetVisualInfos();
            if (visuals.size())
            {
                for (auto i = 0; i < visuals.size(); ++i)
                {
                    Collision::TriangleListFromGeometry(Content::LoadGeometryContent(visuals[i].geometry), identity, 0, triangles);
                }

                object->_triangleMesh = CollisionPrimitive::Create(TriangleMesh(SpacePartitionType::AabbTree, triangles));

                // loose sphere around the AABB. Not a best fit, but fast to compute and "good enough" as a pre-test
                Vector3 aabbMin, aabbMax;
                GetAabbForPrimitive(object->_triangleMesh.get(), &aabbMin, &aabbMax);
                object->_sphere = CollisionPrimitive::Create(Sphere((aabbMin + aabbMax) * 0.5f, (aabbMax - aabbMin).Length() * 0.5f));
            }
        }

        // Bind the object and controller, if one was provided
        if (parameters.controller)
        {
            parameters.controller->OnCreate(object);
        }

        return object;
    }
Exemplo n.º 9
0
void Light::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
{
    // Do not record a raycast result for a directional light, as it would block all other results
    if (lightType_ == LIGHT_DIRECTIONAL)
        return;

    float distance = query.maxDistance_;
    switch (query.level_)
    {
    case RAY_AABB:
        Drawable::ProcessRayQuery(query, results);
        return;

    case RAY_OBB:
        {
            Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
            Ray localRay = query.ray_.Transformed(inverse);
            distance = localRay.HitDistance(GetWorldBoundingBox().Transformed(inverse));
            if (distance >= query.maxDistance_)
                return;
        }
        break;

    case RAY_TRIANGLE:
        if (lightType_ == LIGHT_SPOT)
        {
            distance = query.ray_.HitDistance(GetFrustum());
            if (distance >= query.maxDistance_)
                return;
        }
        else
        {
            distance = query.ray_.HitDistance(Sphere(node_->GetWorldPosition(), range_));
            if (distance >= query.maxDistance_)
                return;
        }
        break;

    case RAY_TRIANGLE_UV:
        LOGWARNING("RAY_TRIANGLE_UV query level is not supported for Light component");
        return;
    }

    // If the code reaches here then we have a hit
    RayQueryResult result;
    result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
    result.normal_ = -query.ray_.direction_;
    result.distance_ = distance;
    result.drawable_ = this;
    result.node_ = node_;
    result.subObject_ = M_MAX_UNSIGNED;
    results.Push(result);
}
Exemplo n.º 10
0
//------------------------------------------------------------------------
void CVehicleDamageBehaviorBurn::Update(const float deltaTime)
{
	m_timeCounter -= deltaTime;

	if (m_timeCounter <= 0.0f)
	{
		CGameRules *pGameRules = g_pGame->GetGameRules();
		if (pGameRules && gEnv->bServer)
		{	
			Vec3 worldPos;
			if (m_pHelper)
				worldPos = m_pHelper->GetWorldTM().GetTranslation();
			else
				worldPos = m_pVehicle->GetEntity()->GetWorldTM().GetTranslation();

      SEntityProximityQuery query;
      query.box = AABB(worldPos-Vec3(m_radius), worldPos+Vec3(m_radius));
      gEnv->pEntitySystem->QueryProximity(query);

      IEntity* pEntity = 0;
      
			for (int i = 0; i < query.nCount; ++i)
			{				
				if ((pEntity = query.pEntities[i]) && pEntity->GetPhysics())
				{
          float damage = (pEntity->GetId() == m_pVehicle->GetEntityId()) ? m_selfDamage : m_damage;

					// SNH: need to check vertical distance here as the QueryProximity() call seems to work in 2d only
					Vec3 pos = pEntity->GetWorldPos();
					if(abs(pos.z - worldPos.z) < m_radius)
					{
						if (damage > 0.f)
						{
							HitInfo hitInfo(m_shooterId, pEntity->GetId(), m_pVehicle->GetEntityId(), -1, m_radius);
							hitInfo.damage = damage;
							hitInfo.pos = worldPos;
							hitInfo.type = pGameRules->GetHitTypeId("fire");

							pGameRules->ServerHit(hitInfo);
						}   
					}
				}
			}
			
			if (gEnv->pAISystem)
	      gEnv->pAISystem->RegisterDamageRegion(this, Sphere(worldPos, m_radius));
		}

		m_timeCounter = m_interval;
	}

  m_pVehicle->NeedsUpdate();
}
Exemplo n.º 11
0
void sph(double angle)
{
   GLfloat blue_mat[]  = { 1, 1, 0, 1 };

   glPushMatrix();
       glTranslatef(0.75, 0.0, 0);
       glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
       Sphere(1.0, 20, 20);
   glPopMatrix();

   glFinish();
}
Exemplo n.º 12
0
// Berechne die kleinste einschliessende Kugel fuer n Punkte, wobei
// die Punkte q1,q2 und q3 auf dem Rand der gesuchten Kugel liegen
Sphere Sphere::ses3(int n, std::vector<Vector3d>& p,Vector3d& q1,Vector3d& q2,Vector3d& q3) {  
    Sphere S(q1,q2,q3);


	///ADD YOUR CODE HERE!
    for(int i=0;i<n;i++){
      if((p[i]-S.center).length()>S.radius)
          S=Sphere(q1,q2,q3,p[i]);
    }

  return S;
}
Exemplo n.º 13
0
void Extent::loadSphere_old (Iff & iff )
{
	iff.enterChunk(TAG_CNTR);
		const Vector center = iff.read_floatVector();
	iff.exitChunk(TAG_CNTR);

	iff.enterChunk(TAG_RADI);
		const real  radius = iff.read_float();
	iff.exitChunk(TAG_RADI);

	setSphere(Sphere(center, radius));
}
Exemplo n.º 14
0
bool CScreensaverCyclone::Start()
{
  int i, j;

  std::string fraqShader = kodi::GetAddonPath("resources/shaders/frag.glsl");
  std::string vertShader = kodi::GetAddonPath("resources/shaders/vert.glsl");
  if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink())
    return false;

  gCycloneSettings.Load();

  srand((unsigned)time(nullptr));

  // Window initialization
  glViewport(X(), Y(), Width(), Height());

  glEnable(GL_DEPTH_TEST);
  glFrontFace(GL_CCW);
  glEnable(GL_CULL_FACE);
  glClearColor(0.0, 0.0, 0.0, 1.0);

  m_modelMat = glm::mat4(1.0f);
  m_projMat = glm::perspective(glm::radians(80.0f), (GLfloat)Height() / (GLfloat)Width(), 50.0f, 3000.0f);
  if (!rsRandi(500))  // Easter egg view
  {
    m_projMat = glm::rotate(m_projMat, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
    m_projMat = glm::translate(m_projMat, glm::vec3(0.0f, -(WIDTH * 2), 0.0f));
  }
  else  // Normal view
    m_projMat = glm::translate(m_projMat, glm::vec3(0.0f, 0.0f, -(WIDTH * 2)));

  Sphere(float(gCycloneSettings.dSize) / 4.0f, 3, 2);
  m_lightingEnabled = 1;

  // Initialize cyclones and their particles
  for (i = 0; i < 13; i++)
    m_fact[i] = float(factorial(i));
  m_cyclones = new CCyclone*[gCycloneSettings.dCyclones];
  m_particles = new CParticle*[gCycloneSettings.dParticles * gCycloneSettings.dCyclones];
  for (i = 0; i < gCycloneSettings.dCyclones; i++)
  {
    m_cyclones[i] = new CCyclone;
    for (j=i*gCycloneSettings.dParticles; j<((i+1)*gCycloneSettings.dParticles); j++)
      m_particles[j] = new CParticle(m_cyclones[i]);
  }

  glGenBuffers(1, &m_vertexVBO);
  glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO);

  m_lastTime = kodi::time::GetTimeSec<double>();
  m_startOK = true;
  return true;
}
Exemplo n.º 15
0
//================================================================================================//
void BrainCell::Spawn(Vec2 pos)
{
	IsActive = true;
	oPos = Pos = pos;
	frame = 0;
	fStartLife = fLife = 3;
	mSphere = Sphere(20,pos+Vec2(32,32));
	iTakeDamageTicks = 0;

	iAttackTicks = 0;
	pulsate = 0;
}
Exemplo n.º 16
0
// Berechne die kleinste einschliessende Kugel fuer n Punkte,
Sphere Sphere::ses0(int n,std::vector<Vector3d>& p) {

    Sphere S = Sphere(p[0]);
    for(int i=1;i<n;i++){
      if((p[i]-S.center).length()>S.radius){
          S=ses1(i,p,p[i]);
      }
    }

	///ADD YOUR CODE HERE!

	return S;
}
Exemplo n.º 17
0
int
main (int argn, char **argc)
{
  double x, y;
  FILE *file;
  file = fopen (argc[1], "r");
  fscanf (file, "%*s%lf%*s%lf", &x, &y);
  fclose (file);
  file = fopen (argc[2], "w");
  fprintf (file, "%.14le", Sphere (x - M_PI_4, y - M_PI_4));
  fclose (file);
  return 0;
}
Exemplo n.º 18
0
//==============================================================================
Sphere Sphere::getCompoundShape(const Sphere& b) const
{
	const Sphere& a = *this;

	/// TODO test this
	/*
	Vec3 centerDiff = b.center - a.center;
	F32 radiusDiff = b.radius - a.radius;
	Vec3 radiusDiffSqr = radiusDiff * radiusDiff;
	F32 lenSqr = centerDiff.getLengthSquared();

	if(radiusDiffSqrt >= 0.0)
	{
		if(radiusDiff >= 0.0)
		{
			return b;
		}
		else
		{
			return a;
		}
	}
	else
	{
		F32 l = sqrt(lenSqr);
		F32 t = (l + b.radius - a.radius) / (2.0 * l);
		return Sphere(a.center + t * centerDiff, (l + a.radius + b.radius) /
			2.0);
	}
	*/

	Vec4 c = b.getCenter() - a.getCenter(); // Vector from one center to the
	                                        // other
	F32 cLen = c.getLength();

	if(cLen + b.getRadius() < a.getRadius())
	{
		return a;
	}
	else if(cLen + a.getRadius() < b.getRadius())
	{
		return b;
	}

	Vec4 bnorm = c / cLen;

	Vec4 ca = (-bnorm) * a.getRadius() + a.getCenter();
	Vec4 cb = (bnorm) * b.getRadius() + b.getCenter();

	return Sphere((ca + cb) / 2.0, (ca - cb).getLength() / 2.0);
}
Exemplo n.º 19
0
void Scene::parseLineForSphere(std::string line, Sphere &sphere, const int &material_offset) {

    std::vector<std::string> parts;            // vector for ;-seperated variables

    strsplit(line, ';', parts);        // split line
    if (parts.size() != 3) {
        std::cout << "parseLineForSphere error in line: " << line << std::endl;
        return;
    }
    else {
        Vector3 center = strtoVect(parts[0]);
        float radius = lexical_cast<float>(parts[1]);
        int matID = lexical_cast<int>(parts[2]) + material_offset;

        if (matID >= nummats) {
            cout << "specified material does not exist! Replaced by default" << endl;
            sphere = Sphere(center, radius, &stdDiffuse);
        }
        else {
            sphere = Sphere(center, radius, &materials[matID]);
        }
    }
}
Exemplo n.º 20
0
int
main (int argn __attribute__ ((unused)), char **argc)
{
  FILE *file;
  double x, y;
  file = fopen (argc[1], "r");
  if (fscanf (file, "%*s%lf%*s%lf", &x, &y) != 2)
    return 1;
  fclose (file);
  file = fopen (argc[2], "w");
  fprintf (file, "%.14le", Sphere (x - M_PI_4, y - M_PI_4));
  fclose (file);
  return 0;
}
bool StickyTrap::Initialize(DirectX::XMFLOAT3 p_startPosition, DirectX::XMFLOAT3 p_endPosition, unsigned int p_stickyTrapID, RakNet::RakNetGUID p_guid)
{
	m_stickyTrapBag = new Object();
	m_stickyTrapBag->Initialize("../Shurikenjutsu/Models/StickyTrapJar.SSP", p_startPosition);

	m_stickyTrap = new Object();
	int randomModel = std::rand() % 4 + 1;
	if (randomModel == 1)
	{
		m_stickyTrap->Initialize("../Shurikenjutsu/Models/StickyTrap1Shape.SSP", p_endPosition);
	}
	else if (randomModel == 2)
	{
		m_stickyTrap->Initialize("../Shurikenjutsu/Models/StickyTrap2Shape.SSP", p_endPosition);
	}
	else 
	{
		m_stickyTrap->Initialize("../Shurikenjutsu/Models/StickyTrap3Shape.SSP", p_endPosition);
	}

	int randomY = std::rand() % 8;
	m_stickyTrap->SetRotation(DirectX::XMFLOAT3(0.0f,(float)randomY,0.0f));

	m_startPosition = p_startPosition;
	m_isThrowing = true;
	m_stickyTrapSphere = Sphere(p_endPosition, STICKY_TRAP_RADIUS);
	m_StickyTrapID = p_stickyTrapID;

	m_speed = STICKY_TRAP_SPEED;
	float x = (p_endPosition.x - p_startPosition.x);
	float z = (p_endPosition.z - p_startPosition.z);
	float length = sqrtf(x*x + z*z);
	m_percentX = x / length;
	m_percentZ = z / length;
	m_angle = asinf((9.82f * length) / (m_speed * m_speed)) * 0.5f;

	m_guid = p_guid;

	m_stickyParticles = new ParticleEmitter();
	m_stickyParticles->Initialize(GraphicsEngine::GetDevice(), p_endPosition, DirectX::XMFLOAT3(0.0f, 1.0f, 0.0f), DirectX::XMFLOAT2(0.2f, 0.2f), PARTICLE_PATTERN_BUBBLES);
	m_stickyParticles->SetEmitParticleState(true);

	m_trail = new Trail();
	if (!m_trail->Initialize(50.0f, 0.2f, 0.2f, DirectX::XMFLOAT4(0.83f, 0.86f, 0.06f, 1.0f), "../Shurikenjutsu/2DTextures/Particles/Trail.png"))
	{
		ConsolePrintErrorAndQuit("A sticky trap trail failed to initialize!");
	}

	return true;
}
Exemplo n.º 22
0
Sphere Frustum::bounding_sphere() const
{
	Vec3f mi = near[0];
	Vec3f ma = near[0];
	for (int i = 0; i < 4; i++) {
		mi = min(near[i], mi);
		ma = max(near[i], ma);
		mi = min(far[i], mi);
		ma = max(far[i], ma);
	}
	const Vec3f center = mi + (ma - mi) / Vec3f(2);
	const float radius = distance(ma, center);
	return Sphere(center, radius);
}
Exemplo n.º 23
0
bool Ellipsoid::Intersects(const Segment& s, CollisionInfo* const pInfo) const {
  Vector InvExtents = 1.0f / m_Extents;
  Segment ScaledSegment(s.m_Point1 * InvExtents, s.m_Point2 * InvExtents);
  if (Sphere(m_Center * InvExtents, 1.0f).Intersects(ScaledSegment, pInfo)) {
    if (pInfo) {
      pInfo->m_Intersection *= m_Extents;
      pInfo->m_Plane =
          Plane((pInfo->m_Plane.m_Normal * InvExtents).GetNormalized(),
                pInfo->m_Intersection);
    }
    return true;
  }
  return false;
}
void Deferred_lighting_renderer::render_light_probe(const scene::Light_probe& light_probe, const Rendering_context& context)
{
	const float4x4& world = light_probe.world_transformation();

	OBB obb(world);

	const auto& camera = context.camera();

	if (Intersection_type::Outside == camera.frustum().intersect(obb))
	{
		return;
	}

	Rendering_device& device = rendering_tool_.device();

	auto& change_per_light_data = change_per_light_.data();
	change_per_light_data.world = world;
	change_per_light_data.light_transformation = invert(world * camera.view());
	change_per_light_data.position_vs = light_probe.world_position() * camera.view();
	change_per_light_.update(device);

	device.set_shader_resources(1, &light_probe.texture(), light_probe_texture_offset_);

	techniques_.volume_light_probe_specular->use();

	if (Intersection_type::Outside != Sphere(camera.world_position(), camera.greatest_distance_to_near_plane()).intersect(obb))
	{
		// camera is inside the light volume

		device.set_rasterizer_state(lighting_rasterizer_states_[Cull_state::Front]);
		device.set_depth_stencil_state(inside_lighting_volume_ds_state_light_, 1);
	}
	else
	{
		// camera is outside the light volume

		device.set_rasterizer_state(lighting_rasterizer_states_[Cull_state::Back]);
		device.set_depth_stencil_state(outside_lighting_volume_ds_state_prepare_, 1);
		device.set_blend_state(z_only_blend_state_);

		box_volume_.render(rendering_tool_);

		device.set_rasterizer_state(lighting_rasterizer_states_[Cull_state::Front]);
		device.set_depth_stencil_state(outside_lighting_volume_ds_state_light_, 2);
	}

	device.set_blend_state(lighting_blend_state_);

	box_volume_.render(rendering_tool_);
}
Exemplo n.º 25
0
    //-----------------------------------------------------------------------
    bool Light::isInLightRange(const Ogre::AxisAlignedBox& container) const
    {
        bool isIntersect = true;
        //Check the 2 simple / obvious situations. Light is directional or light source is inside the container
        if ((mLightType != LT_DIRECTIONAL) && (container.intersects(mDerivedPosition) == false))
        {
            //Check that the container is within the sphere of the light
            isIntersect = Math::intersects(Sphere(mDerivedPosition, mRange),container);
            //If this is a spotlight, do a more specific check
            if ((isIntersect) && (mLightType == LT_SPOTLIGHT) && (mSpotOuter.valueRadians() <= Math::PI))
            {
                //Create a rough bounding box around the light and check if
                Quaternion localToWorld = Vector3::NEGATIVE_UNIT_Z.getRotationTo(mDerivedDirection);

                Real boxOffset = Math::Sin(mSpotOuter * 0.5) * mRange;
                AxisAlignedBox lightBoxBound;
                lightBoxBound.merge(Vector3::ZERO);
                lightBoxBound.merge(localToWorld * Vector3(boxOffset, boxOffset, -mRange));
                lightBoxBound.merge(localToWorld * Vector3(-boxOffset, boxOffset, -mRange));
                lightBoxBound.merge(localToWorld * Vector3(-boxOffset, -boxOffset, -mRange));
                lightBoxBound.merge(localToWorld * Vector3(boxOffset, -boxOffset, -mRange));
                lightBoxBound.setMaximum(lightBoxBound.getMaximum() + mDerivedPosition);
                lightBoxBound.setMinimum(lightBoxBound.getMinimum() + mDerivedPosition);
                isIntersect = lightBoxBound.intersects(container);
                
                //If the bounding box check succeeded do one more test
                if (isIntersect)
                {
                    //Check intersection again with the bounding sphere of the container
                    //Helpful for when the light is at an angle near one of the vertexes of the bounding box
                    isIntersect = isInLightRange(Sphere(container.getCenter(), 
                        container.getHalfSize().length()));
                }
            }
        }
        return isIntersect;
    }
Exemplo n.º 26
0
HorizontalWidget::HorizontalWidget( QWidget* parent )
:QWidget( parent ), sphereRadio( 120.0 ), m_azimuth( 0 ), m_zenith( 0 )
{
	QVBoxLayout* mainLayout = new QVBoxLayout;
	setLayout( mainLayout );

	QWidget* examinerWidget = new QWidget;
	examinerWidget->setFixedSize( 490, 300 );
	mainLayout->addWidget(examinerWidget);

	m_rootNode = new SoSeparator;

	m_rootNode->addChild( Ejes( ) );
	m_rootNode->addChild( Text() );
    m_rootNode->addChild( Sphere() );
   	m_rootNode->addChild( Horizon() );
   	m_rootNode->addChild( AzimuthLine() );
   	m_rootNode->addChild( ZenithLine() );
    m_rootNode->addChild( Star() );

	SoQtExaminerViewer* myRenderArea = new SoQtExaminerViewer( examinerWidget );
    myRenderArea->setSceneGraph( m_rootNode );
    SbColor col( 0.86f, 0.86f, 0.86f );
    myRenderArea->setBackgroundColor(col);
    myRenderArea->show(  );

     QWidget* labelsWidget = new QWidget;
    mainLayout->addWidget( labelsWidget );

 	QGridLayout* labelsLayout = new QGridLayout;
 	labelsWidget->setLayout( labelsLayout );

 	QLabel* m_AzimuthLabel = new QLabel;
 	m_AzimuthLabel->setText( "Azimuth:" );
 	labelsLayout->addWidget( m_AzimuthLabel, 0, 0, 1, 1 );

	m_azimuthValue = new QLabel;
 	m_azimuthValue->setText( QString::number( m_azimuth ) );
 	labelsLayout->addWidget( m_azimuthValue, 0, 1, 1, 3  );

	QLabel* m_zenithLabel = new QLabel;
 	m_zenithLabel->setText( "Zenith:" );
 	labelsLayout->addWidget( m_zenithLabel, 1, 0, 1, 1 );

	m_zenithValue = new QLabel;
 	m_zenithValue->setText( QString::number( m_zenith ) );
 	labelsLayout->addWidget( m_zenithValue, 1, 1, 1, 3 );

}
Exemplo n.º 27
0
bool Ellipsoid::Intersects( const Triangle& t, CollisionInfo* const pInfo /*= NULL*/ ) const
{
	Vector InvExtents = 1.0f / m_Extents;
	Triangle ScaledTriangle( t.m_Vec1 * InvExtents, t.m_Vec2 * InvExtents, t.m_Vec3 * InvExtents );
	if( Sphere( m_Center * InvExtents, 1.0f ).Intersects( ScaledTriangle, pInfo ) )
	{
		if( pInfo )
		{
			pInfo->m_Intersection *= m_Extents;
			pInfo->m_Plane = Plane( ( pInfo->m_Plane.m_Normal * InvExtents ).GetNormalized(), pInfo->m_Intersection );
		}
		return true;
	}
	return false;
}
Exemplo n.º 28
0
Sphere Sphere::FromString(const char *str, const char **outEndStr)
{
	assume(str);
	if (!str)
		return Sphere(vec::nan, FLOAT_NAN);
	Sphere s;
	MATH_SKIP_WORD(str, "Sphere(");
	MATH_SKIP_WORD(str, "pos:(");
	s.pos = PointVecFromString(str, &str);
	MATH_SKIP_WORD(str, " r:");
	s.r = DeserializeFloat(str, &str);
	if (outEndStr)
		*outEndStr = str;
	return s;
}
Radiance3 RayTracer::L_scatteredIndirect(const shared_ptr<Surfel>& surfel, const Vector3& wo, Random& rnd) const{
    Radiance3 L(0,0,0);
    float r = m_settings.gatheringDistance;
    //Find the nearby photons
    Array<Photon> intersected;
    photons.getIntersectingMembers(Sphere(surfel->position, r), intersected);
    //Cone filter constant, set to 1 now. GUI option not implemented. (To change this, we need to add a max(0,filtered value) into code
    int k = 1;
    //Added the energy photon by photon
    for (int i = 0; i < intersected.size(); ++i){
        Photon p = intersected[i];
        L += ((p.power / (G3D::pi() * r * r)) * surfel->finiteScatteringDensity(PathDirection::EYE_TO_SOURCE, -p.direction, wo)) * (1 - (p.origin - surfel->position).magnitude()/(k*r)) / (1 - 2.0/(3.0*k));
    }
    return L;
}
Exemplo n.º 30
0
	virtual bool OverlapObjects_GiantSphereVsKP::CommonSetup()
	{
		TestBase::CommonSetup();
		LoadMeshesFromFile_(*this, "kp.bin");

		const Point Min(-9560.175781f, -1093.885132f, -9461.288086f);
		const Point Max(9538.423828f, 4906.125488f, 9637.304688f);
		const Point Center = (Max + Min)*0.5f;
		const Point Extents = (Max - Min)*0.5f;

//		RegisterSphereOverlap(Sphere(Center, Extents.Magnitude()*0.25f));
		RegisterSphereOverlap(Sphere(Center, 2500.0f));
		mCreateDefaultEnvironment = false;
		return true;
	}