Пример #1
0
// DRAG GENERATOR - OVERLOADED UpdateForce - Applies drag.
void ParticleDrag::UpdateForce(Particle* particle, marb duration) {
	Vector3 force;
	force = particle->GetVelocity();

	// Calculate total drag coefficient
	marb dragCoeff = force.Magnitude();
	dragCoeff = k1 * dragCoeff + k2 * dragCoeff * dragCoeff;

	// Calculate and apply final force
	force.Normalize();
	force *= -dragCoeff;
	particle->AddForce(force);
}
Пример #2
0
void EditorLoader::AddTrigger()
{
	Trigger* pTrigger(new Trigger());

	pTrigger->Init(m_pPhysXEngine, Vector3(2,2,2));

	Vector3 look = m_pRenderContext->GetCamera()->GetLook();
	look.Normalize();

	pTrigger->SetPosition(m_pRenderContext->GetCamera()->GetPosition() + look * 2);

	m_pLevel->AddLevelObject(pTrigger);
}
Пример #3
0
bool Camera::IsLookingAt(const Vector3& point, const float halfAngle, const float cutoffDistance) const
{
	Vector3 pointFromCamera = point - ReturnPosition();
	float length = pointFromCamera.Length();
	pointFromCamera.Normalize();
	Vector3 target = GetTarget();
	float actualHalfAngle = abs(acos(pointFromCamera.Dot(target)));
	if(actualHalfAngle <= Math::DegreeToRadian(halfAngle) && length <= cutoffDistance)
	{
		return true;
	}
	return false;
}
Пример #4
0
void RenderHelper::DrawCircle3D(const Vector3 & center, const Vector3 &emissionVector, float32 radius, bool useFilling)
{
	Polygon3 pts;
    float32 angle = SEGMENT_LENGTH / radius;
	int ptsCount = (int)(PI_2 / (DegToRad(angle))) + 1;

	for (int k = 0; k < ptsCount; ++k)
	{
		float32 angleA = ((float)k / (ptsCount - 1)) * PI_2;
		float sinAngle = 0.0f;
		float cosAngle = 0.0f;
		SinCosFast(angleA, sinAngle, cosAngle);

		Vector3 directionVector(radius * cosAngle,
								radius * sinAngle,
								0.0f);
		
		// Rotate the direction vector according to the current emission vector value.
		Vector3 zNormalVector(0.0f, 0.0f, 1.0f);
		Vector3 curEmissionVector = emissionVector;
		curEmissionVector.Normalize();
		
		// This code rotates the (XY) plane with the particles to the direction vector.
		// Taking into account that a normal vector to the (XY) plane is (0,0,1) this
		// code is very simplified version of the generic "plane rotation" code.
		float32 length = curEmissionVector.Length();
		if (FLOAT_EQUAL(length, 0.0f) == false)
		{
			float32 cosAngleRot = curEmissionVector.z / length;
			float32 angleRot = acos(cosAngleRot);
			Vector3 axisRot(curEmissionVector.y, -curEmissionVector.x, 0);

			Matrix3 planeRotMatrix;
			planeRotMatrix.CreateRotation(axisRot, angleRot);
			Vector3 rotatedVector = directionVector * planeRotMatrix;
			directionVector = rotatedVector;
		}
		
		Vector3 pos = center - directionVector;
		pts.AddPoint(pos);
	}
	
	if (useFilling)
	{
		FillPolygon(pts);
	}
	else
	{
    	DrawPolygon(pts, false);
	}
}
Пример #5
0
Color<real> BlinnPhongShader<real>::GetDiffuseAndSpecular( const Light<real>& light )
{
    Color<real> finalColor( 0, 0, 0, 1 );

    ////////////////////////////////////////////
    //////////////////IFT 3355//////////////////
    ////////////////////////////////////////////
    //Ici, vous calculerez les composantes
    //diffuse et spéculaire en vous servant des
    //propriétés du matériau.
    ////////////////////////////////////////////
    //////////////////IFT 3355//////////////////
    ////////////////////////////////////////////

    Vector3<real> lightPos = light.GetGlobalPosition();
    Vector3<real> lightDir = (lightPos - mIntersection.GetPosition()).Normalized();
    real r2 = (mIntersection.GetPosition() - lightPos).SquaredLength();
    Vector3<real> intersectionShifted = mIntersection.GetPosition() + EPS*mIntersection.GetNormal();

    // Shadow+Diffuse
    bool lightVisible = mRayTracer.IsLightVisible(intersectionShifted, &light);
    if (!lightVisible)
        return finalColor;

    switch (light.GetLightType()) {
    case Light<real>::TypeDirectional:
    case Light<real>::TypeSpot:
    case Light<real>::TypePoint:
        finalColor += mMaterial.GetDiffuse() *
            std::max<real>(0, lightDir * mIntersection.GetNormal()) *
            GetMaterialSurfaceColor();
        break;
    }

    // Specular
    const Camera<real> *cam = mScene.GetActiveCamera();
    Vector3<real> camDir = cam->GetFrontDirection();
    Vector3<real> H = lightDir + camDir;
    H.Normalize();
    Vector3<real> N = mIntersection.GetNormal();
    real n = mMaterial.GetShininess();
    real cs = (n+2)/2;
    Color<real> ks = mMaterial.GetSpecular();
    Color<real> m = mMaterial.GetMetallic();

    finalColor += cs * ks *
        (m*GetMaterialSurfaceColor() + (Color<real>(1, 1, 1, 1) - m)) *
        pow(N * H, n);

    return finalColor * light.GetIntensity() / (r2 * PI);
}
Пример #6
0
void CalculateNormals(vector<VertexPosNormTanTex>& vertices, const vector<DWORD>& indices)
{
    DWORD numTris = indices.size() / 3;
    for (DWORD i = 0; i < numTris; ++i)
    {
        Vector3 normal;

        const Vector3& pos1 = vertices[indices[i * 3]].position, 
                       pos2 = vertices[indices[i * 3 + 1]].position, 
                       pos3 = vertices[indices[i * 3 + 2]].position;

        Vector3 v1 = pos2 - pos1;
        Vector3 v2 = pos3 - pos1;
        v1.Normalize();
        v2.Normalize();
        Vector3 cross = v1.Cross(v2);
        cross.Normalize();

        /*vertices[indices[i * 3 + 0]].normal += cross;
        vertices[indices[i * 3 + 1]].normal += cross;
        vertices[indices[i * 3 + 2]].normal += cross;*/

        if (vertices[indices[i * 3 + 0]].normal == Vector3::Zero)
            vertices[indices[i * 3 + 0]].normal = cross;
        else
        {
            vertices[indices[i * 3 + 0]].normal += cross;
            vertices[indices[i * 3 + 0]].normal.Normalize();
        }

        if (vertices[indices[i * 3 + 1]].normal == Vector3::Zero)
            vertices[indices[i * 3 + 1]].normal = cross;
        else
        {
            vertices[indices[i * 3 + 1]].normal += cross;
            vertices[indices[i * 3 + 1]].normal.Normalize();
        }

        if (vertices[indices[i * 3 + 2]].normal == Vector3::Zero)
            vertices[indices[i * 3 + 2]].normal = cross;
        else
        {
            vertices[indices[i * 3 + 2]].normal += cross;
            vertices[indices[i * 3 + 2]].normal.Normalize();
        }
    }
    /*for_each(vertices.begin(), vertices.end(), [](VertexPosNormTanTex& vpnt)
    {
        vpnt.normal.Normalize();
    });*/
}
Пример #7
0
Quaternion::Quaternion( Radian angle, const Vector3& axis )
{
  MATH_INCREASE_BY(PerformanceMonitor::FLOAT_POINT_MULTIPLY,4);

  Vector3 tmpAxis = axis;
  tmpAxis.Normalize();
  const float halfAngle = angle.radian * 0.5f;
  const float sinThetaByTwo = sinf(halfAngle);
  const float cosThetaByTwo = cosf(halfAngle);
  mVector.x = tmpAxis.x * sinThetaByTwo;
  mVector.y = tmpAxis.y * sinThetaByTwo;
  mVector.z = tmpAxis.z * sinThetaByTwo;
  mVector.w = cosThetaByTwo;
}
Quaternion Quaternion::FromAxisAngle(Vector3 axis, double angle)
{
	double length = axis.Magnitude;

	if (length < Tolerance)
		return Quaternion(0, 0, 0, 1);

	axis.Normalize();

	double cosine = Math::Cos(angle / 2.0);
	double sine = Math::Sin(angle / 2.0);

	return Quaternion(sine * axis.X, sine * axis.Y, sine * axis.Z, cosine);
}
Пример #9
0
void Camera3::Init(const Vector3& pos, const Vector3& target, const Vector3& up)
{
	this->position = defaultPosition = pos;
	this->target = defaultTarget = target;
	Vector3 view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	this->up = defaultUp = right.Cross(view).Normalized();

	// Initialise the camera movement flags
	for (int i = 0; i < 255; i++)
		myKeys[i] = false;
}
Пример #10
0
	//	動くオブジェクトの反射
	bool	Collision::GetReflect( iexMesh* org, Vector3& pos, Vector3& vec, float rate ) 
	{
		// オブジェクトの逆行列を算出
		org->Update();
		Matrix mat = org->TransMatrix;
		Matrix invMat;	// 逆行列
		D3DXMatrixInverse( &invMat, null, &mat );

		// 逆行列でレイをローカル化
		Vector3 invVec;
		invVec.x = invMat._11 * vec.x + invMat._21 * vec.y + invMat._31 * vec.z;
		invVec.y = invMat._12 * vec.x + invMat._22 * vec.y + invMat._32 * vec.z;
		invVec.z = invMat._13 * vec.x + invMat._23 * vec.y + invMat._33 * vec.z;

		Vector3 invPos;
		invPos.x = invMat._11 * pos.x + invMat._21 * pos.y + invMat._31 * pos.z + invMat._41;
		invPos.y = invMat._12 * pos.x + invMat._22 * pos.y + invMat._32 * pos.z + invMat._42;
		invPos.z = invMat._13 * pos.x + invMat._23 * pos.y + invMat._33 * pos.z + invMat._43;

		Vector3 v = invVec;
		Vector3 p = invPos;
		Vector3 out;
		float d = 100.0f;
		if ( org->RayPick( &out, &p, &v, &d ) >= 0 )
		{
			Vector3 vv = out - p;
			float dd = vv.Length();
			float dm = invVec.Length();
			if ( dd < dm ){
				v.Normalize();		//	法線算出			
				float dot = Vector3Dot( -invVec, v );	// 法線方向に射影
				invVec = v*dot*2.0f - ( -invVec );

				Vector3 p;
				p.x = mat._11 * out.x + mat._21 * out.y + mat._31 * out.z + mat._41;
				p.y = mat._12 * out.x + mat._22 * out.y + mat._32 * out.z + mat._42;
				p.z = mat._13 * out.x + mat._23 * out.y + mat._33 * out.z + mat._43;
				pos = p;

				Vector3 v;
				v.x = mat._11 * invVec.x + mat._21 * invVec.y + mat._31 * invVec.z;
				v.y = mat._12 * invVec.x + mat._22 * invVec.y + mat._32 * invVec.z;
				v.z = mat._13 * invVec.x + mat._23 * invVec.y + mat._33 * invVec.z;
				vec = v*rate;

				return true;
			}
		}
		return false;
	}
Пример #11
0
Matrix4 Entity::getLookAtMatrix(const Vector3 &loc, const Vector3 &upVector) {
	rebuildTransformMatrix();
	Vector3 D;
	if(parentEntity)
		D = loc - (parentEntity->getConcatenatedMatrix() *position);		
	else
		D = loc - position;
	
	Vector3 back = D * -1;
	back.Normalize();
	
	Vector3 right = back.crossProduct(upVector) ;
	right.Normalize();
	right = right * -1;
	
	Vector3 up = back.crossProduct(right);
	
	Matrix4 newMatrix(right.x, right.y, right.z, 0, 
					  up.x, up.y, up.z, 0, 
					  back.x, back.y, back.z, 0,
					  0, 0 , 0, 1);		
	return newMatrix;
}
Пример #12
0
/********************************************************************************
LookDown
********************************************************************************/
void TPCamera::LookDown(const double dt)
{
	//float pitch = (float)(-CAMERA_SPEED * Application::camera_pitch * (float)dt);
	float pitch = (float)(CAMERA_SPEED * (float)dt);
	Vector3 view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	up = right.Cross(view).Normalized();
	Mtx44 rotation;
	rotation.SetToRotation(pitch, right.x, right.y, right.z);
	view = rotation * view;
	target = position + view;
}
Пример #13
0
void Arrow::Tick(float deltaTime)
{
    Super::Tick(deltaTime);
    UpdateWorldPos();
    
    Vector3 shippos = mPlayer->GetPosition();
    Vector3 checkpos = mCheckpointPos;
    Vector3 direction = checkpos - shippos;
    direction.Normalize();
    if( direction.x == 1 && direction.y == 0 && direction.z == 0)
    {
        SetRotation(Quaternion::Identity);
    }
    else
    {
        Vector3 axis = Cross(Vector3::UnitX,direction);
        float angle = Math::Acos(Dot(Vector3::UnitX,direction));
        axis.Normalize();
        Quaternion rotation(axis, angle);
        SetRotation(rotation);
        
    }
}
Пример #14
0
/********************************************************************************
Turn right
********************************************************************************/
void TPCamera::TurnRight(const double dt)
{
	Vector3 view = (target - position).Normalized();
	//	float yaw = (float)(-CAMERA_SPEED * Application::camera_yaw * (float)dt);
	float yaw = (float)(-CAMERA_SPEED * (float)dt);
	Mtx44 rotation;
	rotation.SetToRotation(yaw, 0, 1, 0);
	view = rotation * view;
	target = position + view;
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	up = right.Cross(view).Normalized();
}
Пример #15
0
//-------------------------------
//
//-------------------------------
void Vector3::GetQuaternion( Quaternion& qRot )
{
	Vector3		vDir;
	vDir.x = x;
	vDir.y = y;
	vDir.z = z;
	vDir.Normalize();
	vDir *= -1;

	Matrix44		matWorld;
	matWorld.SetWorld( Vector3( 0.0F, 0.0F, 0.0F ), vDir, Vector3( 0.0F, 0.0F, 1.0F ) );

	qRot = matWorld.GetQuaternion();	
} //Vector3::GetQuaternion
Пример #16
0
void FPcamera::lookUp(const double dt)
{
	float pitch = (float)(-TURN_SPEED * Application::camera_pitch * (float)dt);
	rotationX -= pitch;
	view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	up = right.Cross(view).Normalized();
	Mtx44 rotation;
	rotation.SetToRotation(pitch, right.x, right.y, right.z);
	view = rotation * view;
	target = position + view;
}
Пример #17
0
void FPcamera::lookRight(const double dt)
{
	view = (target - position).Normalized();
	float yaw = (float)(-TURN_SPEED * Application::camera_yaw * (float)dt);
	rotationY += yaw;
	Mtx44 rotation;
	rotation.SetToRotation(yaw, 0, 1, 0);
	view = rotation * view;
	target = position + view;
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	up = right.Cross(view).Normalized();
}
Пример #18
0
void Camera3::Init(const Vector3& pos, const Vector3& target, const Vector3& up, vector<Rock> *Rocks, Flag *flag, vector<CollisionObject> *Pillars)
{
	this->position = defaultPosition = pos;
	this->target = defaultTarget = target;
	Vector3 view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	MouseSensitivity = 0.2;
	this->up = defaultUp = right.Cross(view).Normalized();
	this->Rocks = Rocks;
	this->flag = flag;
	this->Pillars = Pillars;
}
Пример #19
0
//**************************************************
//				Lighting
//**************************************************
// 平行光
void Deferred::DirLight(const Vector3 dir, const Vector3 color)
{
	Matrix matV = matView;

	Vector3 LightDir;
	// ワールドの平行光を渡す
	Vector3 wLightDir = dir;
	wLightDir.Normalize();
	//shader->SetValue("wLightVec", wLightDir);

	//ビュー座標系に変換
	LightDir.x = dir.x * matV._11 + dir.y * matV._21 + dir.z * matV._31;
	LightDir.y = dir.x * matV._12 + dir.y * matV._22 + dir.z * matV._32;
	LightDir.z = dir.x * matV._13 + dir.y * matV._23 + dir.z * matV._33;


	LightDir.Normalize();

	//	シェーダー設定 shaderに送る
	shader->SetValue("ViewLightVec", LightDir);
	shader->SetValue("LightColor", (Vector3)color);

	//現在のレンダーターゲットを一時的に確保
	Surface* now = nullptr;
	tdnSystem::GetDevice()->GetRenderTarget(0, &now);

	//レンダーターゲットの切替え
	m_sLight->RenderTarget();
	m_sSpecular->RenderTarget(1);

	//	レンダリング
	m_mNormal->Render(0,0,shader, "DirLight");

	//レンダーターゲットの復元
	tdnSystem::GetDevice()->SetRenderTarget(0, now);
	tdnSystem::GetDevice()->SetRenderTarget(1, nullptr);
}
Пример #20
0
Quaternion RotationBetweenVectors3(Vector3 v1, Vector3 v2)
{
    const float epsilon = 0.0000001;

    double length1 = v1.Mag();
    double length2 = v2.Mag();
    double cosangle = (v1 * v2) / (length1 * length2);

    if (fabs(cosangle-1.0) < epsilon)
    {
        // near co-linear vectors
        return Quaternion(0.0, 0.0, 0.0, 1.0);
    }

    else if (fabs(cosangle+1.0) < epsilon)
    {
        // vectors are opposite, so we need to find an orthogonal vector to v1
        // around which to rotate

        Vector3 tmp;

        if (fabs(v1.x)<fabs(v1.y))
            if (fabs(v1.x)<fabs(v1.z))
                tmp = Vector3(1.0,0.0,0.0); // use x axis.
            else
                tmp = Vector3(0.0,0.0,1.0);
        else if (fabs(v1.y)<fabs(v1.z))
            tmp = Vector3(0.0,1.0,0.0);
        else
            tmp = Vector3(0.0,0.0,1.0);

        // find orthogonal axis.
        Vector3 axis = v2^tmp;
        axis.Normalize();

        // cos of half angle of PI is zero.
        return QuatFromAxis(axis, 0.0);
    }

    else {

        // this is the usual case: take a cross-product of v1 and v2
        // and that is the axis around which to rotate

        Vector3 axis = v1^v2;
        double angle = acos( cosangle );
        return QuatFromAxis(axis, angle);
    }
}
Пример #21
0
void CameraComponent::Tick(float deltaTime)
{
	Super::Tick(deltaTime);

	Vector3 ideal = ComputeIdealPosition();
	Vector3 displace = mCameraPos - ideal;
	Vector3 accel = (-mSpringConstant * displace) - (mDampConstant * mCameraVelocity);
	mCameraVelocity += accel * deltaTime;
	mCameraPos += mCameraVelocity * deltaTime;

	Vector3 shipPos = mOwner.GetWorldTransform().GetTranslation() +
		Vector3::UnitX * mTargetOffset;
	Vector3 forward = shipPos - mCameraPos;
	forward.Normalize();
	Vector3 left = Cross(Vector3::UnitZ, forward);
	left.Normalize();
	Vector3 up = Cross(forward, left);
	up.Normalize();

	mCameraMat = Matrix4::CreateLookAt(mCameraPos, shipPos, up);
	
	// Tell the renderer
	mOwner.GetGame().GetRenderer().UpdateViewMatrix(mCameraMat);
}
Пример #22
0
bool BoundingSphere::ContainsOther(const BoundingSphere & self, const BoundingSphere & other, Vector3 & toOther, Vector3 & otherFarEnd)
{

	if (self.getCenter() == other.getCenter())
	{
		return other.GetRadius() < self.GetRadius();
	}

	toOther = other.getCenter() - self.getCenter();
	toOther.Normalize();
	otherFarEnd = other.getCenter() + toOther*other.GetRadius();

	Vector3 toOtherFarEnd = otherFarEnd - self.getCenter();
	return toOtherFarEnd.Length2() < self.GetSquaredRadius();
}
Пример #23
0
void FPS_Cam::LookYaw(float yawValue, double dt)
{
	float mspeed = mouse_speed * yawValue;

	FaceDirection = (target - position).Normalized();
	Vector3 right = FaceDirection.Cross(up);
	right.y = 0;
	right.Normalize();
	up = right.Cross(FaceDirection).Normalized();
	rotation22.SetToRotation(mspeed * dt, 0, 1, 0);
	FaceDirection = rotation22 * FaceDirection;
	target = position + FaceDirection;

	up = rotation22 * up;
}
Пример #24
0
void FPcamera::lookDown(const double dt, float downValue)
{
	float pitch = (float)(-WALK_SPEED * Application::camera_pitch * (float)dt - downValue * (float)dt);
	recoil -= 5.f * (float)dt;;
	rotationX -= pitch;
	view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	up = right.Cross(view).Normalized();
	Mtx44 rotation;
	rotation.SetToRotation(pitch, right.x, right.y, right.z);
	view = rotation * view;
	target = position + view;
}
Пример #25
0
/********************************************************************************
Move the camera left
********************************************************************************/
void TPCamera::MoveLeft(const double dt)
{
	Vector3 view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();

	MoveVel_A = MoveVel_A + CAMERA_ACCEL * (float)dt;
	if (MoveVel_A < -CAMERA_SPEED)
		MoveVel_A = -CAMERA_SPEED;

	// Update the camera and target position
	position -= right * MoveVel_A;
	target -= right * MoveVel_A;
}
Пример #26
0
/********************************************************************************
LookRight
********************************************************************************/
void Camera3::LookRight(const double dt)
{
	float yaw = yawVelocity;
	Vector3 view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();
	up = right.Cross(view).Normalized();
	Mtx44 rotation;
	rotation.SetToRotation(yaw, 0, 1, 0);
	view = rotation * view;
	target = position + view;

	up = rotation * up;
}
Пример #27
0
void YoYoParticleModel::func(myState& preState, myState& resultState,float deltaT)
{
	resultState.pos = preState.vel*deltaT;

	Vector3 e = (m_yoyoParticle.m_position - m_topParticle.m_position);
	e.Normalize();
	Vector3 Fk = -m_stiffness*((m_yoyoParticle.m_position - m_topParticle.m_position).CalcLength() - m_stringLength) * e;
	Vector3 Fc = -m_cofficient * (DotProduct(e, (m_yoyoParticle.m_velocity - m_topParticle.m_velocity))) *e;
	Vector3 A = Fk + Fc - m_yoyoParticle.m_mass*m_gravityVector - m_stringCofficient*m_yoyoParticle.m_velocity;
	
	Vector3 delta_prev_velocity = A*deltaT;
	delta_prev_velocity.z = -m_gravityVector.z*deltaT;
	resultState.vel = delta_prev_velocity;
	
}
Пример #28
0
/********************************************************************************
Move the camera right
********************************************************************************/
void TPCamera::MoveRight(const double dt)
{
	Vector3 view = (target - position).Normalized();
	Vector3 right = view.Cross(up);
	right.y = 0;
	right.Normalize();

	MoveVel_D = MoveVel_D + CAMERA_ACCEL * (float)dt;
	if (MoveVel_D > CAMERA_SPEED)
		MoveVel_D = CAMERA_SPEED;

	// Update the camera and target position
	position += right * MoveVel_D;
	target += right * MoveVel_D;
}
Пример #29
0
T calcSkyVisibility(const COctreeNode *octree, const Vector3<T> &pos, const Vector3<T> &normal, const Vector3<T> &tangent, const Vector3<T> &bitangent,
                    size_t rayCount)
{
    size_t hitRays = 0;
    for(size_t i = 0; i < rayCount; ++i)
    {
        Vector3<T> rnd(randomFloat<T>(), randomFloat<T>()*T(2.0)-T(1.0), randomFloat<T>()*T(2.0)-T(1.0));
        rnd.Normalize();
        Vector3<T> raydir = normal * rnd.x + tangent * rnd.y + bitangent * rnd.z;
        CRay_t<T> ray(pos + raydir * T(0.01), raydir.Normalize());
        if(octree->rayTriangleCollision(ray))
            hitRays++;
    }
    return calcSkyVisibility(T(hitRays), T(rayCount));
}
Пример #30
-1
void ParticleEmitter3D::CalculateParticlePositionForCircle(Particle* particle, const Vector3& tempPosition,
														   const Matrix3& rotationMatrix)
{
	float32 curRadius = 1.0f;
	if (radius)
	{
		curRadius = radius->GetValue(time);
	}

	float32 curAngle = PI_2 * (float32)Random::Instance()->RandFloat();
	if (emitterType == EMITTER_ONCIRCLE_VOLUME)
	{
		// "Volume" means we have to emit particles from the whole circle.
		curRadius *= (float32)Random::Instance()->RandFloat();
	}

	float sinAngle = 0.0f;
	float cosAngle = 0.0f;
	SinCosFast(curAngle, sinAngle, cosAngle);

	Vector3 directionVector(curRadius * cosAngle,
							curRadius * sinAngle,
							0.0f);
		
	// Rotate the direction vector according to the current emission vector value.
	Vector3 zNormalVector(0.0f, 0.0f, 1.0f);
	Vector3 curEmissionVector;
	if (emissionVector)
	{
		curEmissionVector = emissionVector->GetValue(time);
		curEmissionVector.Normalize();
	}
		
	// This code rotates the (XY) plane with the particles to the direction vector.
	// Taking into account that a normal vector to the (XY) plane is (0,0,1) this
	// code is very simplified version of the generic "plane rotation" code.
	float32 length = curEmissionVector.Length();
	if (FLOAT_EQUAL(length, 0.0f) == false)
	{
		float32 cosAngleRot = curEmissionVector.z / length;
		float32 angleRot = acos(cosAngleRot);
		Vector3 axisRot(curEmissionVector.y, -curEmissionVector.x, 0);

		Matrix3 planeRotMatrix;
		planeRotMatrix.CreateRotation(axisRot, angleRot);
		Vector3 rotatedVector = directionVector * planeRotMatrix;
		directionVector = rotatedVector;
	}
		
	particle->position = tempPosition + TransformPerserveLength(directionVector, rotationMatrix);	
}