Example #1
0
void PUParticle3DBoxRender::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
{
    //batch and generate draw
    const ParticlePool &particlePool = particleSystem->getParticlePool();
    if (!_isVisible || particlePool.empty())
        return;

    auto camera = Camera::getVisitingCamera();
    auto cameraMat = camera->getNodeToWorldTransform();
    Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]);

    if (_vertexBuffer == nullptr && _indexBuffer == nullptr) {
        GLsizei stride = sizeof(VertexInfo);
        _vertexBuffer = VertexBuffer::create(stride, 8 * particleSystem->getParticleQuota());
        if (_vertexBuffer == nullptr)
        {
            CCLOG("PUParticle3DBoxRender::render create vertex buffer failed");
            return;
        }
        _vertexBuffer->retain();
        _vertices.resize(8 * particleSystem->getParticleQuota());

        _indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, 36 * particleSystem->getParticleQuota());
        if (_indexBuffer == nullptr)
        {
            CCLOG("PUParticle3DBoxRender::render create index buffer failed");
            return;
        }
        _indexBuffer->retain();
        _indices.resize(36 * particleSystem->getParticleQuota());
        reBuildIndices(particleSystem->getParticleQuota());
    }

    unsigned int vertexindex = 0;
    unsigned int index = 0;
    Mat4 texRot;
    Vec3 val;
    for (auto iter : particlePool.getActiveDataList())
    {
        auto particle = static_cast<PUParticle3D *>(iter);
        float halfHeight = particle->height * 0.5f;
        float halfWidth = particle->width * 0.5f;
        float halfDepth = particle->depth * 0.5f;
        Mat4::createRotation(backward, particle->zRotation, &texRot);
        val = texRot * Vec3(0.0f, 0.75f, 0.0);
        _vertices[vertexindex + 0].position = particle->position + Vec3(-halfWidth, -halfHeight, halfDepth);
        _vertices[vertexindex + 0].color = particle->color;
        _vertices[vertexindex + 0].uv.x = val.x;
        _vertices[vertexindex + 0].uv.y = val.y;
        val = texRot * Vec3(0.0f, 0.25f, 0.0);
        _vertices[vertexindex + 1].position = particle->position + Vec3(halfWidth, -halfHeight, halfDepth);
        _vertices[vertexindex + 1].color = particle->color;
        _vertices[vertexindex + 1].uv.x = val.x;
        _vertices[vertexindex + 1].uv.y = val.y;
        val = texRot * Vec3(0.5f, 0.25f, 0.0);
        _vertices[vertexindex + 2].position = particle->position + Vec3(halfWidth, halfHeight, halfDepth);
        _vertices[vertexindex + 2].color = particle->color;
        _vertices[vertexindex + 2].uv.x = val.x;
        _vertices[vertexindex + 2].uv.y = val.y;
        val = texRot * Vec3(0.5f, 0.75f, 0.0);
        _vertices[vertexindex + 3].position = particle->position + Vec3(-halfWidth, halfHeight, halfDepth);
        _vertices[vertexindex + 3].color = particle->color;
        _vertices[vertexindex + 3].uv.x = val.x;
        _vertices[vertexindex + 3].uv.y = val.y;

        val = texRot * Vec3(0.0f, 0.0f, 0.0);
        _vertices[vertexindex + 4].position = particle->position + Vec3(halfWidth, -halfHeight, -halfDepth);
        _vertices[vertexindex + 4].color = particle->color;
        _vertices[vertexindex + 4].uv.x = val.x;
        _vertices[vertexindex + 4].uv.y = val.y;
        val = texRot * Vec3(0.0f, 1.0f, 0.0);
        _vertices[vertexindex + 5].position = particle->position + Vec3(-halfWidth, -halfHeight, -halfDepth);
        _vertices[vertexindex + 5].color = particle->color;
        _vertices[vertexindex + 5].uv.x = val.x;
        _vertices[vertexindex + 5].uv.y = val.y;
        val = texRot * Vec3(0.5f, 1.0f, 0.0);
        _vertices[vertexindex + 6].position = particle->position + Vec3(-halfWidth, halfHeight, -halfDepth);
        _vertices[vertexindex + 6].color = particle->color;
        _vertices[vertexindex + 6].uv.x = val.x;
        _vertices[vertexindex + 6].uv.y = val.y;
        val = texRot * Vec3(0.5f, 0.0f, 0.0);
        _vertices[vertexindex + 7].position = particle->position + Vec3(halfWidth, halfHeight, -halfDepth);
        _vertices[vertexindex + 7].color = particle->color;
        _vertices[vertexindex + 7].uv.x = val.x;
        _vertices[vertexindex + 7].uv.y = val.y;

        vertexindex += 8;
        index += 36;
    }

    if (!_vertices.empty() && !_indices.empty()) {
        _vertexBuffer->updateVertices(&_vertices[0], vertexindex/* * sizeof(_posuvcolors[0])*/, 0);
        _indexBuffer->updateIndices(&_indices[0], index/* * sizeof(unsigned short)*/, 0);

        GLuint texId = (_texture ? _texture->getName() : 0);
        _stateBlock->setBlendFunc(_particleSystem->getBlendFunc());
        _meshCommand->init(0,
                           texId,
                           _glProgramState,
                           _stateBlock,
                           _vertexBuffer->getVBO(),
                           _indexBuffer->getVBO(),
                           GL_TRIANGLES,
                           GL_UNSIGNED_SHORT,
                           index,
                           transform,
                           Node::FLAGS_RENDER_AS_3D);
        _meshCommand->setSkipBatching(true);
        _meshCommand->setTransparent(true);

        _glProgramState->setUniformVec4("u_color", Vec4(1,1,1,1));
        renderer->addCommand(_meshCommand);
    }
}
//--------------------------------------------------------------------------------------------------
// Name: Initialise
// Desc: Initialises post effect activation system from data
//       Uses the xml node name for the post effect, and activeValue and nonActiveValue attributes
//--------------------------------------------------------------------------------------------------
void CPostEffectActivationSystem::Initialise(const IItemParamsNode* postEffectListXmlNode)
{
	if(postEffectListXmlNode)
	{
		const IItemParamsNode* postEffectXmlNode = NULL;
		SPostEffectParam* param = NULL;
		int childCount = postEffectListXmlNode->GetChildCount();
		int postEffectCount = childCount;

		const IItemParamsNode* vecsXmlNode = postEffectListXmlNode->GetChild("vecs");

		if(vecsXmlNode)
		{
			postEffectCount--;
		}

		m_postEffectParam.resize(postEffectCount);

		int paramIndex=0;
		for(int c=0; c<childCount; c++)
		{
			postEffectXmlNode = postEffectListXmlNode->GetChild(c);
			if(postEffectXmlNode && postEffectXmlNode != vecsXmlNode)
			{
				param = &m_postEffectParam[paramIndex];
				cry_strcpy(param->name, postEffectXmlNode->GetName());
				postEffectXmlNode->GetAttribute("activeValue",param->activeValue);
				postEffectXmlNode->GetAttribute("nonActiveValue",param->nonActiveValue);

				int forceValue = 0;
				postEffectXmlNode->GetAttribute("forceValue",forceValue);
				param->forceValue = (forceValue) ? true : false;
				paramIndex++;
			}
		}

		if(vecsXmlNode)
		{
			SPostEffectParamVec* paramVec = NULL;
			const int vecCount = vecsXmlNode->GetChildCount();
			m_postEffectParamVec.resize(vecCount);
			for(int i=0; i<vecCount; i++)
			{
				postEffectXmlNode = vecsXmlNode->GetChild(i);

				paramVec = &m_postEffectParamVec[i];
				cry_strcpy(paramVec->name, postEffectXmlNode->GetName());

				Vec3 vecValue(0.0f,0.0f,0.0f);
				float wValue = 0.0f;

				postEffectXmlNode->GetAttribute("activeVec3",vecValue);
				postEffectXmlNode->GetAttribute("activeW",wValue);
				paramVec->activeValue = Vec4(vecValue,wValue);

				postEffectXmlNode->GetAttribute("nonActiveVec3",vecValue);
				postEffectXmlNode->GetAttribute("nonActiveW",wValue);
				paramVec->nonActiveValue = Vec4(vecValue,wValue);

				int forceValue = 0;
				postEffectXmlNode->GetAttribute("forceValue",forceValue);
				paramVec->forceValue = (forceValue) ? true : false;
			}
		}
	}
}//-------------------------------------------------------------------------------------------------
Example #3
0
		Vec4		 Vec4::operator+(const Vec4& v) { return Vec4(this->x + v.x, this->y + v.y, this->z + v.z, this->w + v.w); }
Example #4
0
void FilterDoubleExponential::Update( const SKinSkeletonRawData& pSkeletonData, uint32 i, const KIN_TRANSFORM_SMOOTH_PARAMETERS& smoothingParams )
{
    Vec4 vPrevRawPosition;
    Vec4 vPrevFilteredPosition;
    Vec4 vPrevTrend;
    Vec4 vRawPosition;
    Vec4 vFilteredPosition;
    Vec4 vPredictedPosition;
    Vec4 vDiff;
    Vec4 vTrend;
    Vec4 vLength;
    float fDiff;
    BOOL bJointIsValid;

    const Vec4* __restrict pJointPositions = pSkeletonData.vSkeletonPositions;

    vRawPosition            = pJointPositions[i];
    vPrevFilteredPosition   = m_History[i].m_vFilteredPosition;
    vPrevTrend              = m_History[i].m_vTrend;
    vPrevRawPosition        = m_History[i].m_vRawPosition;
    bJointIsValid           = JointPositionIsValid(vRawPosition);

    // If joint is invalid, reset the filter
    if (!bJointIsValid)
    {
        m_History[i].m_dwFrameCount = 0;
    }

    // Initial start values
    if (m_History[i].m_dwFrameCount == 0)
    {
        vFilteredPosition = vRawPosition;
        vTrend = Vec4(0,0,0,0);
        m_History[i].m_dwFrameCount++;
    }
    else if (m_History[i].m_dwFrameCount == 1)
    {
        vFilteredPosition = (vRawPosition + vPrevRawPosition) * 0.5f;
        vDiff = vFilteredPosition - vPrevFilteredPosition;
        vTrend = (vDiff * smoothingParams.m_fCorrection) + (vPrevTrend *  (1.0f - smoothingParams.m_fCorrection));
        m_History[i].m_dwFrameCount++;
    }
    else
    {              
        // First apply jitter filter
        vDiff = vRawPosition - vPrevFilteredPosition;
        fDiff = fabs(vDiff.GetLength());

        if (fDiff <= smoothingParams.m_fJitterRadius)
        {
            vFilteredPosition = vRawPosition * (fDiff/smoothingParams.m_fJitterRadius) + vPrevFilteredPosition * (1.0f - fDiff/smoothingParams.m_fJitterRadius);
        }
        else
        {
            vFilteredPosition = vRawPosition;
        }

        // Now the double exponential smoothing filter
        vFilteredPosition = vFilteredPosition * (1.0f - smoothingParams.m_fSmoothing) + (vPrevFilteredPosition + vPrevTrend) * smoothingParams.m_fSmoothing;


        vDiff = vFilteredPosition - vPrevFilteredPosition;
        vTrend = vDiff * smoothingParams.m_fCorrection + vPrevTrend * (1.0f - smoothingParams.m_fCorrection); 
    }      

    // Predict into the future to reduce latency
    vPredictedPosition = vFilteredPosition + (vTrend * smoothingParams.m_fPrediction);

    // Check that we are not too far away from raw data
    vDiff = vPredictedPosition - vRawPosition;
    fDiff = fabs(vDiff.GetLength());

    if (fDiff > smoothingParams.m_fMaxDeviationRadius)
    {
        vPredictedPosition = vPredictedPosition * smoothingParams.m_fMaxDeviationRadius/fDiff + vRawPosition * (1.0f - smoothingParams.m_fMaxDeviationRadius/fDiff);
    }

    // Save the data from this frame
    m_History[i].m_vRawPosition      = vRawPosition;
    m_History[i].m_vFilteredPosition = vFilteredPosition;
    m_History[i].m_vTrend            = vTrend;
    
    // Output the data
    m_FilteredJoints[i] = vPredictedPosition;
    m_FilteredJoints[i].w = 1.0f;
}
Example #5
0
    void PhysicsDebugDraw::drawSphere(const btVector3& p, btScalar radius, const btVector3& color)
    {

		debugRenderer->drawSphere(Vec3(p.getX(), p.getY(), p.getZ()), radius, Vec4(color.getX(), color.getY(), color.getZ(), 1.f));
    }
Example #6
0
void tcOptionsView::Draw() 
{
	static unsigned int drawCount = 0;


    std::string activeTab = GetTab();

    StartDraw();

	wxASSERT(mpOptions);   


    UpdateButtonInfo();

    std::vector<tcOptions::OptionInfo>& optionList = mpOptions->maOptionInfo;

    for(size_t k=0; k<buttonInfo.size(); k++) 
    {
        if (!buttonInfo[k].isSlider)
        {
            int optionIdx = buttonInfo[k].optionIdx;
            int valueIdx = buttonInfo[k].valueIdx;

            tcString sText = optionList[optionIdx].mzCaption[valueIdx];

            float x = (float)buttonInfo[k].textX;
            float y = (float)buttonInfo[k].textY;

            DrawText(sText.c_str(), x, y, defaultFont.get(), 
                Vec4(0.86f, 0.86f, 1.0f, 1.0f), fontSize, LEFT_CENTER);

            if (optionList[optionIdx].mnValue == valueIdx) 
            {
                DrawButton(buttonInfo[k].buttonX, buttonInfo[k].buttonY, 1);
            }
            else 
            {
                DrawButton(buttonInfo[k].buttonX, buttonInfo[k].buttonY, 0);
            }
        }
        else
        {
            int optionIdx = buttonInfo[k].optionIdx;

            tcString sText = optionList[optionIdx].mzCaption[0];

            bool thisSliderActive = sliderDragActive && (sliderIdx == k);

            float sliderVal = thisSliderActive ? 
                                sliderDragValue : optionList[optionIdx].floatVal;
            float sliderMin = optionList[optionIdx].floatMin;
            float sliderMax = optionList[optionIdx].floatMax;
            float sliderFraction = (sliderVal - sliderMin) / (sliderMax - sliderMin);

  
            float xText = (float)buttonInfo[k].textX;
            float yText = (float)buttonInfo[k].textY;
            float xBar = (float)buttonInfo[k].buttonX;
            float yBar = (float)buttonInfo[k].buttonY;

            DrawText(sText.c_str(), xText, yText, defaultFont.get(), 
                Vec4(0.86f, 0.86f, 1.0f, 1.0f), fontSize, LEFT_CENTER);

            float xThumb = xBar + sliderFraction*sliderBarWidth;
            tcRect thumbRect(xThumb-2.0f, xThumb+2.0f, yBar-8.0f, yBar+8.0f);
            buttonInfo[k].thumbRect = thumbRect;

            // draw slider here
            DrawSlider(xBar, yBar, thumbRect, sliderVal, thisSliderActive);

        }

	}


	FinishDraw();
}
Example #7
0
void OsgViewerBase::setSunLightPosition( const Vec3d& position )
{
	_sunLight->setPosition(Vec4(position.x(), position.y(), position.z(), 0.0f));
}
//==============================================================================
void FollowPathEvent::update(F32 prevUpdateTime, F32 crntTime)
{
	MoveComponent& move = movableSceneNode->getComponent<MoveComponent>();

	I pointA = 0;
	I pointB = 0;

	// Calculate the current distance. Clamp it to max distance
	F32 crntDistance = distPerTime * (crntTime - getStartTime());
	ANKI_ASSERT(crntDistance >= 0.0);
	crntDistance = std::min(crntDistance, path->getDistance());

	const I pointsCount = path->getPoints().size();
	ANKI_ASSERT(pointsCount > 1);

	// Find the points that we lie between
	for(I i = 1; i < pointsCount; i++)
	{
		const PathPoint& ppa = path->getPoints()[i - 1];
		const PathPoint& ppb = path->getPoints()[i];

		if(crntDistance > ppa.getDistanceFromFirst() 
			&& crntDistance <= ppb.getDistanceFromFirst())
		{
			pointA = i - 1;
			pointB = i;
			break;
		}
	}

	ANKI_ASSERT(pointA < pointsCount && pointB < pointsCount);

	I preA = std::max((I)0, pointA - 1);
	I postB = std::min(pointsCount - 1, pointB + 1);
	/*I pminus2 = std::max((I)0, pointA - 2);
	I pminus1 = std::max((I)0, pointA - 1);*/

	// Calculate the u [0.0, 1.0]
	F32 u = path->getPoints()[pointB].getDistance() + getEpsilon<F32>();
	ANKI_ASSERT(u != 0.0);

	const F32 c = crntDistance 
		- path->getPoints()[pointA].getDistanceFromFirst();

	u = c / u;

	// Calculate and set new position and rotation for the movable
	/*Vec3 newPos = cubicInterpolate(
		path->getPoints()[preA].getPosition(),
		path->getPoints()[pointA].getPosition(),
		path->getPoints()[pointB].getPosition(),
		path->getPoints()[postB].getPosition(),
		u);*/
	Vec3 newPos = interpolate(
		path->getPoints()[pointA].getPosition(),
		path->getPoints()[pointB].getPosition(),
		u);

	{
		F32 u2 = u * u;
		Vec4 us(1, u, u2, u2 * u);
		F32 t = 0.7;
		
		Mat4 tentionMat(
			0.0, 1.0, 0.0, 0.0,
			-t, 0.0, t, 0.0,
			2.0 * t, t - 3.0, 3.0 - 2.0 * t, -t,
			-t, 2.0 - t, t - 2.0, t);

		Vec4 tmp = us * tentionMat;

		Mat4 posMat;
		posMat.setRows(
			Vec4(path->getPoints()[preA].getPosition(), 1.0),
			Vec4(path->getPoints()[pointA].getPosition(), 1.0),
			Vec4(path->getPoints()[pointB].getPosition(), 1.0),
			Vec4(path->getPoints()[postB].getPosition(), 1.0));

		Vec4 finalPos = tmp * posMat;

		newPos = finalPos.xyz();
	}

	Quat newRot = path->getPoints()[pointA].getRotation().slerp(
			path->getPoints()[pointB].getRotation(),
			u);

	F32 scale = move.getLocalTransform().getScale();
	Transform trf;
	trf.setOrigin(newPos);
	trf.setRotation(Mat3(newRot));
	trf.setScale(scale);
	move.setLocalTransform(trf);
}
Example #9
0
void Flow::SelfEquilibrium()
{
  Vec4 sum =  fvec.ltf +
              fvec.rtf +
              fvec.ldf +
              fvec.rdf +
              fvec.ltb +
              fvec.rtb +
              fvec.ldb +
              fvec.rdb;

  sum = Vec4(sum.m_x/8.0f, sum.m_y/8.0f, sum.m_z/8.0f);

  fvec.ltf = Vec4(Vec4(fvec.ltf.m_x + sum.m_x,
                  fvec.ltf.m_y + sum.m_y,
                  fvec.ltf.m_z + sum.m_z)
                * m_equilibrium_factor) + (fvec.rtf * fvec.rtf.dot(sum) * m_equilibrium_factor);
                // m_equilibrium_factor;

  fvec.rtf = Vec4(Vec4(fvec.rtf.m_x + sum.m_x,
                  fvec.rtf.m_y + sum.m_y,
                  fvec.rtf.m_z + sum.m_z)
                * m_equilibrium_factor) + (fvec.rtf * fvec.rtf.dot(sum)* m_equilibrium_factor);
                //* m_equilibrium_factor);

  fvec.ldf = Vec4(Vec4(fvec.ldf.m_x + sum.m_x,
                  fvec.ldf.m_y + sum.m_y,
                  fvec.ldf.m_z + sum.m_z)
                * m_equilibrium_factor) + (fvec.ldf * fvec.ldf.dot(sum)* m_equilibrium_factor);
                 //m_equilibrium_factor);

  fvec.rdf = Vec4(Vec4(fvec.rdf.m_x + sum.m_x,
                  fvec.rdf.m_y + sum.m_y,
                  fvec.rdf.m_z + sum.m_z)
                * m_equilibrium_factor) + (fvec.rdf * fvec.rdf.dot(sum)* m_equilibrium_factor);
               // * m_equilibrium_factor);

  fvec.ltb = Vec4(Vec4(fvec.ltb.m_x + sum.m_x,
                  fvec.ltb.m_y + sum.m_y ,
                  fvec.ltb.m_z + sum.m_z )
                * m_equilibrium_factor) + (fvec.ltf * fvec.ltb.dot(sum)* m_equilibrium_factor);
               // * m_equilibrium_factor);

  fvec.rtb = Vec4(Vec4(fvec.rtb.m_x + sum.m_x,
                  fvec.rtb.m_y + sum.m_y,
                  fvec.rtb.m_z + sum.m_z )
                * m_equilibrium_factor) + (fvec.rtf * fvec.rtb.dot(sum));
//                * m_equilibrium_factor);

  fvec.ldb = Vec4(Vec4(fvec.ldb.m_x + sum.m_x,
                  fvec.ldb.m_y + sum.m_y,
                  fvec.ldb.m_z + sum.m_z)
                * m_equilibrium_factor) + (fvec.ldf / fvec.rdb.dist(sum));
                //* m_equilibrium_factor);

  fvec.rdb = Vec4(Vec4(fvec.rdb.m_x + sum.m_x,
                  fvec.rdb.m_y + sum.m_y,
                  fvec.rdb.m_z + sum.m_z)
                * m_equilibrium_factor) + (fvec.rdf / fvec.ldb.dist(sum));
                //* m_equilibrium_factor);

}
Example #10
0
	/* Assembles atlas from tileset and autotile bitmaps */
	void buildAtlas()
	{
		updateAutotileInfo();

		TileAtlas::BlitVec blits = TileAtlas::calcBlits(atlas.efTilesetH, atlas.size);

		/* Clear atlas */
		FBO::bind(atlas.gl.fbo, FBO::Draw);
		glState.clearColor.pushSet(Vec4());
		glState.scissorTest.pushSet(false);

		FBO::clear();

		glState.scissorTest.pop();
		glState.clearColor.pop();

		/* Blit autotiles */
		for (size_t i = 0; i < atlas.usableATs.size(); ++i)
		{
			const uint8_t atInd = atlas.usableATs[i];
			Bitmap *autotile = autotiles[atInd];

			int blitW = std::min(autotile->width(), atAreaW);
			int blitH = std::min(autotile->height(), atAreaH);

			FBO::bind(autotile->getGLTypes().fbo, FBO::Read);

			if (blitW <= autotileW && tiles.animated)
			{
				/* Static autotile */
				for (int j = 0; j < 4; ++j)
					FBO::blit(0, 0, autotileW*j, atInd*autotileH, blitW, blitH);
			}
			else
			{
				/* Animated autotile */
				FBO::blit(0, 0, 0, atInd*autotileH, blitW, blitH);
			}
		}

		/* Blit tileset */
		if (tileset->megaSurface())
		{
			/* Mega surface tileset */
			FBO::unbind(FBO::Draw);
			TEX::bind(atlas.gl.tex);

			SDL_Surface *tsSurf = tileset->megaSurface();

			for (size_t i = 0; i < blits.size(); ++i)
			{
				const TileAtlas::Blit &blitOp = blits[i];

				GLMeta::subRectImageUpload(tsSurf->w, blitOp.src.x, blitOp.src.y,
				                           blitOp.dst.x, blitOp.dst.y, tsLaneW, blitOp.h, tsSurf, GL_RGBA);
			}

			GLMeta::subRectImageFinish();
		}
		else
		{
			/* Regular tileset */
			FBO::bind(tileset->getGLTypes().fbo, FBO::Read);

			for (size_t i = 0; i < blits.size(); ++i)
			{
				const TileAtlas::Blit &blitOp = blits[i];

				FBO::blit(blitOp.src.x, blitOp.src.y, blitOp.dst.x, blitOp.dst.y, tsLaneW, blitOp.h);
			}
		}
	}
Example #11
0
void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
    if (_skeleton)
        _skeleton->updateBoneMatrix();
    
    Color4F color(getDisplayedColor());
    color.a = getDisplayedOpacity() / 255.0f;
    
    //check light and determine the shader used
    const auto& lights = Director::getInstance()->getRunningScene()->getLights();
    bool usingLight = false;
    for (const auto light : lights) {
        usingLight = ((unsigned int)light->getLightFlag() & _lightMask) > 0;
        if (usingLight)
            break;
    }
    if (usingLight != _shaderUsingLight)
        genGLProgramState(usingLight);
    
    int i = 0;
    for (auto& mesh : _meshes) {
        if (!mesh->isVisible())
        {
            i++;
            continue;
        }
        auto programstate = mesh->getGLProgramState();
        auto& meshCommand = mesh->getMeshCommand();

#if (!defined NDEBUG) || (defined CC_MODEL_VIEWER) 
        GLuint textureID = 0;
        if(mesh->getTexture())
        {
            textureID = mesh->getTexture()->getName();
        }else
        { //let the mesh use a dummy texture instead of the missing or crashing texture file
            auto texture = getDummyTexture();
            mesh->setTexture(texture);
            textureID = texture->getName();
        }

#else
        GLuint textureID = mesh->getTexture() ? mesh->getTexture()->getName() : 0;
#endif

        float globalZ = _globalZOrder;
        bool isTransparent = (mesh->_isTransparent || color.a < 1.f);
        if (isTransparent && Camera::getVisitingCamera())
        {   // use the view matrix for Applying to recalculating transparent mesh's Z-Order
            const auto& viewMat = Camera::getVisitingCamera()->getViewMatrix();
            globalZ = -(viewMat.m[2] * transform.m[12] + viewMat.m[6] * transform.m[13] + viewMat.m[10] * transform.m[14] + viewMat.m[14]);//fetch the Z from the result matrix
        }
        meshCommand.init(globalZ, textureID, programstate, _blend, mesh->getVertexBuffer(), mesh->getIndexBuffer(), mesh->getPrimitiveType(), mesh->getIndexFormat(), mesh->getIndexCount(), transform);
        
        meshCommand.setLightMask(_lightMask);

        auto skin = mesh->getSkin();
        if (skin)
        {
            meshCommand.setMatrixPaletteSize((int)skin->getMatrixPaletteSize());
            meshCommand.setMatrixPalette(skin->getMatrixPalette());
        }
        //support tint and fade
        meshCommand.setDisplayColor(Vec4(color.r, color.g, color.b, color.a));
        meshCommand.setTransparent(isTransparent);
        renderer->addCommand(&meshCommand);
    }
}
Example #12
0
void FloatsToVec4Node::Operate() {
  mValue = Vec4(mX.Get(), mY.Get(), mZ.Get(), mW.Get());
}
Example #13
0
void PUSphereRender::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
{
    //batch and generate draw
    const ParticlePool &particlePool = particleSystem->getParticlePool();
    if (!_isVisible || particlePool.empty())
        return;

    auto camera = Camera::getVisitingCamera();
    auto cameraMat = camera->getNodeToWorldTransform();
    Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]);

    unsigned int vertexCount = (_numberOfRings + 1) * (_numberOfSegments + 1);
    unsigned int indexCount = 6 * _numberOfRings * (_numberOfSegments + 1);
    if (_vertexBuffer == nullptr && _indexBuffer == nullptr) {
        GLsizei stride = sizeof(VertexInfo);
        _vertexBuffer = VertexBuffer::create(stride, vertexCount * particleSystem->getParticleQuota());
        if (_vertexBuffer == nullptr)
        {
            CCLOG("PUSphereRender::render create vertex buffer failed");
            return;
        }
        _vertexBuffer->retain();
        _vertices.resize(vertexCount * particleSystem->getParticleQuota());

        _indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, indexCount * particleSystem->getParticleQuota());
        if (_indexBuffer == nullptr)
        {
            CCLOG("PUSphereRender::render create index buffer failed");
            return;
        }
        _indexBuffer->retain();
        _indices.resize(indexCount * particleSystem->getParticleQuota());

        buildBuffers(particleSystem->getParticleQuota());
    }

    unsigned int vertexindex = 0;
    unsigned int index = 0;

    Mat4 mat;
    Mat4 rotMat;
    Mat4 sclMat;
    Mat4 texRot;
    Vec3 val;
    for (auto iter : particlePool.getActiveDataList())
    {
        auto particle = static_cast<PUParticle3D *>(iter);
        float radius = particle->width * 0.5f;
        Mat4::createRotation(particle->orientation, &rotMat);
        Mat4::createScale(radius, radius, radius, &sclMat);
        Mat4::createRotation(backward, particle->zRotation, &texRot);
        mat = rotMat * sclMat;
        mat.m[12] = particle->position.x;
        mat.m[13] = particle->position.y;
        mat.m[14] = particle->position.z;

        for (unsigned int i = 0; i < vertexCount; ++i) {
            val = texRot * Vec3(_vertexTemplate[vertexindex + i].uv.x, _vertexTemplate[vertexindex + i].uv.y, 0.0f);
            mat.transformPoint(_vertexTemplate[vertexindex + i].position, &_vertices[vertexindex + i].position);
            _vertices[vertexindex + i].color = particle->color;
            _vertices[vertexindex + i].uv.x = val.x;
            _vertices[vertexindex + i].uv.y = val.y;
        }
        vertexindex += vertexCount;
        index += indexCount;
    }

    if (!_vertices.empty() && !_indices.empty()) {
        _vertexBuffer->updateVertices(&_vertices[0], vertexindex/* * sizeof(_posuvcolors[0])*/, 0);
        _indexBuffer->updateIndices(&_indices[0], index/* * sizeof(unsigned short)*/, 0);

        GLuint texId = (_texture ? _texture->getName() : 0);
        _stateBlock->setBlendFunc(particleSystem->getBlendFunc());
        _meshCommand->init(
            0,
            texId,
            _glProgramState,
            _stateBlock,
            _vertexBuffer->getVBO(),
            _indexBuffer->getVBO(),
            GL_TRIANGLES,
            GL_UNSIGNED_SHORT,
            index,
            transform,
            Node::FLAGS_RENDER_AS_3D);
        _meshCommand->setSkipBatching(true);
        _meshCommand->setTransparent(true);

        _glProgramState->setUniformVec4("u_color", Vec4(1,1,1,1));
        renderer->addCommand(_meshCommand);
    }
}
Example #14
0
void PUParticle3DQuadRender::render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem)
{
    //batch and generate draw
    const ParticlePool &particlePool = particleSystem->getParticlePool();
    if (!_isVisible || particlePool.empty())
        return;

    if (_vertexBuffer == nullptr) {
        GLsizei stride = sizeof(VertexInfo);
        _vertexBuffer = VertexBuffer::create(stride, 4 * particleSystem->getParticleQuota());
        if (_vertexBuffer == nullptr)
        {
            CCLOG("PUParticle3DQuadRender::render create vertex buffer failed");
            return;
        }
        _vertexBuffer->retain();
    }

    if (_indexBuffer == nullptr) {
        _indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, 6 * particleSystem->getParticleQuota());
        if (_indexBuffer == nullptr)
        {
            CCLOG("PUParticle3DQuadRender::render create index buffer failed");
            return;
        }
        _indexBuffer->retain();
    }
    const ParticlePool::PoolList &activeParticleList = particlePool.getActiveDataList();
    if (_vertices.size() < activeParticleList.size() * 4)
    {
        _vertices.resize(activeParticleList.size() * 4);
        _indices.resize(activeParticleList.size() * 6);
    }

    auto camera = Camera::getVisitingCamera();
    auto cameraMat = camera->getNodeToWorldTransform();


    //for (auto iter : activeParticleList){
    //    iter->depthInView = -(viewMat.m[2] * iter->positionInWorld.x + viewMat.m[6] * iter->positionInWorld.y + viewMat.m[10] * iter->positionInWorld.z + viewMat.m[14]);
    //}

    //std::sort(activeParticleList.begin(), activeParticleList.end(), compareParticle3D);
    Vec3 right(cameraMat.m[0], cameraMat.m[1], cameraMat.m[2]);
    Vec3 up(cameraMat.m[4], cameraMat.m[5], cameraMat.m[6]);
    Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]);

    Mat4 pRotMat;
    Vec3 position; //particle position
    int vertexindex = 0;
    int index = 0;
    int offsetX,offsetY;
    getOriginOffset(offsetX, offsetY);

    if (_type == PERPENDICULAR_COMMON) {
        up = _commonUp;
        up.normalize();
        Vec3::cross(up, _commonDir, &right);
        right.normalize();
        backward = _commonDir;
    } else if (_type == ORIENTED_COMMON) {
        up = _commonDir;
        up.normalize();
        Vec3::cross(up, backward, &right);
        right.normalize();
    }

    for (auto iter : activeParticleList)
    {
        auto particle = static_cast<PUParticle3D *>(iter);
        determineUVCoords(particle);
        if (_type == ORIENTED_SELF) {
            Vec3 direction = particle->direction;
            //transform.transformVector(particle->direction, &direction);
            up = direction;
            up.normalize();
            Vec3::cross(direction, backward, &right);
            right.normalize();
        } else if (_type == PERPENDICULAR_SELF) {
            Vec3 direction = particle->direction;
            //transform.transformVector(particle->direction, &direction);
            direction.normalize();
            //up = PUUtil::perpendicular(direction);
            //up.normalize();
            Vec3::cross(_commonUp, direction, &right);
            right.normalize();
            Vec3::cross(direction, right, &up);
            up.normalize();
            backward = direction;
        } else if (_type == ORIENTED_SHAPE) {
            up.set(particle->orientation.x, particle->orientation.y, particle->orientation.z);
            up.normalize();
            Vec3::cross(up, backward, &right);
            right.normalize();
        }
        Vec3 halfwidth = particle->width * 0.5f * right;
        Vec3 halfheight = particle->height * 0.5f * up;
        Vec3 offset = halfwidth * offsetX + halfheight * offsetY;
        //transform.transformPoint(particle->position, &position);
        position = particle->position;

        if (_rotateType == TEXTURE_COORDS) {
            float costheta = cosf(-particle->zRotation);
            float sintheta = sinf(-particle->zRotation);
            Vec2 texOffset = 0.5f * (particle->lb_uv + particle->rt_uv);
            Vec2 val;
            val.set((particle->lb_uv.x - texOffset.x), (particle->lb_uv.y - texOffset.y));
            val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
            fillVertex(vertexindex, (position + (-halfwidth - halfheight + offset)), particle->color, val + texOffset);

            val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y);
            val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
            fillVertex(vertexindex + 1, (position + (halfwidth - halfheight + offset)), particle->color, val + texOffset);

            val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
            val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
            fillVertex(vertexindex + 2, (position + (-halfwidth + halfheight + offset)), particle->color, val + texOffset);

            val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
            val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
            fillVertex(vertexindex + 3, (position + (halfwidth + halfheight + offset)), particle->color, val + texOffset);
        } else {
            Mat4::createRotation(backward, -particle->zRotation, &pRotMat);
            fillVertex(vertexindex    , (position + pRotMat * (- halfwidth - halfheight + offset)), particle->color, particle->lb_uv);
            fillVertex(vertexindex + 1, (position + pRotMat * (halfwidth - halfheight + offset)), particle->color, Vec2(particle->rt_uv.x, particle->lb_uv.y));
            fillVertex(vertexindex + 2, (position + pRotMat * (-halfwidth + halfheight + offset)), particle->color, Vec2(particle->lb_uv.x, particle->rt_uv.y));
            fillVertex(vertexindex + 3, (position + pRotMat * (halfwidth + halfheight + offset)), particle->color, particle->rt_uv);
        }

        fillTriangle(index, vertexindex, vertexindex + 1, vertexindex + 3);
        fillTriangle(index + 3, vertexindex, vertexindex + 3, vertexindex + 2);

        //_posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY));
        //_posuvcolors[vertexindex].color = particle->color;
        //_posuvcolors[vertexindex].uv.set(val.x + texOffset.x, val.y + texOffset.y);

        //val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y);
        //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
        //_posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY));
        //_posuvcolors[vertexindex + 1].color = particle->color;
        //_posuvcolors[vertexindex + 1].uv.set(val.x + texOffset.x, val.y + texOffset.y);
        //
        //val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
        //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
        //_posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY));
        //_posuvcolors[vertexindex + 2].color = particle->color;
        //_posuvcolors[vertexindex + 2].uv.set(val.x + texOffset.x, val.y + texOffset.y);
        //
        //val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
        //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
        //_posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY));
        //_posuvcolors[vertexindex + 3].color = particle->color;
        //_posuvcolors[vertexindex + 3].uv.set(val.x + texOffset.x, val.y + texOffset.y);
        //
        //
        //_indexData[index] = vertexindex;
        //_indexData[index + 1] = vertexindex + 1;
        //_indexData[index + 2] = vertexindex + 3;
        //_indexData[index + 3] = vertexindex;
        //_indexData[index + 4] = vertexindex + 3;
        //_indexData[index + 5] = vertexindex + 2;

        index += 6;
        vertexindex += 4;

    }

    _vertices.erase(_vertices.begin() + vertexindex, _vertices.end());
    _indices.erase(_indices.begin() + index, _indices.end());

    if (!_vertices.empty() && !_indices.empty()) {
        _vertexBuffer->updateVertices(&_vertices[0], vertexindex/* * sizeof(_posuvcolors[0])*/, 0);
        _indexBuffer->updateIndices(&_indices[0], index/* * sizeof(unsigned short)*/, 0);

        _stateBlock->setBlendFunc(particleSystem->getBlendFunc());

        GLuint texId = (_texture ? _texture->getName() : 0);
        _meshCommand->init(0,
                           texId,
                           _glProgramState,
                           _stateBlock,
                           _vertexBuffer->getVBO(),
                           _indexBuffer->getVBO(),
                           GL_TRIANGLES,
                           GL_UNSIGNED_SHORT,
                           index,
                           transform,
                           Node::FLAGS_RENDER_AS_3D);
        _meshCommand->setSkipBatching(true);
        _meshCommand->setTransparent(true);
        _glProgramState->setUniformVec4("u_color", Vec4(1,1,1,1));
        renderer->addCommand(_meshCommand);
    }
}
Example #15
0
Vec4 operator^(const Vec4 &l, const Vec4 &r) {
	float x = l.coord[1] * r.coord[2] - l.coord[2] * r.coord[1];
	float y = l.coord[2] * r.coord[0] - l.coord[0] * r.coord[2];
	float z = l.coord[0] * r.coord[1] - l.coord[1] * r.coord[0];
	return Vec4(x, y, z, 0);
}
Example #16
0
Vec4 Matrix4x4::getRotationSeted()
{
    return Vec4(rotx,roty,rotz);
}
Example #17
0
Mat4 ortho(float l, float r, float t, float b, float n, float f){
	Mat4 a;
	a = scale(a, Vec4(dnLbd(r, l), dnLbd(t, b), -dnLbd(f, n), 1.0f));
	a = translate(a, Vec4(-nLbd(r, l), -nLbd(t, b), -nLbd(f, n), 1.0f));
	return a;
}
Example #18
0
Vec4 Matrix4x4::getScaleSeted()
{
    return Vec4(scale_m[0],scale_m[5],scale_m[10]);
}
Example #19
0
//run a loop with with specific textured quad. Wait for specific input.
bool World::display(SDL_Window *window,const int type) const
{
    bool state= false;
    bool loop = false;
    SDL_Event event;
    Vec4 white(1,1,1);

      while(!loop)
      {
        while ( SDL_PollEvent(&event) )
        {
          switch (event.type)
          {
            // this is the window x being clicked.
            case SDL_QUIT : state = false; return false; break;
            // if the window is re-sized pass it to the ngl class to change gl viewport
            // note this is slow as the context is re-create by SDL each time

            // now we look for a keydown event
            case SDL_KEYDOWN:
            {
              switch(type)
                case W_MENU:
                {
                  switch(event.key.keysym.sym)
                  {
                    case SDLK_m : state = true;   return state; break;
                    case SDLK_s : state = false;  return state; break;
                  }
                }
                case W_PLAY1_WIN:
                {
                  switch(event.key.keysym.sym)
                  {
                    case SDLK_SPACE :  state = false;return state; break;
                    case SDLK_ESCAPE : state = true; return state; break;
                  }
                }
                case W_PLAY2_WIN:
                {
                  switch(event.key.keysym.sym)
                  {
                    case SDLK_SPACE :  state = false;return state; break;
                    case SDLK_ESCAPE : state = true; return state; break;
                  }
                }
                case W_CRASHED:
                {
                  switch(event.key.keysym.sym)
                  {
                    case SDLK_SPACE :  state = false;return state; break;
                    case SDLK_ESCAPE : state = true; return state; break;
                  }
                }
                default:break;
              } // end of keydown
            } // end of event switch
          } // end of poll events

        white.colourGL();

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        GLFunctions::lookAt(Vec4(0,0,1),Vec4(0,0,0),Vec4(0,1,0));

        switch(type)
        {
          case W_MENU:      { World::drawDisplay(MENU);    break; }
          case W_PLAY1_WIN:  { World::drawDisplay(PLAY1WIN);break; }
          case W_PLAY2_WIN:  { World::drawDisplay(PLAY2WIN);break; }
          case W_CRASHED:   { World::drawDisplay(CRASH);   break; }
        }
        SDL_GL_SwapWindow(window);
    }

    return false;
}
Example #20
0
Vec4 Matrix4x4::getTranslateSeted()
{
    return Vec4(translate_m[12],translate_m[13],translate_m[14]);
}
Example #21
0
//--------------------------------------------------------------------------------------
// Name: CombiJointFilter()
// Desc: A filter for the positional data.  This filter uses a combination of velocity 
//       position history to filter the joint positions.
//--------------------------------------------------------------------------------------
void FilterCombination::Update( const SKinSkeletonRawData& pSkeletonData, const float fDeltaTime )
{
    // Process each joint
    for ( uint32 nJoint = 0; nJoint < KIN_SKELETON_POSITION_COUNT; ++nJoint )
    {
        // Remember where the camera thinks this joint should be
        m_History[ nJoint ].m_vWantedPos = pSkeletonData.vSkeletonPositions[ nJoint ];

        Vec4 vDelta;
        vDelta = m_History[ nJoint ].m_vWantedPos - m_History[ nJoint ].m_vLastWantedPos;
        {
            Vec4 vBlended;

            // Calculate the vBlended value - could optimize this by remembering the running total and
            // subtracting the oldest value and then adding the newest. Saves adding them all up on each frame.
            vBlended = Vec4(0,0,0,0);
            for( uint32 k = 0; k < m_nUseTaps; ++k)
            {
                vBlended = vBlended + m_History[ nJoint ].m_vPrevDeltas[k];
            }
            vBlended = vBlended / ((float)m_nUseTaps);

						vBlended.w = 0.0f;
						vDelta.w = 0.0f;

            float fDeltaLength = vDelta.GetLength();
            float fBlendedLength = vBlended.GetLength();
            m_History[ nJoint ].m_fWantedLocalBlendRate = m_fDefaultApplyRate;
            m_History[ nJoint ].m_bActive[0] = false;
            m_History[ nJoint ].m_bActive[1] = false;
            m_History[ nJoint ].m_bActive[2] = false;

            // Does the current velocity and history have a reasonable magnitude?
            if( fDeltaLength   >= m_fDeltaLengthThreshold &&
                fBlendedLength >= m_fBlendedLengthThreshold )
            {
                float fDotProd;
                float fConfidence;

                if( m_bDotProdNormalize )
                {
                    Vec4 vDeltaOne = vDelta;
										vDeltaOne.Normalize();
                    Vec4 vBlendedOne = vBlended;
										vBlendedOne.Normalize();

                    fDotProd = vDeltaOne.Dot( vBlendedOne );
                }
                else
                {
										fDotProd = vDelta.Dot(vBlended);
                }

                // Is the current frame aligned to the recent history?
                if( fDotProd >= m_fDotProdThreshold )
                {
                    fConfidence = fDotProd;
                    m_History[ nJoint ].m_fWantedLocalBlendRate = min( fConfidence, 1.0f );
                    m_History[ nJoint ].m_bActive[0] = true;
                }
            }

            assert( m_History[ nJoint ].m_fWantedLocalBlendRate <= 1.0f );
        }

        // Push the previous deltas down the history
        for( int j = m_nUseTaps-2; j >= 0; --j )
        {
            m_History[ nJoint ].m_vPrevDeltas[j+1] = m_History[ nJoint ].m_vPrevDeltas[j];
        }

        // Store the current history
        m_History[ nJoint ].m_vPrevDeltas[0] = vDelta;	

        // Remember where the camera thought this joint was on the this frame
        m_History[ nJoint ].m_vLastWantedPos = m_History[ nJoint ].m_vWantedPos;
    }

    // Secondary and tertiary blending
    for ( uint32 pass = 0; pass < 2; ++pass )
    {
        for ( uint32 bone = 0; bone < g_numBones; ++bone )
        {
            float fRate1;
            float fRate2;

            fRate1 = m_History[ g_Bones[bone].startJoint ].m_fWantedLocalBlendRate;
            fRate2 = m_History[ g_Bones[bone].endJoint ].m_fWantedLocalBlendRate;

            // Blend down? Start to end
            if( (fRate1 * m_fDownBlendRate) > fRate2)
            {
                // Yes, apply
                m_History[ g_Bones[bone].endJoint ].m_fWantedLocalBlendRate = ( fRate1 * m_fDownBlendRate );

                // Flag
                m_History[ g_Bones[bone].endJoint ].m_bActive[pass+1] = true;
            }
            // Blend down? End to start
            if( ( fRate2 * m_fDownBlendRate ) > fRate1)
            {
                // Yes, apply
                m_History[ g_Bones[bone].startJoint ].m_fWantedLocalBlendRate = ( fRate2 * m_fDownBlendRate );

                // Flag
                m_History[ g_Bones[bone].startJoint ].m_bActive[pass+1] = true;
            }
        }
    }

    // Apply
    for ( uint32 joint = 0; joint < KIN_SKELETON_POSITION_COUNT; ++joint )
    {
        // Blend the blend rate
        m_History[ joint ].m_fActualLocalBlendRate = 
                Lerp(m_History[ joint ].m_fActualLocalBlendRate,
                     m_History[ joint ].m_fWantedLocalBlendRate,
                     m_fBlendBlendRate);

        // Blend the actual position towards the wanted positon
        m_History[ joint ].m_vPos = 
                Lerp(m_History[ joint ].m_vPos,
                             m_History[ joint ].m_vWantedPos,
                             m_History[ joint ].m_fActualLocalBlendRate);
        m_FilteredJoints[ joint ] = m_History[ joint ].m_vPos;
    }
}
Example #22
0
Vec4 SpotLight::calculateColor(Vec4 pit, Vec4 n,Vec4 viewer, Material *m,Vec4 pos,Vec4 texColor,int mode_texture)
{
    if(mode_texture==TYPE_ONLY_TEXTURE){
        Vec4 direction(direction_light->x1,direction_light->x2,direction_light->x3);
        Vec4 position(position_light->x1,position_light->x2,position_light->x3);
        Vec4 l = (position-pit)/(position-pit).module();
        float fator = fmax((n*l)/(n.module()*l.module()),0);
        Vec4 Diffuse;
        Diffuse.x1 = (texColor.x() * diffuse_light->x1)*fator;
        Diffuse.x2 = (texColor.y() * diffuse_light->x2)*fator;
        Diffuse.x3 = (texColor.z() * diffuse_light->x3)*fator;

        l = l.unitary();
        Vec4 r = (n*((l*n)*2) - l);
        Vec4 v = (viewer-pit)/(viewer-pit).module();
        r = (r+v)/(r+v).module();

        float fator2 = fmax(pow((r*v),m->shininess*128),0);
        if(r*n<0) fator2 = 0;
        Vec4 especular;
        especular.x1 = (texColor.x() * specular_light->x1)*fator2;
        especular.x2 = (texColor.y() * specular_light->x2)*fator2;
        especular.x3 = (texColor.z() * specular_light->x3)*fator2;

        Vec4 ambiente;
        ambiente.x1 = texColor.x() * ambient_light->x1;
        ambiente.x2 = texColor.y() * ambient_light->x2;
        ambiente.x3 = texColor.z() * ambient_light->x3;

        Vec4 color = ((Diffuse+especular))*isInDualConeSpot(pit)*pow(direction*(l*-1),expoent_light)*attenuation((position-viewer).module());
        return color;

    }else if(mode_texture==TYPE_REPLACE_TEXTURE){

    Vec4 direction(direction_light->x1,direction_light->x2,direction_light->x3);

    //calculo da contribuição difusa

    Vec4 position(position_light->x1,position_light->x2,position_light->x3);
    if ((position-pit).unitary()*n<=0) return Vec4();
    //direction = (direction)/(direction).module();
    Vec4 l = (position-pit)/(position-pit).module();
    float fator = fmax((n*l)/(n.module()*l.module()),0);
    Vec4 Diffuse;
    Diffuse.x1 = (m->diffuse[0] * diffuse_light->x1)*fator;
    Diffuse.x2 = (m->diffuse[1] * diffuse_light->x2)*fator;
    Diffuse.x3 = (m->diffuse[2] * diffuse_light->x3)*fator;

    //calculo da contribuicao especular
    l = l.unitary();
    Vec4 r = (n*((l*n)*2) - l);
    Vec4 v = (viewer-pit)/(viewer-pit).module();
    r = (r+v)/(r+v).module();

    float fator2 = fmax(pow((r*v),m->shininess*128),0);
    if(r*n<0) fator2 = 0;
    Vec4 especular;
    especular.x1 = (m->specular[0] * specular_light->x1)*fator2;
    especular.x2 = (m->specular[1] * specular_light->x2)*fator2;
    especular.x3 = (m->specular[2] * specular_light->x3)*fator2;
    //calculo da contribuição ambiente
    Vec4 ambiente;
    ambiente.x1 = m->ambient[0] * ambient_light->x1;
    ambiente.x2 = m->ambient[1] * ambient_light->x2;
    ambiente.x3 = m->ambient[2] * ambient_light->x3;

    Vec4 color = texColor.mult(((Diffuse+especular))*isInDualConeSpot(pit)*pow(direction*(l*-1),expoent_light)*attenuation((position-viewer).module()));
    return color;
    }else{
        Vec4 direction(direction_light->x1,direction_light->x2,direction_light->x3);

        //calculo da contribuição difusa

        Vec4 position(position_light->x1,position_light->x2,position_light->x3);
        if ((position-pit).unitary()*n<=0) return Vec4();
        //direction = (direction)/(direction).module();
        Vec4 l = (position-pit)/(position-pit).module();
        float fator = fmax((n*l)/(n.module()*l.module()),0);
        Vec4 Diffuse;
        Diffuse.x1 = (m->diffuse[0] * diffuse_light->x1)*fator;
        Diffuse.x2 = (m->diffuse[1] * diffuse_light->x2)*fator;
        Diffuse.x3 = (m->diffuse[2] * diffuse_light->x3)*fator;

        //calculo da contribuicao especular
        l = l.unitary();
        Vec4 r = (n*((l*n)*2) - l);
        Vec4 v = (viewer-pit)/(viewer-pit).module();
        r = (r+v)/(r+v).module();

        float fator2 = fmax(pow((r*v),m->shininess*128),0);
        if(r*n<0) fator2 = 0;
        Vec4 especular;
        especular.x1 = (m->specular[0] * specular_light->x1)*fator2;
        especular.x2 = (m->specular[1] * specular_light->x2)*fator2;
        especular.x3 = (m->specular[2] * specular_light->x3)*fator2;
        //calculo da contribuição ambiente
        Vec4 ambiente;
        ambiente.x1 = m->ambient[0] * ambient_light->x1;
        ambiente.x2 = m->ambient[1] * ambient_light->x2;
        ambiente.x3 = m->ambient[2] * ambient_light->x3;

        Vec4 color = ((Diffuse+especular))*isInDualConeSpot(pit)*pow(direction*(l*-1),expoent_light)*attenuation((position-viewer).module());
        return color;
    }
}
Example #23
0
//--------------------------------------------------------------------------------------
// The Taylor Series smooths and removes jitter based on a taylor series expansion
//--------------------------------------------------------------------------------------
void FilterTaylorSeries::Update( const SKinSkeletonRawData& pSkeletonData, const float fDeltaTime )
{
    const float fJitterRadius = 0.05f;
    const float fAlphaCoef  = 1.0f - m_fSmoothing;
    const float fBetaCoeff  = (fAlphaCoef * fAlphaCoef ) / ( 2 - fAlphaCoef );

    Vec4 vRawPos;
    // Velocity, acceleration and Jolt are 1st, 2nd and 3rd degree derivatives of position respectively. 
    Vec4 vCurFilteredPos, vEstVelocity, vEstAccelaration, vEstJolt;
    Vec4 vPrevFilteredPos, vPrevEstVelocity, vPrevEstAccelaration, vPrevEstJolt;
    Vec4 vDiff;
    float fDiff;

    Vec4 vPredicted, vError;
    Vec4 vConstants(0.0f, 1.0f, 0.5f, 0.1667f);

    for (int i = 0; i < KIN_SKELETON_POSITION_COUNT; i++)
    {
        vRawPos             = pSkeletonData.vSkeletonPositions[i];
        vPrevFilteredPos    = m_History[i].vPos;
        vPrevEstVelocity    = m_History[i].vEstVelocity;
        vPrevEstAccelaration = m_History[i].vEstAccelaration;
        vPrevEstJolt        = m_History[i].vEstJolt;

        if (!JointPositionIsValid(vPrevFilteredPos))
        {
            vCurFilteredPos = vRawPos;
            vEstVelocity      = Vec4(0,0,0,0);
            vEstAccelaration     = Vec4(0,0,0,0);
            vEstJolt     = Vec4(0,0,0,0);
        }
        else if (!JointPositionIsValid(vRawPos))
        {
            vCurFilteredPos = vPrevFilteredPos;
            vEstVelocity = vPrevEstVelocity;
            vEstAccelaration = vPrevEstAccelaration;
            vEstJolt = vPrevEstJolt;
        }
        else
        {
            // If the current and previous frames have valid data, perform interpolation

            vDiff = vPrevFilteredPos - vRawPos;
            fDiff = fabs(vDiff.GetLength());

            if (fDiff <= fJitterRadius)
            {
                vCurFilteredPos = vRawPos * fDiff/fJitterRadius + vPrevFilteredPos * (1.0f - fDiff/fJitterRadius);
            }
            else
            {
                vCurFilteredPos = vRawPos;
            }

            vPredicted  = vPrevFilteredPos + vPrevEstVelocity;
            vPredicted  = vPredicted + vPrevEstAccelaration * (vConstants.y * vConstants.y * vConstants.z);
            vPredicted  = vPredicted + vPrevEstJolt * (vConstants.y * vConstants.y * vConstants.y * vConstants.w);
            vError      = vCurFilteredPos - vPredicted;

            vCurFilteredPos = vPredicted + vError * fAlphaCoef;
            vEstVelocity = vPrevEstVelocity + vError * fBetaCoeff;
            vEstAccelaration = vEstVelocity - vPrevEstVelocity;
            vEstJolt = vEstAccelaration - vPrevEstAccelaration;
        }

        // Update the state
        m_History[i].vPos = vCurFilteredPos;
        m_History[i].vEstVelocity = vEstVelocity;
        m_History[i].vEstAccelaration = vEstAccelaration;
        m_History[i].vEstJolt = vEstJolt;
      
        // Output the data
        m_FilteredJoints[i]     = vCurFilteredPos;
        m_FilteredJoints[i].w   = 1.0f;
    }
}
Example #24
0
Vec4 SpotLight::randLight()
{
    Vec4 position = Vec4(position_light->x(),position_light->y(),position_light->z());
    return position;
}
Example #25
0
	Renderer::Renderer()
		: m_vClearColour(Vec4(0.0, 0.0, 0.0, 0.0))
	{
		LOG_VERBOSE << "Renderer constructor";
		init();
	}
Example #26
0
Vec4 SpotLight::getVecB()
{
    return Vec4();
}
Example #27
0
		Vec3		 Vec3::operator*(const Mat4& m4)
		{
			return Vec3(Vec4(*this, 1.0f)*m4);
		}
PointLight::PointLight(){
    ls = 1.0;
    color = RGBColor(1.0,1.0,1.0);
    position = Vec4(0.0,0.0,0.0);
}
Example #29
0
		Vec4		 Vec4::operator-(const Vec4& v) { return Vec4(this->x - v.x, this->y - v.y, this->z - v.z, this->w - v.w); }
Example #30
0
stitch::Vec4 stitch::Vec4::allOnes()
{
    return Vec4(1.0f);
}