void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		auto lightAzimuth = FullCircles(time * -0.5);
		light_pos.Set(
			Vec3f(
				Cos(lightAzimuth),
				1.0f,
				Sin(lightAzimuth)
			) * 2.0f
		);
		//
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.0f,
				Degrees(-45),
				Degrees(SineWave(time / 30.0) * 70)
			)
		);

		// set the model matrix
		model_matrix.Set(
			ModelMatrixf::RotationY(FullCircles(time * 0.05))
		);

		cube.Bind();
		gl.CullFace(Face::Back);
		cube_instr.Draw(cube_indices);
	}
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				4.0,
				Degrees(time * 25),
				Degrees(SineWave(time / 30.0) * 90)
			)
		);

		model_matrix.Set(
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time * 0.5)
			)
		);

		shape.Draw();

		thread_ready.Signal();
		parent_ready.Wait();
	}
Exemple #3
0
const Matrix<complex<double> > randomMatrix( Uniform<double>& generator, 
                                             const int dimension,
                                             const double upperBound ) {

    Matrix<complex<double> > tmp( dimension, dimension,
                                  complex<double>(0.0,0.0) );
    for ( int i=0; i<dimension; i++ ) {
        tmp[i][i] = generator.random();
        for ( int j=0; j<i; j++ ) {
            tmp[j][i] = complex<double>( generator.random() - 0.5,
                                         generator.random() - 0.5 );
            tmp[i][j] = conj( tmp[j][i] );
        }
    }

    double trace = 0.0;
    for ( int i=0; i<dimension; i++ ) {
        trace += tmp[i][i].real();
    }

    if ( trace < ZERO ) throw Fpe("trace too small");

    for ( int i=0; i<dimension; i++ ) {
        for ( int j=0; j<dimension; j++ ) {
            tmp[i][j] /= trace;
            tmp[i][j] *= upperBound;
        }
    }

    return tmp;

}
Exemple #4
0
	void Render(const PangoCairoLayout& layout)
	{
		_bitmap.Set(GLint(layout.Use()));
		_log_coords.Set(layout._log_coords);
		_tex_coords.Set(layout._tex_coords);
		_gl.DrawArrays(PrimitiveType::Points, 0, 1);
	}
Exemple #5
0
void Shader::extractShaderUniforms()
{
	GLuint pId = getProgramID();
	const int BUFF_SIZE = 255;
	int count;
	glGetProgramiv(pId, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &count);

	for (int i = 0; i < count; ++i)
	{
		char name[BUFF_SIZE]; // for holding the variable name
		GLint size = BUFF_SIZE;
		GLenum type;
		GLsizei length;
		GLsizei bufSize = BUFF_SIZE;
		glGetActiveUniform(pId, i, bufSize, &length, &size, &type, name);
		int location = glGetUniformLocation(pId, name);

		Uniform* uniform = UniformFactory::createUniform(name, type);
		uniform->addOwner(this,location);
		uniforms.insert(std::make_pair(uniform->getName(), uniform));

		//Borrar
		const char* uni_types[6] = { "Error", "FLOAT", "FLOAT_VEC3", "FLOAT_VEC4", "FLOAT_MAT3", "FLOAT_MAT4" };
		printf("Uniform name: %s. Type: %s.\n", uniform->getName().c_str(), uni_types[uniform->getType()]);	
	}
	printf("---------------\n");
}
Exemple #6
0
int main() {
  switch (2) {
    case 0: {
      // Sample uniform scalars.
      Uniform<> uniform;
      for (int i = 0; i < 100; i++) {
        cout << uniform.sample() << " ";
      }
      cout << endl;
      break;
    }
    case 1: {
      // Sample Gaussian.
      Vector2d mean;
      mean << -4, 10;
      Matrix<double, 2, 2> covariance;
      covariance << 3, -1.6, -1.6, 1;
      Gaussian<double, 2> gaussian(mean, covariance);
      Matrix2Xd samples(2, 1000);
      gaussian.sample(samples);
      // Output is where lots of mallocs and frees happen.
      cout << samples << endl;
      break;
    }
    case 2: {
      // Bag classification problem.
      testProblem(buildSqueezeProblem);
      break;
    }
  }
  return 0;
}
void Squad::read_members() {
    m_members_addr = m_df->enumerate_vector(m_address + m_mem->squad_offset("members"));

    short carry_food = m_df->read_short(m_address+m_mem->squad_offset("carry_food"));
    short carry_water = m_df->read_short(m_address+m_mem->squad_offset("carry_water"));
    int carry_ammo = m_df->enumerate_vector(m_address+m_mem->squad_offset("ammunition")).count();

    //read the uniforms
    int position = 0;
    Uniform *u;
    foreach(VIRTADDR addr, m_members_addr){
        u = new Uniform(m_df,this);

        m_members.insert(position,m_df->read_int(addr));
        read_equip_category(addr+m_mem->squad_offset("armor_vector"),ARMOR,u);
        read_equip_category(addr+m_mem->squad_offset("helm_vector"),HELM,u);
        read_equip_category(addr+m_mem->squad_offset("pants_vector"),PANTS,u);
        read_equip_category(addr+m_mem->squad_offset("gloves_vector"),GLOVES,u);
        read_equip_category(addr+m_mem->squad_offset("shoes_vector"),SHOES,u);
        read_equip_category(addr+m_mem->squad_offset("shield_vector"),SHIELD,u);
        read_equip_category(addr+m_mem->squad_offset("weapon_vector"),WEAPON,u);

        //add other items
        if(carry_ammo){
            u->add_uniform_item(addr+m_mem->squad_offset("quiver"),QUIVER);
            u->add_uniform_item(AMMO,-1,-1);
        }
        if(carry_food)
            u->add_uniform_item(addr+m_mem->squad_offset("backpack"),BACKPACK);
        if(carry_water)
            u->add_uniform_item(addr+m_mem->squad_offset("flask"),FLASK);

        m_uniforms.insert(position,u);
        position++;
    }
/***************************************************************
* Function: updateVSParameters()
***************************************************************/
void DSVirtualEarth::updateVSParameters(const Vec3 &viewDir, const Vec3 &viewPos)
{
    if (!mVirtualScenicHandler) return;

    /*  compute sun direction in world space: apply transforms resulted by viewer's orientation change, 
	guarantee that from the viewer's position, the virtual earth is always half illuminated. */
    Matrixd baserotMat;
    baserotMat.makeRotate(Vec3(0, 1, 0), gDesignStateFrontVect);
    Vec3 sunDirWorld = (CAVEAnimationModeler::ANIMVirtualEarthLightDir()) * baserotMat;
    StateSet *stateset = mEarthGeode->getStateSet();
    if (stateset)
    {
	Uniform *lightposUniform = stateset->getOrCreateUniform("LightPos", Uniform::FLOAT_VEC4);
	lightposUniform->set(Vec4(sunDirWorld, 0.0));
    }

    /* compute matrix combination that transforms a vector from shader space into world space */
    Matrixd latiMat;
    latiMat.makeRotate(mLati / 180.f * M_PI, Vec3(0, 1, 0));
    Matrixd equatorMat;   
    equatorMat.makeRotate((mTimeOffset / 12.f + mLongi / 180.f) * M_PI, Vec3(0, 0, 1));  
    Matrixd tiltaxisMat = mTiltAxisTrans->getMatrix();
    Matrixd eclipticMat = mEclipticTrans->getMatrix();
    Matrixd transMat = mUnitspaceMat * latiMat * equatorMat * tiltaxisMat * eclipticMat * baserotMat;

    /* updata environment rendering by passing parameters to VirtualScenicHandler */
    mVirtualScenicHandler->updateVSParameters(transMat, sunDirWorld, viewDir, viewPos);
}
Exemple #9
0
Uniform const& GLES_Shader::get_uniform_skin_matrix(void* data) const
{
    Command_Stream::Render_Context* ctx = (Command_Stream::Render_Context*)data;
    static Uniform u(Uniform::Type::VEC4, 1);
    if (u.get_count() == 1)
    {
        u = Uniform(Uniform::Type::VEC4, m_max_skin_nodes * 3);
    }
    if (ctx)
    {
        QASSERT(ctx->render_job_data->node_transform_count < m_max_skin_nodes);
        size_t count = math::min(ctx->render_job_data->node_transform_count, m_max_skin_nodes);
        if (u.get_count() == count * 3)
        {
            u = Uniform(Uniform::Type::VEC4, count * 3);
        }
        for (size_t i = 0; i < count; i++)
        {
            auto const& mat = ctx->render_job_data->node_transforms[i].mat;
            u.set(i*3 + 0, mat.get_row(0));
            u.set(i*3 + 1, mat.get_row(1));
            u.set(i*3 + 2, mat.get_row(2));
        }
    }
    return u;
}
Exemple #10
0
	void SetLightAndCamera(const Vec3f& light, const Mat4f& camera)
	{
		// use the shading program
		prog.Use();
		// set the uniforms
		light_pos.Set(light);
		camera_matrix.Set(camera);
	}
Exemple #11
0
bool pushUniform_sub(const std::string& name, const Uniform& uniform, UniformStack& stack) {
    auto p = uniform.find(name);
    if (p != uniform.end()) {
        stack[name].push(p->second);
        return true;
    }
    return false;
}
Exemple #12
0
void Shader::SetUniformValueByIndex(int32 uniformIndex, const Matrix3 & matrix)
{
	DVASSERT(uniformIndex >= 0 && uniformIndex < activeUniforms);
	Uniform* currentUniform = GET_UNIFORM(uniformIndex);
	if(currentUniform->ValidateCache(matrix) == false)
	{
		RENDER_VERIFY(glUniformMatrix3fv(currentUniform->location, 1, GL_FALSE, matrix.data));
	}
}
Exemple #13
0
void Shader::SetUniformValueByIndex(int32 uniformIndex, const Vector4 & vector)
{
	DVASSERT(uniformIndex >= 0 && uniformIndex < activeUniforms);
	Uniform* currentUniform = GET_UNIFORM(uniformIndex);
	if(currentUniform->ValidateCache(vector) == false)
	{
		RENDER_VERIFY(glUniform4fv(currentUniform->location, 1, &vector.x));
	}
}
Exemple #14
0
void Shader::SetUniformValueByIndex(int32 uniformIndex, float32 value)
{
	DVASSERT(uniformIndex >= 0 && uniformIndex < activeUniforms);
	Uniform* currentUniform = GET_UNIFORM(uniformIndex);
	if(currentUniform->ValidateCache(value) == false)
	{
		RENDER_VERIFY(glUniform1f(currentUniform->location, value));
	}
}
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();
		// make the camera matrix orbiting around the origin
		// at radius of 3.5 with elevation between 15 and 90 degrees
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				5.0,
				Degrees(time * 11),
				Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)*0.5*75)
			)
		);
		ModelMatrixf identity;
		// make the model transformation matrix
		ModelMatrixf model =
			ModelMatrixf::Translation(0.0f, 1.5f, 0.0) *
			ModelMatrixf::RotationZ(Degrees(time * 43))*
			ModelMatrixf::RotationY(Degrees(time * 63))*
			ModelMatrixf::RotationX(Degrees(time * 79));
		// make the reflection matrix
		auto reflection = ModelMatrixf::Reflection(false, true, false);
		//
		gl.Disable(Capability::Blend);
		gl.Disable(Capability::DepthTest);
		gl.Enable(Capability::StencilTest);
		gl.ColorMask(false, false, false, false);
		gl.StencilFunc(CompareFunction::Always, 1, 1);
		gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Replace);

		gl.Bind(plane);
		model_matrix.Set(identity);
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

		gl.ColorMask(true, true, true, true);
		gl.Enable(Capability::DepthTest);
		gl.StencilFunc(CompareFunction::Equal, 1, 1);
		gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Keep);

		// draw the cube using the reflection program
		model_matrix.Set(reflection * model);
		gl.Bind(cube);
		cube_instr.Draw(cube_indices);

		gl.Disable(Capability::StencilTest);

		// draw the cube using the normal object program
		model_matrix.Set(model);
		cube_instr.Draw(cube_indices);

		// blend-in the plane
		gl.Enable(Capability::Blend);
		gl.BlendEquation(BlendEquation::Max);
		gl.Bind(plane);
		model_matrix.Set(identity);
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
	}
 void Reshape(GLuint width, GLuint height) {
     gl.Viewport(width, height);
     Mat4f projection =
       CamMatrixf::PerspectiveX(Degrees(70), float(width) / height, 1, 30);
     object_prog.Use();
     object_projection_matrix.Set(projection);
     shadow_prog.Use();
     shadow_projection_matrix.Set(projection);
 }
Exemple #17
0
bool popUniform_sub(const std::string& name, Uniform& uniform, UniformStack& stack) {
    auto p = uniform.find(name);
    if (p != uniform.end()) {
        p->second = stack[name].top();
        stack[name].pop();
        return true;
    }
    return false;
}
Exemple #18
0
void Shader::SetUniformColor4ByIndex(int32 uniformIndex, const Color & color)
{
	DVASSERT(uniformIndex >= 0 && uniformIndex < activeUniforms);
	Uniform* currentUniform = GET_UNIFORM(uniformIndex);
	if(currentUniform->ValidateCacheColor4(color) == false)
	{
		RENDER_VERIFY(glUniform4fv(currentUniform->location, 1, &color.r));
	}
}
void printRandoms()
{
  Uniform<T> x;
  //x.seed((unsigned int)time(0));
  x.seed(5);
  int N=5;
  for (int i = 0; i < N; ++i) 
    cout << setprecision(digits10(T())) << LD_HACK(x.random()) << endl;

  cout << endl;
}
Exemple #20
0
bool Pass::hasUniformState(const char* name) const
{
  if (!m_program)
    return false;

  Uniform* uniform = m_program->findUniform(name);
  if (!uniform)
    return false;

  return !uniform->isShared();
}
Exemple #21
0
void getUniformNumbersAsArray(Array * targetArray,const Uniform & u){
	const value_t *v = reinterpret_cast<const value_t*>(u.getData());
	const size_t numSingleValues = u.getDataSize() / sizeof(value_t);
	ERef<Array> arr;
	for(size_t i=0;i<numSingleValues;++i){
		if( (i%bucketSize) == 0){
			arr=Array::create();
			targetArray->pushBack(arr.get());
		}
		arr->pushBack(Number::create(v[i]));
	}
}
Exemple #22
0
	void Reshape(GLuint width, GLuint height)
	{
		gl.Viewport(width, height);
		viewport_dimensions.Set(Vec2f(width, height));
		projection_matrix.Set(
			CamMatrixf::PerspectiveX(
				Degrees(60),
				double(width)/height,
				1, 50
			)
		);
	}
Exemple #23
0
    Eigen::VectorXd sample(const Uniform &d, RNG &rng)
    {
      std::uniform_real_distribution<double> dist(0, 1);

      Eigen::ArrayXd sample(length(d));
      for (Eigen::ArrayXd::Index i = 0; i < sample.rows(); i++)
      {
        sample(i) = dist(rng);
      }

      // Transform the output to fit within the support of the distribution
      return d.min().array() + sample * (d.max() - d.min()).array();
    }
Exemple #24
0
 void IEffect::UseCustomTexture(Texture* texture)
 {        
     Uniform CustomTexture;
     std::ostringstream toSTR; toSTR << "uTex" << TextureUnits;
     CustomTexture.Name = toSTR.str();
     CustomTexture.Type = DataType::Int;
     CustomTexture.Usage = PostEffects::Other;
     CustomTexture.SetValue(&TextureUnits);
     AddUniform(CustomTexture);
     
     // Set RTT Order
     RTTOrder.push_back(RTT::Info(texture, RTT::CustomTexture, TextureUnits));
     
     TextureUnits++;
 }
Exemple #25
0
 void IEffect::UseLastRTT()
 {        
     Uniform RTT;
     std::ostringstream toSTR; toSTR << "uTex" << TextureUnits;
     RTT.Name = toSTR.str();
     RTT.Type = DataType::Int;
     RTT.Usage = PostEffects::Other;
     RTT.SetValue(&TextureUnits);
     AddUniform(RTT);
     
     // Set RTT Order
     RTTOrder.push_back(RTT::Info(RTT::LastRTT, TextureUnits));
     
     TextureUnits++;
 }
Exemple #26
0
 void IEffect::UseDepth()
 {
     Uniform Depth;
     std::ostringstream toSTR; toSTR << "uTex" << TextureUnits;
     Depth.Name = toSTR.str();
     Depth.Type = DataType::Int;
     Depth.Usage = PostEffects::Other;
     Depth.SetValue(&TextureUnits);
     AddUniform(Depth);
     
     // Set RTT Order
     RTTOrder.push_back(RTT::Info(RTT::Depth, TextureUnits));
     
     TextureUnits++;
 }
Exemple #27
0
 void IEffect::UseColor()
 {
     Uniform Color;
     std::ostringstream toSTR; toSTR << "uTex" << TextureUnits;
     Color.Name = toSTR.str();
     Color.Type = DataType::Int;
     Color.Usage = PostEffects::Other;
     Color.SetValue(&TextureUnits);
     AddUniform(Color);
     
     // Set RTT Order
     RTTOrder.push_back(RTT::Info(RTT::Color, TextureUnits));
     
     TextureUnits++;
 }
int CFeasibilityMap::count_x_out_fn(CData &Data,int i_tau, int i_original,int n_simul, Uniform &randUnif) {
	
  // double case2_count_out = 0;
	int case2_count_out = 0; // Changed by Hang on 5/16/2015
	
  ColumnVector s_i = tau_to_s_fn( i_tau, Data.n_var );   
  ColumnVector item_by_joint = Data.copy_non_balance_edit(s_i);
  ColumnVector tilde_y_i = Data.log_D_Observed.row(i_original).t();
  
	for (int i_simul=1; i_simul<=n_simul; i_simul++){
			//Generate from uniform distribution
			ColumnVector y_q = tilde_y_i;
			for ( int temp_j=1; temp_j<=Data.n_var; temp_j++ ){
				if ( item_by_joint(temp_j)==1 ){
					y_q(temp_j) = Data.logB_L(temp_j)+Data.logB_U_L(temp_j)*randUnif.Next(); 
				} 
			} 
	
			ColumnVector x_q = exp_ColumnVector(y_q) ;
      Data.update_full_x_for_balance_edit(x_q);
			// if (!Data.PassEdits(x_q)) { case2_count_out += 1.0;}
      if (!Data.PassEdits(x_q)) { case2_count_out += 1;}  // Changed by Hang on 5/16/2015
	} 
  if (case2_count_out ==0) {
    case2_count_out = 1;
  }
	return case2_count_out; // ADDED by Hang on 5/16/2015
}
Exemple #29
0
void ShVarModel::setRecursiveUniformValues(ShVarItem *item, const Uniform& u)
{
	if (!item)
		return;

	if (item->getFullName() == u.name()) {
		dbgPrint(DBGLVL_INFO, "found uniform: %s\n", u.name().toAscii().data());
		item->setData(DF_DEBUG_UNIFORM_VALUE, u.toString());
		emit dataChanged(ShVarModel::getIndex(item, 0),
				ShVarModel::getIndex(item, DF_LAST - 1));
	} else {
		for (int i = 0; i < item->childCount(); ++i) {
			setRecursiveUniformValues(item->child(i), u);
		}
	}
}
Exemple #30
0
/*
=============
OpenGLProgram::SetUniform

	Sets a uniform int value.
=============
*/
void OpenGLProgram::SetUniform( const char* name, const int* value, unsigned size ) {	
	Uniform* cachedUniform = GetCachedUniform( name );
    if ( cachedUniform ) {
        cachedUniform->Set( value );
    } else {
	    //Not found
        GLint location = glGetUniformLocation( m_programID, name );
	    if ( location > -1 ) {
		    Uniform* newUniform = new Uniform( location, name, size );
		    newUniform->Set( value );
        
            m_uniforms[StringUtils::Hash( name )] = ( newUniform );
	    } else {
			printf( "Could not find int uniform: %s\n", name );
        }
    }
}