QuadBuff<DrawVert> *make_cube( float size, vec3f center )
{
    QuadBuff<DrawVert> *gbuff = new QuadBuff<DrawVert>();
    
    DrawVert *cubeVert = gbuff->addVerts( NUM_CUBE_VERTS );
    
    for (int i=0; i < NUM_CUBE_VERTS; ++i)
    {
        cubeVert->m_pos = vec3f( (_cubeVertData[i*6 + 0] * size) - center.x,
                                 (_cubeVertData[i*6 + 1] * size) - center.y,
                                 (_cubeVertData[i*6 + 2] * size) - center.z );
 
        cubeVert->m_nrm = vec3f( (_cubeVertData[i*6 + 3] * size) - center.x,
                                 (_cubeVertData[i*6 + 4] * size) - center.y,
                                 (_cubeVertData[i*6 + 5] * size) - center.z );
        
        // TODO: better cube texture coords
        if ( ((i/6)==2) || ((i/6)==5) )
        {
            cubeVert->m_st = vec4f( _cubeVertData[i*6 + 1] + 0.5, _cubeVertData[i*6 + 2] + 0.5, 0.0, 0.0 );
        }
        else
        {
            cubeVert->m_st = vec4f( _cubeVertData[i*6 + 0] + 0.5, _cubeVertData[i*6 + 1] + 0.5, 0.0, 0.0 );            
        }
        
        cubeVert++;
    }
    
    return gbuff;
}
Пример #2
0
void glutils_set_material(const vec3f& ke, const vec3f& ka, const vec3f& kd, const vec3f& ks, float n) {
    auto _ke = vec4f(ke.x,ke.y,ke.z,1);
    auto _ka = vec4f(ka.x,ka.y,ka.z,1);
    auto _kd = vec4f(kd.x,kd.y,kd.z,1);
    auto _ks = vec4f(ks.x,ks.y,ks.z,1);
    glutils_set_material(_ke, _ka, _kd, _ks, n);
}
Пример #3
0
void RAction::draw(float dt) {
    if(isFinished()) return;

    glDisable(GL_TEXTURE_2D);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    vec2f src  = source->getPos();
    vec2f dest = target->getAbsolutePos();

    vec2f offset     = (dest - src).normal().perpendicular() * target->getSize() * 0.5;
    vec2f offset_src = offset * 0.3f;

    float max_alpha = 1.0f;
    float alpha = max_alpha * (1.0f - progress);

    float alpha2 = alpha * 0.1f;

    vec4f col1 = vec4f(colour, alpha);
    vec4f col2 = vec4f(colour, alpha2);

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    glBegin(GL_QUADS);
        glColor4fv(col2);

        glVertex2f(src.x - offset_src.x, src.y - offset_src.y);
        glVertex2f(src.x + offset_src.x, src.y + offset_src.y);

        glColor4fv(col1);

        glVertex2f(dest.x + offset.x, dest.y + offset.y);
        glVertex2f(dest.x - offset.x, dest.y - offset.y);
    glEnd();
}
Пример #4
0
void spothdl::update()
{
	/* TODO Assignment 2: Update both the direction and position of the light using the position and orientation
	 * of the attached model. See above.
	 */
	if(model)
	{
		glTranslatef(model->position[0], model->position[1], model->position[2]);
		glRotatef(radtodeg(model->orientation[0]), 1.0, 0.0, 0.0);
		glRotatef(radtodeg(model->orientation[1]), 0.0, 1.0, 0.0);
		glRotatef(radtodeg(model->orientation[2]), 0.0, 0.0, 1.0);

		GLdouble modelview[16];
		glGetDoublev( GL_TRANSPOSE_MODELVIEW_MATRIX, modelview );
		mat4f mdvl;
		for(int i = 0; i < 16; i++){
			int row = i / 4;
			int col = i % 4;
			mdvl[row][col] = modelview[i];
		}

		mat4f normal = transpose(inverse(mdvl));
		direction = normal * vec4f(0.0, 0.0, -1.0, 0.0);

		vec4f p = mdvl * vec4f(0.0, 0.0, 0.0, 1.0);
		position = p(0,3)/p[3];

		glRotatef(-radtodeg(model->orientation[2]), 0.0, 0.0, 1.0);
		glRotatef(-radtodeg(model->orientation[1]), 0.0, 1.0, 0.0);
		glRotatef(-radtodeg(model->orientation[0]), 1.0, 0.0, 0.0);		 	
	 	glTranslatef(-model->position[0], -model->position[1], -model->position[2]);
	}
}
Пример #5
0
void VHParticlesRender::calcVectors()
{
    // get model view matrix
    glGetFloatv(GL_MODELVIEW_MATRIX, (float *) modelView.get_value());

    // calculate eye space light vector
    lightVector = normalize(lightPos);
    lightPosEye = modelView * vec4f(lightPos, 1.0);

    // calculate half-angle vector between view and light
    viewVector = -vec3f(modelView.get_row(2));
    if (dot(viewVector, lightVector) > 0) {
        halfVector = normalize(viewVector + lightVector);
        invertedView = false;
    } else {
        halfVector = normalize(-viewVector + lightVector);
        invertedView = true;
    }

    // calculate light view matrix
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    gluLookAt(lightPos[0], lightPos[1], lightPos[2], 
              lightTarget[0], lightTarget[1], lightTarget[2],
              0.0, 1.0, 0.0);

    // calculate light projection matrix
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPerspective(45.0, 1.0, 1.0, 200.0);

    glGetFloatv(GL_MODELVIEW_MATRIX, (float *) lightView.get_value());
    glGetFloatv(GL_PROJECTION_MATRIX, (float *) lightProj.get_value());

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    // construct shadow matrix
    matrix4f scale;
    scale.set_scale(vec3f(0.5, 0.5, 0.5));
    matrix4f translate;
    translate.set_translate(vec3f(0.5, 0.5, 0.5));

    shadowMatrix = translate * scale * lightProj * lightView * inverse(modelView);

    // calc object space eye position
    eyePos = inverse(modelView) * vec4f(0.0, 0.0, 0.0, 1.0);

    // calc half vector in eye space
    halfVectorEye = modelView * vec4f(halfVector, 0.0);

}
Пример #6
0
vec4f PhysActor_PhysX::GetRotation()
{
	if (impl && impl->physActor)
	{
		auto trans = impl->physActor->getGlobalPose();

		return vec4f(trans.q.x, trans.q.y, trans.q.z, trans.q.w);
	}

	return vec4f(0.0f, 0.0f, 0.0f, 0.0f);
}
Пример #7
0
 bool CAssimpMesh::ExtractMaterials(const aiScene* pScene)
 {
     CCacheResourceManager& res = CCacheResourceManager::Instance();
     
     // Initialize the materials
     for (uint32 i = 0 ; i < pScene->mNumMaterials ; i++) {
         CMaterial* material = new CMaterial();
         const aiMaterial* pMaterial = pScene->mMaterials[i];
         
         material->diffuseTexture = NULL;
         
         if (pMaterial->GetTextureCount(aiTextureType_DIFFUSE) > 0) {
             aiString path;
             
             if (pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) {
                 material->diffuseTexture = (CTexture*)res.LoadTexture2D(path.data);
             }
         }
         
         struct aiColor4D specular, diffuse, ambient;
         vec4f zero;
         
         //diffuse
         if((AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_DIFFUSE, &diffuse)))
             material->diffuse = vec4f(diffuse.r, diffuse.g, diffuse.b, diffuse.a);
         else
             material->diffuse = zero;
         
         //ambiant
         if((AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_AMBIENT, &ambient)))
             material->ambient = vec4f(ambient.r, ambient.g, ambient.b, ambient.a);
         else 
             material->ambient = zero;	
         
         //specular
         if((AI_SUCCESS == aiGetMaterialColor(pMaterial, AI_MATKEY_COLOR_SPECULAR, &specular)))
             material->specular = vec4f(specular.r, specular.g, specular.b, specular.a);
         else 
             material->specular = zero;	
         
         //shininess
         aiGetMaterialFloat(pMaterial,AI_MATKEY_SHININESS,&material->shininess);
         if(material->shininess <1.0f)
             material->shininess = 15;
         
         aiGetMaterialFloat(pMaterial,AI_MATKEY_OPACITY,&material->opacity);
         if(material->opacity< 1.f)
             material->isTransparent = true;
         
         aiGetMaterialInteger(pMaterial,AI_MATKEY_TWOSIDED,&material->twoSided);
         m_pMeshBuffer->AddMaterial(material);
     }
     return true;
 }
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void MyWindow::display()
{
  WindowInertiaCamera::display();
  if(!s_pCurRenderer->valid())
  {
      glClearColor(0.5,0.0,0.0,0.0);
      glClear(GL_COLOR_BUFFER_BIT);
      swapBuffers();
      return;
  }
  float dt = (float)m_realtime.getTiming();
  //
  // render the scene
  //
  std::string stats;
  static std::string hudStats = "...";
  {
    nv_helpers::Profiler::FrameHelper helper(g_profiler,sysGetTime(), 2.0, stats);
    PROFILE_SECTION("display");

    s_pCurRenderer->display(m_camera, m_projection);
    //
    // additional HUD stuff
    //
    WindowInertiaCamera::beginDisplayHUD();
    s_helpText -= dt;
    m_oglTextBig.drawString(5, 5, "('h' for help)", 1, vec4f(0.8,0.8,1.0,0.5f).vec_array);
    float h = 30;
    if(s_bStats)
        h += m_oglTextBig.drawString(5, m_winSz[1]-h, hudStats.c_str(), 0, vec4f(0.8,0.8,1.0,0.5).vec_array);
    if(s_helpText > 0)
    {
        // camera help
        const char *txt = getHelpText();
        h += m_oglTextBig.drawString(5, m_winSz[1]-h, txt, 0, vec4f(0.8,0.8,1.0,s_helpText/HELPDURATION).vec_array);
        h += m_oglTextBig.drawString(5, m_winSz[1]-h, s_sampleHelp, 0, vec4f(0.8,0.8,1.0,s_helpText/HELPDURATION).vec_array);
    }
    WindowInertiaCamera::endDisplayHUD();
    {
      //PROFILE_SECTION("SwapBuffers");
      swapBuffers();
    }
  } //PROFILE_SECTION("display");
  //
  // Stats
  //
  if (s_bStats && (!stats.empty()))
  {
    hudStats = stats; // make a copy for the hud display
  }

}
Пример #9
0
void ParticleSystem::reset(float size)
{
    vec4f *pos = m_pos->map();
    for(size_t i=0; i<m_size; i++) {
        pos[i] = vec4f(sfrand()*size, sfrand()*size, sfrand()*size, 1.0f);
    }
    m_pos->unmap();

    vec4f *vel = m_vel->map();
    for(size_t i=0; i<m_size; i++) {
        vel[i] = vec4f(0.0f, 0.0f, 0.0f, 1.0f);
    }
    m_vel->unmap();
}
Пример #10
0
vec3f SceneObject::getWorldNormal(unsigned fi, const vec3f& position, bool flat) const 
{
	vec3f original_normal = SimpleShape::getWorldNormal(fi, position, flat);
	if(bumpTex.size() <= 1 || fi >= faceVertexTexCoordIndexList.size())
		return original_normal;

	printf("use not original normal\n");

	vec3f vps[3], vts[3], vns[3];
	for(unsigned i=0; i<3; i++)
	{
		vps[i] = getWorldVertexPosition(faceVertexIndexList[fi][i]);
		if(faceVertexTexCoordIndexList[fi][i] >= vertexTexCoordList.size())
			return original_normal;
		vts[i] = vertexTexCoordList[faceVertexTexCoordIndexList[fi][i]];
	}
	vec3f uv_grad = bumpTex.getGrad(getTexCoord(fi, position));
	vec3f b1 = vps[1] - vps[0];
	vec3f b2 = vps[2] - vps[0];
	vec3f duv1 = vts[1] - vts[0];
	vec3f duv2 = vts[2] - vts[0];
	float k2 = (uv_grad.x*duv1.y - uv_grad.y*duv1.x) / (duv1.y*duv2.x - duv1.x*duv2.y);
	float k1 = (uv_grad.y - k2*duv2.y) / duv1.y;
	b1.normalize();
	b2.normalize();
	vec3f dl = k1*b1+k2*b2;
	vec3f dh = original_normal*uv_grad.z;
	if(dh.length()*1000 < dl.length())
		return original_normal;
	float angle = atan2(dh.length(), dl.length());
	vec3f axis = dl.cross(dh);
	axis.normalize();
	return vec3f(rotMat(axis, angle) * vec4f(original_normal, 0));
}
Пример #11
0
GLMeshBuffer* GLMeshBuffer::PrepareMeshBufferForDrawingNormals(float len, U32 ctVertices, U32 fstep,
                                                               const vector<float>& arrVertices,
                                                               const vector<float>& arrNormals) {
    if(arrVertices.size() == 0 || arrNormals.size() == 0)
        return NULL;

    vector<float> allvertices;
    allvertices.resize(ctVertices* 3 * 2);
    for(U32 i=0; i < ctVertices; i++) {
        vec3f ptStart = vec3f(&arrVertices[i * fstep]);
        vec3f ptEnd = ptStart + vec3f(&arrNormals[i*3]) * len;
        allvertices[i*6] = ptStart.x;
        allvertices[i*6 + 1] = ptStart.y;
        allvertices[i*6 + 2] = ptStart.z;
        allvertices[i*6 + 3] = ptEnd.x;
        allvertices[i*6 + 4] = ptEnd.y;
        allvertices[i*6 + 5] = ptEnd.z;
    }

    //Create scene node
    GLMeshBuffer* lpDrawNormal = new GLMeshBuffer();
    lpDrawNormal->setupPerVertexColor(vec4f(0,0,1,1), ctVertices*2, 4);
    lpDrawNormal->setupVertexAttribs(allvertices, 3, vatPosition);
    lpDrawNormal->setFaceMode(ftLines);

    return lpDrawNormal;
}
Particle LightParticleEmitter::makeParticle(float frameTimePassed, float deltaTime, vec3f position) {
	(void) frameTimePassed;
	(void) deltaTime;
	vec3f vel = glm::sphericalRand(3.0f);
	Particle pt;
    pt.life = 0.2;
    pt.startSize =1;
    pt.endSize = 0;
	pt.startCol = vec4f(col, 0.7);
	pt.endCol = vec4f(col, 0);
	pt.v = glm::length(position-oldWorldPos) > 0? glm::normalize(position - oldWorldPos )*-2.0f + vel:vel;
    pt.p = position + (glm::length(position-oldWorldPos) > 0? (position - oldWorldPos)*2.0f:vec3f(0.0f));
    pt.a = glm::sphericalRand(10.0f);
    pt.texIndex = 1;
	return pt;
}
Пример #13
0
void Level00::RenderGrid()
{
	int i, j;
	for (i = 0; i < numSpheresX; i++)
	{
		for (j = 0; j < numSpheresY; j++)
		{
			auto pos = mGrid.graph.grid[i][j].worldPos;
			auto hasLight = mGrid.graph.grid[i][j].hasLight;
			auto weight = mGrid.graph.grid[i][j].weight;

			vec4f c;
			switch ((int)weight) {
			case -10:
				c = Colors::magenta;
				break;
			case -2:
				c = Colors::red;
				break;
			case -1:
				c = Colors::yellow;
				break;
			case 0:
				c = Colors::green;
				break;
			default:
				c = vec4f(0, 0, weight*0.01f, 1);
				break;
			}
			//TRACE_BOX(pos, hasLight ? Colors::cyan : Colors::magenta);
			TRACE_SMALL_BOX(pos, c);
		}
	}
}
Пример #14
0
void Level00::HandleInput(Input& input)
{
	// Player Mouse

	if (input.GetKeyDown(KEYCODE_1))
	{
		Application::SharedInstance().LoadScene<MainMenuScene>();
	}

	if (input.GetMouseButtonDown(MOUSEBUTTON_LEFT))
	{
		float x = (2.0f * input.mousePosition.x) / mRenderer->GetWindowWidth() - 1.0f;
		float y = 1.0f - (2.0f * input.mousePosition.y) / mRenderer->GetWindowHeight();

		mat4f toWorld = (mQuadShaderData.Projection * mQuadShaderData.View).inverse();
		vec3f worldPos = vec4f(x, y, 0.0f, 1.0f) * toWorld;
		vec3f worldDir = vec3f(0.0f, 0.0f, 1.0f);
		worldPos.z = -30.0f;

		Ray<vec3f> ray = { worldPos, worldDir };

		RayCastHit<vec3f> hit;
		if (RayCast(&hit, ray, mLightColliders, mCircleCount))
		{
			mCircleColorWeights[hit.index] = mCircleColorWeights[hit.index] > 0 ? 0.0f : 1.0f;
		}
	}
}
Пример #15
0
Particle FireParticleEmitter::makeParticle(float frameTimePassed, float deltaTime, vec3f position) {
	(void) frameTimePassed;
	(void) deltaTime;
	vec3f vel = glm::sphericalRand(3.0f);
	Particle pt;
	pt.life = 1;
	pt.startSize =1;
	pt.endSize = 0.5;
	pt.startCol = vec4f(1, Utils::randomFloat(0, 0.4), 0.01, 0.1);
	pt.endCol = vec4f(1, 0.4, 0.09, 0);
	pt.v = (currWorldPos - oldWorldPos )*-30.0f + vel;
	pt.p = position + pt.v/10.0f;
	pt.a = vec3f(0,1,0);
	pt.texIndex = 0;
	return pt;
}
Пример #16
0
// 4D
vec4f operator+(const vec4f& v1, const vec4f &v2)
{
	return vec4f(v1.peekx()+v2.peekx(),
                 v1.peeky()+v2.peeky(),
                 v1.peekz()+v2.peekz(),
				 v1.peekw()+v2.peekw());
}
Пример #17
0
int main ()
{
  printf ("Results of line_list_test:\n");
  
  LineList::Pointer list = LineList::Create ();

  list->SetMaterial ("material1");

  list->Reserve (10);

  for (size_t i=0; i<10; i++)
  {
    LineDesc s;
    
    for (int j=0; j<2; j++)
    {
      s.point [j].position   = vec3f (float (i), 0, float (j));
      s.point [j].color      = vec4f (1.0f, float (j), 0.5f, 0.25f);
      s.point [j].tex_offset = vec2f (float (i), float (j));
    }

    list->Insert (s);
  }    

  MyVisitor visitor;

  list->VisitEach (visitor, NodeTraverseMode_TopToBottom);  

  return 0;
}
Пример #18
0
void RGBDSensor::savePointCloud( const std::string& filename, const mat4f& transform /*= mat4f::identity()*/ ) const
{
	//DepthImage d(getDepthHeight(), getDepthWidth(), getDepthFloat());
	//ColorImageRGB c(d);
	//FreeImageWrapper::saveImage("test.png", c, true);

	PointCloudf pc;
	for (unsigned int i = 0; i < getDepthWidth()*getDepthHeight(); i++) {
		unsigned int x = i % getDepthWidth();
		unsigned int y = i / getDepthWidth();

		float d = getDepthFloat()[i];
		if (d != 0.0f && d != -std::numeric_limits<float>::infinity()) {
			vec3f p = getDepthIntrinsicsInv()*vec3f((float)x*d, (float)y*d, d);

			//TODO check why our R and B is flipped
			vec4f c = vec4f(getColorRGBX()[i].z, getColorRGBX()[i].y, getColorRGBX()[i].x, getColorRGBX()[i].w);
			c /= 255.0f;

			pc.m_points.push_back(p);
			pc.m_colors.push_back(c);
		}
	}

	PointCloudIOf::saveToFile(filename, pc);
}
Пример #19
0
    void setValue(const float *value)
    {
        ptr<SceneNode> scene = manager->loadResource("scene").cast<SceneNode>();
        ptr<Module> o = find(scene, path).cast<Module>();
        if (o == NULL) {
            return;
        }
        set<Program *> progs = o->getUsers();
        for(set<Program *>::iterator i = progs.begin(); i != progs.end(); ++i) {
            ptr<Uniform> u = (*i)->getUniform(name);
            if (u != NULL) {
                switch (dim) {
                case 1:
                    u.cast<Uniform1f>()->set(value[0]);
                    break;
                case 2:
                    u.cast<Uniform2f>()->set(vec2f(value[0], value[1]));
                    break;
                case 3:
                    u.cast<Uniform3f>()->set(vec3f(value[0], value[1], value[2]));
                    break;
                case 4:
                    u.cast<Uniform4f>()->set(vec4f(value[0], value[1], value[2], value[4]));
                    break;
                }

            }
        }
    }
Пример #20
0
void RGBDSensor::computePointCurrentPointCloud(PointCloudf& pc, const mat4f& transform /*= mat4f::identity()*/) const
{
	if (!(getColorWidth() == getDepthWidth() && getColorHeight() == getDepthHeight()))	throw MLIB_EXCEPTION("invalid dimensions");

	for (unsigned int i = 0; i < getDepthWidth()*getDepthHeight(); i++) {
		unsigned int x = i % getDepthWidth();
		unsigned int y = i / getDepthWidth();
		vec3f p = depthToSkeleton(x,y);
		if (p.x != -std::numeric_limits<float>::infinity() && p.x != 0.0f)	{

			vec3f n = getNormal(x,y);
			if (n.x != -FLT_MAX) {
				pc.m_points.push_back(p);
				pc.m_normals.push_back(n);
				vec4uc c = m_colorRGBX[i];
				pc.m_colors.push_back(vec4f(c.z/255.0f, c.y/255.0f, c.x/255.0f, 1.0f));	//there's a swap... dunno why really
			}
		}
	}
	for (auto& p : pc.m_points) {
		p = transform * p;
	}
	mat4f invTranspose = transform.getInverse().getTranspose();
	for (auto& n : pc.m_normals) {
		n = invTranspose * n;
		n.normalize();
	}
}
Пример #21
0
    ForestOrthoLayerResource(ptr<ResourceManager> manager, const string &name, ptr<ResourceDescriptor> desc,
            const TiXmlElement *e = NULL) :
        ResourceTemplate<40, ForestOrthoLayer> (manager, name, desc)
    {
        e = e == NULL ? desc->descriptor : e;
        ptr<GraphProducer>graphProducer;
        int displayLevel = 0;
        vec4f color = vec4f((float)30/255,(float)62/255,(float)45/255, 1.0f);

        checkParameters(desc, e, "name,graph,renderProg,level,color,quality,");
        string g = getParameter(desc, e, "graph");

        graphProducer = manager->loadResource(g).cast<GraphProducer>();
        if (e->Attribute("level") != NULL) {
            getIntParameter(desc, e, "level", &displayLevel);
        }
        if (e->Attribute("quality") != NULL) {
            quality = strcmp(e->Attribute("quality"), "true") == 0;
        }

        if (e->Attribute("color") != NULL) {
            string c = getParameter(desc, e, "color") + ",";
            string::size_type start = 0;
            string::size_type index;
            for (int i = 0; i < 3; i++) {
                index = c.find(',', start);
                color[i] = (float) atof(c.substr(start, index - start).c_str()) / 255;
                start = index + 1;
            }
        }

        ptr<Program> layerProgram = manager->loadResource(getParameter(desc, e, "renderProg")).cast<Program>();
        init(graphProducer, layerProgram, displayLevel, quality, color);
    }
Пример #22
0
	ParticleEmitter::ParticleEmitter() :
		m_Shader((std::string(Config::ASSET_PATH) + "/Shaders/" + SHADERS[0]).c_str(), (std::string(Config::ASSET_PATH) + "/Shaders/" + SHADERS[1]).c_str()),
		m_Manager(this), m_ParticleRenderer(nullptr), m_Links(5), m_Beams(1), m_Width(1.0f)
	{
		float points[] = 
		{
			0.0f, 0.0f, 1.0f,
			0.0f, 1.0f, 1.0f,
			1.0f, 0.0f, 1.0f,
			1.0f, 1.0f, 1.0f
		};

		::VertexData data;
		data.drawType = GL_TRIANGLE_STRIP;
		data.initialPoints = points;
		data.numOfFloats = 3;
		data.vertexCount = 4;

		//setup the particle renderer
		m_ParticleRenderer = New ParticleRenderer < ParticleManager, VertexFormat>(data, ::ParticleAttributeData("i_Position", 3, sizeof(float) * 3),
		{ ::ParticleAttributeData("i_PointB", 3, sizeof(VertexFormat), sizeof(float) * 7),::ParticleAttributeData("i_PointA", 3, sizeof(VertexFormat), sizeof(float) * 4), ::ParticleAttributeData("i_Color", 4, sizeof(VertexFormat)) },
		&m_Manager, 1000, 1);

		m_Timer.SetInterval(INITIAL_FREQUENCY);

		srand(time(0));

		m_Color = vec4f(1.0f,1.0f, 1.0f, 1.0f);


	}
Пример #23
0
void directionalhdl::update()
{
	/* TODO Assignment 2: Update the direction of the light using the orientation of the attached model.
	 * The easiest thing is to do translations and rotations like you were going to render the object, and
	 * then just multiply some initial direction vector by the normal matrix.
	 */
	if(model)
	{
		glTranslatef(model->position[0], model->position[1], model->position[2]);
		glRotatef(radtodeg(model->orientation[0]), 1.0, 0.0, 0.0);
		glRotatef(radtodeg(model->orientation[1]), 0.0, 1.0, 0.0);
		glRotatef(radtodeg(model->orientation[2]), 0.0, 0.0, 1.0);

		GLdouble modelview[16];
		glGetDoublev( GL_TRANSPOSE_MODELVIEW_MATRIX, modelview );
		mat4f mdvl;
		for(int i = 0; i < 16; i++){
			int row = i / 4;
			int col = i % 4;
			mdvl[row][col] = modelview[i];
		}

		mat4f normal = transpose(inverse(mdvl));
		direction = normal * vec4f(0.0, 0.0, -1.0, 0.0);

		glRotatef(-radtodeg(model->orientation[2]), 0.0, 0.0, 1.0);
		glRotatef(-radtodeg(model->orientation[1]), 0.0, 1.0, 0.0);
		glRotatef(-radtodeg(model->orientation[0]), 1.0, 0.0, 0.0);		 	
	 	glTranslatef(-model->position[0], -model->position[1], -model->position[2]);
	}
}
Пример #24
0
void pointhdl::update()
{
	/* TODO Assignment 2: Update the position of the light using the position of the attached model.
	 * The easiest thing is to do translations and rotations like you were going to render the object, and
	 * then just multiply the origin by the modelview matrix.
	 */
	if(model)
	{
		glTranslatef(model->position[0], model->position[1], model->position[2]);
		glRotatef(radtodeg(model->orientation[0]), 1.0, 0.0, 0.0);
		glRotatef(radtodeg(model->orientation[1]), 0.0, 1.0, 0.0);
		glRotatef(radtodeg(model->orientation[2]), 0.0, 0.0, 1.0);

		GLdouble modelview[16];
		glGetDoublev( GL_TRANSPOSE_MODELVIEW_MATRIX, modelview );
		mat4f mdvl;
		for(int i = 0; i < 16; i++){
			int row = i / 4;
			int col = i % 4;
			mdvl[row][col] = modelview[i];
		}

		vec4f p = mdvl * vec4f(0.0, 0.0, 0.0, 1.0);
		position = p(0,3)/p[3];

		glRotatef(-radtodeg(model->orientation[2]), 0.0, 0.0, 1.0);
		glRotatef(-radtodeg(model->orientation[1]), 0.0, 1.0, 0.0);
		glRotatef(-radtodeg(model->orientation[0]), 1.0, 0.0, 0.0);		 	
	 	glTranslatef(-model->position[0], -model->position[1], -model->position[2]);
	}
}
Пример #25
0
vec4f CCameraObject::GetVecFromScreenspace(uint32_t x, uint32_t y, uint32_t winWidth, uint32_t winHeight)
{
/*
	float percX = x / (float)winWidth;
	float percY = y / (float)winHeight;

	vec3f farPCenter(0.0f, 0.0f, -m_zFar);
	vec3f vpUp(0.0f, 1.0f, 0.0f);
	float farPHeight = 2.0f * tanf(m_curFOV / 2.0f) * m_zFar;
	float farPWidth = farPHeight * m_curAspect;

	float interpX = (-farPWidth * 0.5f) + (farPWidth * percX);
	float interpY = (farPHeight * 0.5f) - (farPHeight * percY);

	vec3f z(interpX, interpY, -m_zFar);
	z.normalize();
	vec4f z4(z.x, z.y, z.z, 0.0f);
	mat4f V = getMatrix(MATRIX_VIEW);
	V.invert();
	vec4f res = V * z;

	return res;
*/
	return vec4f(1.0, 1.0, 1.0, 1.0);
}
Пример #26
0
void Vizzer::init(ApplicationData &app)
{
    m_meshes.resize(20);

    //const FloatType radius, const ml::vec3<FloatType>& pos, const size_t stacks /*= 10*/, const size_t slices /*= 10*/, const ml::vec4<FloatType>& color
    for (int i = 0; i < 20; i++)
    {
        const vec3f pos = vec3f(util::randomUniform(-1.0f, 1.0f), util::randomUniform(-1.0f, 1.0f), util::randomUniform(-1.0f, 1.0f));
        const vec4f color = vec4f(util::randomUniform(0.5f, 1.0f), util::randomUniform(0.5f, 1.0f), util::randomUniform(0.5f, 1.0f), 1.0f);
        m_meshes[i].load(app.graphics, TriMeshf(Shapesf::sphere(util::randomUniform(0.1f, 0.2f), pos, 10, 10, color)));
    }
	
    const string shaderDir = "../../frameworkD3D11/shaders/";
    m_vsColor.load(app.graphics, shaderDir + "test.shader");
    m_psColor.load(app.graphics, shaderDir + "test.shader");

    m_constants.init(app.graphics);

    vec3f eye(1.0f, 1.0f, 4.5f);
    vec3f worldUp(0.0f, 0.0f, 1.0f);
    m_camera = Cameraf(-eye, worldUp, vec3f::origin, 60.0f, (float)app.window.getWidth() / app.window.getHeight(), 0.01f, 1000.0f, true);

    m_font.init(app.graphics, "Calibri");

    m_world = mat4f::identity();

}
Пример #27
0
void ParticleSystem::reset(float radius)
{
	vec4f *pos = m_pos->map();
	for (size_t i = 0; i < m_size; i++) {
		vec3f generated_vec3 = vec3f(sfrand(), sfrand(), sfrand());
		generated_vec3 = normalize(generated_vec3) * radius;
		pos[i] = vec4f(generated_vec3, 1.0);
	}
	m_pos->unmap();
	

	vec4f *vel = m_vel->map();
	for (size_t i = 0; i < m_size; i++) {		
		float max_velocity = 0.02f;
		vel[i] = vec4f(sfrand()*max_velocity, sfrand()*max_velocity, sfrand()*max_velocity, 0.0f);
	}
	m_vel->unmap();
}
Пример #28
0
BaseEntity::BaseEntity_Impl::BaseEntity_Impl()
{
    _components = std::vector<BaseComponent*>();
    _should_destroy = false;
    _position = vec3f(0.0f, 0.0f, 0.0f);
    _direction = vec4f(0.0f, 0.0f, -1.0f, 0.0f);
    _scale = vec3f(1.0f, 1.0f, 1.0f);
    _id = GetNextId();
}
Пример #29
0
void AELightingCache::BuildRelativeArray(AEObject *obj)
{
	arr_length=0;
	arr_type.clear();
	arr_position.clear();
	arr_rotation.clear();
	arr_color.clear();
	arr_attenuation.clear();
	arr_spot.clear();

	size_t max=lights.size();
	for(size_t q=0;q<max;q++)
	{
		AEObjectLight *light=lights[q];
		arr_type.push_back(light->light_type);
		// AEVector3f pos=light->translate;
		// if(obj)
		// {
		// 	pos.X-=obj->translate.X;
		// 	pos.Y-=obj->translate.Y;
		// 	pos.Z-=obj->translate.Z;
		// }
		AEVector4f ppos = vec4f(light->translate,1.0f);
		if(obj)
		{
			ppos = obj->GetCameraMatrix()*ppos;
		}
		arr_position.push_back(vec3f(ppos.X,ppos.Y,ppos.Z));
		arr_color.push_back(light->color);
		arr_attenuation.push_back(light->attenuation);
		arr_spot.push_back(light->spot);

		//Multiplicate object's world matrix on vector {0,-1,0,0} to get normalised light vector
		AEVector4f rot4;
		rot4=lights[q]->GetWorldMatrix()*vec4f(0,-1,0,0);
		if(obj)
			rot4=obj->GetCameraMatrix()*rot4;

		arr_rotation.push_back(vec3f(rot4.X,rot4.Y,rot4.Z));

		arr_length++;
	}
}
Пример #30
0
    vec4f Material::getParam(const char *name, vec4f defaultVal) 
    {
      ParamMap::iterator it = params.find(name);
      if (it != params.end()) {
        assert( it->second->type == Param::FLOAT_4 && "Param type mismatch" );
        return vec4f( it->second->f[0], it->second->f[1], it->second->f[2], it->second->f[3] );
      }

      return defaultVal;
    }