当前位置: 首页>>代码示例>>C++>>正文


C++ glm::vec4方法代码示例

本文整理汇总了C++中glm::vec4方法的典型用法代码示例。如果您正苦于以下问题:C++ glm::vec4方法的具体用法?C++ glm::vec4怎么用?C++ glm::vec4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在glm的用法示例。


在下文中一共展示了glm::vec4方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

bool ComputerGraphics::update(float deltaTime) {

    // close the application if the window closes
    if (glfwWindowShouldClose(m_window) ||
        glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
        return false;

    // update the camera's movement
    m_camera->update(deltaTime);
	elapsedTime += deltaTime;

	//emitter.position += vec3(glm::sin(elapsedTime), 0, 0);

	emitter.Update(deltaTime, m_camera->getTransform());
    // clear the gizmos out for this frame
    Gizmos::clear();
	terrain.Update(deltaTime);

    Gizmos::addTransform(glm::mat4(1));

    // ...for now let's add a grid to the gizmos
    for (int i = 0; i < 21; ++i) {
        Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10),
            i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));

        Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i),
            i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));
    }

    // return true, else the application closes
    return true;
}
开发者ID:nathanwblair,项目名称:computer_graphics,代码行数:32,代码来源:ComputerGraphics.cpp

示例2: drawBox

void easygl::drawBox(GLdouble width, GLdouble height, GLdouble depth)
{
	const GLfloat vertices[8][3] = {
		{1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {-1.0, -1.0, 1.0}, {-1.0, 1.0, 1.0},
		{1.0, 1.0, -1.0}, {1.0, -1.0, -1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0} };
	const GLfloat normals[6][3] = {
		{0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0},
		{0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}};
	const short faces[6][4] = {
		{3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7} };

	glEnable(GL_LIGHTING);

	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, value_ptr(vec4(0.5f, 0.5f, 1.0f, 1.0f)));
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, value_ptr(vec4(0.0f, 0.0f, 0.0f, 1.0f)));
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 2.0f);

    glPushMatrix();
    glTranslatef(0, height/2, 0);
    glScalef(width/2, height/2, depth/2);
    glBegin(GL_QUADS);
    for(int f = 0; f < 6; f++)
	{
		glNormal3fv(normals[f]);
        for(int i = 0; i < 4; i++)
            glVertex3fv(vertices[faces[f][i]]);
	}
    glEnd ();
    glPopMatrix();

    glDisable(GL_LIGHTING);
}
开发者ID:rene-dev,项目名称:knuthcam,代码行数:32,代码来源:easygl.cpp

示例3: ScreenNode

vector< vector<vertexInfo>> ScreenNode(const vector< vector<vertexInfo>> &node)
{//compute node in screen space

    setMatrix();
    vector< vector<vertexInfo>> node_screen = node;
    for(int i = 0; i < (int)node.size(); i++)
    {
        for(int j = 0 ; j <(int)node[i].size(); j++)
        {
            vec4 v_pers = ::MVP * vec4(node[i][j].x, node[i][j].y, node[i][j].z, 1.0);
            vec4 v_screen = ::m_screen * vec4(v_pers/v_pers[3]);

            node_screen[i][j].x = v_screen.x;
            node_screen[i][j].y = v_screen.y;
            node_screen[i][j].z = v_screen.z;
        }
    }
//    for(int i = 0; i< (int)node_screen.size(); i++)
//    {
//
//        for(int j = 0; j< (int)node_screen[i].size(); j++)
//        {
//            cout<<i*(int)node_screen.size() + j<<'\t';
//            cout<<node_screen[i][j].x<<'\t'<<'\t';
//            cout<<node_screen[i][j].y<<'\t'<<'\t';
//            cout<<node_screen[i][j].z<<endl;
//        }
//    }
    return node_screen;
}
开发者ID:jlyharia,项目名称:Interactive-Deformable-Object,代码行数:30,代码来源:main.cpp

示例4: update

bool UtilitySystems::update(float deltaTime) {
	
	// close the application if the window closes
	if (glfwWindowShouldClose(m_window) ||
		glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
		return false;

	// update the camera's movement
	m_camera->update(deltaTime);

    m_pNPC->update(deltaTime);


	// clear the gizmos out for this frame
	Gizmos::clear();

	Gizmos::addTransform(glm::mat4(1));

	// ...for now let's add a grid to the gizmos
	for (int i = 0; i < 21; ++i) {
		Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10),
			i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));

		Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i),
			i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));
	}

	// return true, else the application closes
	return true;
}
开发者ID:johnsietsma,项目名称:AIE_OpenGLTutorials,代码行数:30,代码来源:UtilitySystems.cpp

示例5: Draw

void BasicNetworkingApp::Draw()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	Gizmos::Clear();

	Gizmos::AddTransform(glm::translate(m_pickPosition));

	for (int i = 0; i < 21; ++i)
	{
		Gizmos::AddLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));

		Gizmos::AddLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));
	}

	for (unsigned int i = 0; i < m_gameObjects.size(); i++)
	{
		GameObject& obj = m_gameObjects[i];
		Gizmos::AddSphere(vec3(obj.xPos, 2, obj.zPos), 2, 32, 32, vec4(obj.redColour, obj.greenColour, obj.blueColour, 1), nullptr);
	}

	Gizmos::Draw(m_camera->GetProjectionView());

	int width = 0;
	int height = 0;
	glfwGetWindowSize(m_window, &width, &height);
	glm::mat4 guiMatrix = glm::ortho<float>(0, (float)width, 0, (float)height);

	Gizmos::Draw2D(guiMatrix);
}
开发者ID:PorygonSeizure,项目名称:Complex-Game-Systems,代码行数:30,代码来源:BasicNetworkingApp.cpp

示例6: get_camera_matrix

mat4 GLFrame::get_camera_matrix(bool rotation_only)
{
	vec3 x, z;
	mat4 mat(1);

	// Make rotation matrix
	// Z vector is reversed due to pespective projection matrix
	z = -forward;

	x = glm::cross(up, z);

	// Matrix has no translation information and is
	// transposed.... (rows instead of columns)
	mat[0] = vec4(x.x, up.x, z.x, 0);
	mat[1] = vec4(x.y, up.y, z.y, 0);
	mat[2] = vec4(x.z, up.z, z.z, 0);
	//mat[3] already set
	

	if (rotation_only)
		return mat;

	// Apply translation too
	mat4 trans(1);
	trans[3] = vec4(-origin, 1);

	//TODO
	//could instead of having the previous 2 lines just mat*(-origin) and drop the result
	//in column 4 of mat.  I think that actually saves mult ops

	return mat*trans;
}
开发者ID:rswinkle,项目名称:opengl_reference,代码行数:32,代码来源:glm_glframe.cpp

示例7: Draw

void CheckersProject::Draw(FlyCamera &_gameCamera, float a_deltatime)
{
	using glm::vec3;
	using glm::vec4;

	//BROWN UNDERBOARD
	Gizmos::addCylinderFilled(vec3(5.25, -1, 5.25), 10, 0.75, 4, vec4(0.545, 0.270, 0.074, 1), &rotate);

	///Draw the Grid
	for (float c = 0; c <= m_cols- 1; c++)
	{
		for (float r = 0; r <= m_rows - 1; r++)
		{	
			if (m_tileRed == false)
			{
				Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0, c * m_scaleMod), 1, 0.25, 4, vec4(0, 0, 0, 1), &rotate);
				m_tileRed = true;
			}
			else if (m_tileRed == true)
			{
				Gizmos::addCylinderFilled(vec3(r * m_scaleMod,0, c *m_scaleMod), 1, 0.25, 4, vec4(1, 0, 0, 1), &rotate);
				m_tileRed = false;
			}
			
		}
		m_tileRed = !m_tileRed;
	}


	///Draw Tokens  

	for (int c = 0; c <= m_cols - 1; c++)
	{
		for (int r = 0; r <= m_rows - 1; r++)
		{
			if (m_board[c][r] == PIECE::RED)
			{
				Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.5, 0.25, 16, vec4(1,0 , 0, 1), &rotate);
			}
			else if (m_board[c][r] == PIECE::REDKING)
			{
				Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.75, 0.55, 16, vec4(1, 0, 0, 1), &rotate);
			}
			else if (m_board[c][r] == PIECE::BLACK)
			{
				Gizmos::addCylinderFilled(vec3((r * m_scaleMod),0.5, c * m_scaleMod), 0.5, 0.25, 16, vec4(0 ,0, 0, 1), &rotate);
			}
			else if (m_board[c][r] == PIECE::BLACKKING)
			{
				Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.75, 0.55, 16, vec4(0, 0, 0, 1), &rotate);
			}
			else if (m_board[c][r] == PIECE::POSSIBLEMOVE)
			{
				Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.5, 0.25, 16, vec4(0, 1, 0, 1), &rotate);
			}
		}
	}

}
开发者ID:Boopy321,项目名称:Take2Checkers,代码行数:59,代码来源:CheckersProject.cpp

示例8: iniObjStack

void RayTracer::iniObjStack()
{//initialize object
    //sphere ID = 1
    //(x-a)^2 + (y-b)^2 + (z-c)^2 = r^2
    //vec4(a, b, c, r)
    addObjectStack(vec4(3.0, 1.0, 1.0, 0.7), 1);//reflect object
    addObjectStack(vec4(0.0, 1.0, 0.0, 1.0), 1);//opaque object
    addObjectStack(vec4(0.5, 0.5, 2.5, 0.5), 1);//transparent object
    //plane ID = 2
    //ax + by + cz + d =0
    //vec4(a, b, c, d)
    addObjectStack(vec4(0.0, 1.0, 0.0, 0.0), 2);//opaque object
    addObjectStack(vec4(1.0, 0.0, 0.3, 1.0), 2);//reflect object
}
开发者ID:jlyharia,项目名称:Graphic_Platform,代码行数:14,代码来源:RayTracer.cpp

示例9: transform

void Geometry::transform(mat4 const &m)
{
    mat4 it = glm::transpose(glm::inverse(m));

    //  Check.. Did I forget something?
    //  \todo Mark each attributemap how they should be transformed

    auto polygon_centroids = polygon_attributes().maybe_find<vec3>("polygon_centroids");
    auto polygon_normals   = polygon_attributes().maybe_find<vec3>("polygon_normals");
    auto point_locations   = point_attributes().maybe_find<vec3>("point_locations");
    auto point_normals     = point_attributes().maybe_find<vec3>("point_normals");
    auto corner_normals    = corner_attributes().maybe_find<vec3>("corner_normals");

    for (auto point : points())
    {
        if (point_locations != nullptr && point_locations->has(point))
        {
            point_locations->put(point, vec3(m * vec4(point_locations->get(point), 1.0f)));
        }

        if (point_normals != nullptr && point_normals->has(point))
        {
            point_normals->put(point, vec3(it * vec4(point_normals->get(point), 0.0f)));
        }
    }

    for (auto polygon : polygons())
    {
        if (polygon_centroids != nullptr && polygon_centroids->has(polygon))
        {
            polygon_centroids->put(polygon, vec3(m * vec4(polygon_centroids->get(polygon), 1.0f)));
        }

        if (polygon_normals != nullptr && polygon_normals->has(polygon))
        {
            polygon_normals->put(polygon, vec3(it * vec4(polygon_normals->get(polygon), 0.0f)));
        }

        if (corner_normals != nullptr)
        {
            for (auto corner : polygon->corners())
            {
                if (corner_normals != nullptr && corner_normals->has(corner))
                {
                    corner_normals->put(corner, vec3(it * vec4(corner_normals->get(corner), 0.0f)));
                }
            }
        }
    }
}
开发者ID:tksuoran,项目名称:RenderStack,代码行数:50,代码来源:geometry.cpp

示例10: CalculateRayFromPixel

void Picking::CalculateRayFromPixel( const glm::ivec2& pixel, const glm::ivec2& windowSize, const glm::mat4& invViewProj, Ray* outRay ) const
{
	// Clip space coordinates for the pixel. (-1,-1) in lower left corner, (-1,1) upper left corner, (1,-1) lower right corner. 
	const vec2	mousePosNorm	= vec2( -1.0f + 2.0f * (pixel.x / static_cast<float>(windowSize.x)),
											1.0f - 2.0f * (pixel.y / static_cast<float>(windowSize.y)) );

	// Translating pixel at near plane and far plane to world coordinates. Z-coordinate is depth into the screen (values between -1 and 1 are in view of camera).
	const vec4 nearHomogeneous	= invViewProj * vec4( mousePosNorm.x, mousePosNorm.y, 0.0f, 1.0f );
	const vec4 farHomogeneous	= invViewProj * vec4( mousePosNorm.x, mousePosNorm.y, 1.0f, 1.0f );
	const vec3 nearWorld		= vec3( nearHomogeneous ) / nearHomogeneous.w;
	const vec3 farWorld			= vec3( farHomogeneous ) / farHomogeneous.w;

	outRay->Position			= nearWorld;
	outRay->Direction			= glm::normalize( farWorld - nearWorld );
}
开发者ID:Robograde,项目名称:Robograde,代码行数:15,代码来源:Picking.cpp

示例11: updateMatrices

void OrthoCamera::updateMatrices()
{
	vec3 s = glm::normalize(glm::cross(direction, upVector));
	vec3 u = glm::normalize(glm::cross(s, direction));

	mat4 untranslatedViewMatrix = mat4(vec4(s, 0), vec4(u, 0), vec4(direction, 0), vec4(0, 0, 0, 1.0f));
	untranslatedViewMatrix = glm::transpose(untranslatedViewMatrix);

	viewMatrix = glm::translate(untranslatedViewMatrix, -focus);

	projectionMatrix = mat4(1/width,	0,			0,			0,
							0,			1/height,	0,			0, 
							0,			0,			1/depth,	0,
							0,			0,			0,			1);
}
开发者ID:SimonWallner,项目名称:kocmoc-core,代码行数:15,代码来源:OrthoCamera.cpp

示例12: vertex

vec3 phong_tangent_space_shader::vertex(
        const mat4& viewmat,
        const vec3& v) const
{
    auto res = viewmat * vec4(v, 1);
    return res / res.w;
}
开发者ID:scottnm,项目名称:tinyrenderer,代码行数:7,代码来源:shaders.cpp

示例13: render

void ControlLayer::render(ESContext *esContext) {
    storeState();

    // do real render
    prog.setUniform("CircleColor", vec4(0.0f, 0.0f, 0.0f, 0.2f));
    leftPanel->panel->render(GL_TRIANGLE_FAN);
    rightPanel->panel->render(GL_TRIANGLE_FAN);

    prog.setUniform("CircleColor", vec4(0.0f, 0.0f, 1.0f, 0.8f));
    if(leftPanel->isActive == TRUE) {
        leftPanel->hitPoint->render(GL_TRIANGLE_FAN);
    }
    if(rightPanel->isActive == TRUE) {
        rightPanel->hitPoint->render(GL_TRIANGLE_FAN);
    }

    recoverState();
}
开发者ID:qige023,项目名称:Glorex,代码行数:18,代码来源:controllayer.cpp

示例14: draw

void Blank::draw() {

    // clear the screen for this frame
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    // ...for now let's add a grid to the gizmos
    for (int i = 0; i < 21; ++i) {
        Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10),
            i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));

        Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i),
            i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1));
    }


    // display the 3D gizmos
    Gizmos::draw(m_camera->getProjectionView());
}
开发者ID:johnsietsma,项目名称:AIE_OpenGLTutorials,代码行数:19,代码来源:Blank.cpp

示例15: resizeGL

void My_OpenGLWidget::resizeGL(int width, int height) {
	glViewport(0, 0, width, height);
	float aspectRatio = static_cast<float>(width) / static_cast<float>(height);
	//top, bottom, near, and far are still ok, aspect ratio is the problem

	float bottom = -1.0f;
	float nearZ = 2.0f;
	float top = nearZ * tan(3.14/8.0f);
	float farZ = -1.0f;
	float right = aspectRatio;
	float left = -aspectRatio;	//near and far had namespace collisions

	//mat4 projectionScale = mat4(vec4(2.0f / (right - left), 0.0f, 0.0f, 0.0f), vec4(0.0f, 2.0f / (top - bottom), 0.0f, 0.0f), vec4(0.0f, 0.0f, 2.0f / (farZ - nearZ), 0.0f), vec4(0.0f, 0.0f, 0.0f, 1.0f));

	mat4 projectionScale = mat4(vec4((nearZ/right), 0, 0, 0), vec4(0, (nearZ/top), 0,0), vec4(0,0,((-farZ+nearZ)/(farZ-nearZ)),((-2*farZ*nearZ)/(farZ-nearZ))), vec4(0,0,-1, 0));

	//mat4 projectionTranslate = glm::translate(vec3(0.0f, 0.0f, 1.0f));
	//projectionMatrix = projectionScale * projectionTranslate;
	projectionMatrix = projectionScale;
}
开发者ID:stuartsoft,项目名称:GraphicsMilestones,代码行数:20,代码来源:my_openglwidget.cpp


注:本文中的glm::vec4方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。