本文整理汇总了C++中glm类的典型用法代码示例。如果您正苦于以下问题:C++ glm类的具体用法?C++ glm怎么用?C++ glm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了glm类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: vec4
void SceneOit::drawScene() {
prog.setUniform("LightPosition", vec4(0,0,0,1) );
prog.setUniform("LightIntensity", vec3(0.9f) );
prog.setUniform("Kd", vec4(0.2f, 0.2f, 0.9f, 0.55f) );
float size = 0.45f;
for( int i = 0; i <= 6; i++ )
for( int j = 0; j <= 6; j++ )
for( int k = 0; k <= 6; k++ ) {
if( (i + j + k) % 2 == 0 ) {
model = glm::translate(mat4(1.0f), vec3(i-3, j-3, k-3));
model = glm::scale( model, vec3(size) );
setMatrices();
sphere->render();
}
}
prog.setUniform("Kd", vec4(0.9f, 0.2f, 0.2f, 0.4f) );
size = 2.0f;
float pos = 1.75f;
model = glm::translate(mat4(1.0f), vec3(-pos, -pos, pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
model = glm::translate(mat4(1.0f), vec3(-pos, -pos, -pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
model = glm::translate(mat4(1.0f), vec3(-pos, pos, pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
model = glm::translate(mat4(1.0f), vec3(-pos, pos, -pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
model = glm::translate(mat4(1.0f), vec3(pos, pos, pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
model = glm::translate(mat4(1.0f), vec3(pos, pos, -pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
model = glm::translate(mat4(1.0f), vec3(pos, -pos, pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
model = glm::translate(mat4(1.0f), vec3(pos, -pos, -pos) );
model = glm::scale( model, vec3(size) );
setMatrices();
cube->render();
}
开发者ID:Ssapo,项目名称:TestOpengl,代码行数:53,代码来源:sceneoit.cpp
示例2: vec3
void MovableObject::scale(float x, float y, float z)
{
m_worldTransform = glm::scale(m_worldTransform, vec3(x, y, z));
}
开发者ID:NotCamelCase,项目名称:JBIC,代码行数:4,代码来源:MovableObject.cpp
示例3: cameraPos
using namespace std;
using glm::vec3;
using glm::mat3;
// ----------------------------------------------------------------------------
// GLOBAL VARIABLES
const int SCREEN_WIDTH = 500;
const int SCREEN_HEIGHT = 500;
SDL_Surface* screen;
int t;
vector<Triangle> triangles;
float focalLength = SCREEN_WIDTH/2;
vec3 cameraPos(0, 0, -2);
mat3 R(vec3(1,0,0),vec3(0,1,0),vec3(0,0,1));
float yaw = 0;
float dyaw = M_PI / 10;
vec3 rightDir(R[0][0], R[0][1], R[0][2]);
vec3 downDir(R[1][0], R[1][1], R[1][2]);
vec3 forwardDir(R[2][0], R[2][1], R[2][2]);
vec3 lightPos(0, -0.5, -0.7);
vec3 lightColor = 14.f * vec3(1, 1, 1);
vec3 indirectLight = 0.5f*vec3(1, 1, 1);
struct Intersection
{
vec3 position;
float distance;
int triangleIndex;
};
开发者ID:Martin36,项目名称:DH2323-Computer-Graphics,代码行数:30,代码来源:Source.cpp
示例4: makeCube
Neumont::ShapeData makeCube()
{
using glm::vec2;
using glm::vec3;
using glm::vec4;
Neumont::Vertex stackVerts[] =
{
// Top
vec3(-1.0f, +1.0f, +1.0f), // 0
vec4(1,0,0,0), //Tangent
vec3(+0.0f, +1.0f, +0.0f), // Normal
vec2(+0.0f, +1.0f), // UV
vec3(+1.0f, +1.0f, +1.0f), // 1
vec4(1,0,0,0), //Tangent
vec3(+0.0f, +1.0f, +0.0f), // Normal
vec2(+1.0f, +1.0f), // UV
vec3(+1.0f, +1.0f, -1.0f), // 2
vec4(1,0,0,0), //Tangent
vec3(+0.0f, +1.0f, +0.0f), // Normal
vec2(+1.0f, +0.0f), // UV
vec3(-1.0f, +1.0f, -1.0f), // 3
vec4(1,0,0,0), //Tangent
vec3(+0.0f, +1.0f, +0.0f), // Normal
vec2(+0.0f, +0.0f), // UV
// Front
vec3(-1.0f, +1.0f, -1.0f), // 4
vec4(+1,0,0,0), //Tangent
vec3(+0.0f, +0.0f, -1.0f), // Normal
vec2(+0.0f, +1.0f), // UV
vec3(+1.0f, +1.0f, -1.0f), // 5
vec4(+1,0,0,0), //Tangent
vec3(+0.0f, +0.0f, -1.0f), // Normal
vec2(+1.0f, +1.0f), // UV
vec3(+1.0f, -1.0f, -1.0f), // 6
vec4(+1,0,0,0), //Tangent
vec3(+0.0f, +0.0f, -1.0f), // Normal
vec2(+1.0f, +0.0f), // UV
vec3(-1.0f, -1.0f, -1.0f), // 7
vec4(+1,0,0,0), //Tangent
vec3(+0.0f, +0.0f, -1.0f), // Normal
vec2(+0.0f, +0.0f), // UV
// Right
vec3(+1.0f, +1.0f, -1.0f), // 8
vec4(0,0,-1,0), //Tangent
vec3(+1.0f, +0.0f, +0.0f), // Normal
vec2(+1.0f, +0.0f), // UV
vec3(+1.0f, +1.0f, +1.0f), // 9
vec4(0,0,-1,0), //Tangent
vec3(+1.0f, +0.0f, +0.0f), // Normal
vec2(+0.0f, +0.0f), // UV
vec3(+1.0f, -1.0f, +1.0f), // 10
vec4(0,0,-1,0), //Tangent
vec3(+1.0f, +0.0f, +0.0f), // Normal
vec2(+0.0f, +1.0f), // UV
vec3(+1.0f, -1.0f, -1.0f), // 11
vec4(0,0,-1,0), //Tangent
vec3(+1.0f, +0.0f, +0.0f), // Normal
vec2(+1.0f, +1.0f), // UV
// Left
vec3(-1.0f, +1.0f, +1.0f), // 12
vec4(0,0,1,0), //Tangent
vec3(-1.0f, +0.0f, +0.0f), // Normal
vec2(+1.0f, +0.0f), // UV
vec3(-1.0f, +1.0f, -1.0f), // 13
vec4(0,0,1,0), //Tangent
vec3(-1.0f, +0.0f, +0.0f), // Normal
vec2(+0.0f, +0.0f), // UV
vec3(-1.0f, -1.0f, -1.0f), // 14
vec4(0,0,1,0), //Tangent
vec3(-1.0f, +0.0f, +0.0f), // Normal
vec2(+0.0f, +1.0f), // UV
vec3(-1.0f, -1.0f, +1.0f), // 15
vec4(0,0,1,0), //Tangent
vec3(-1.0f, +0.0f, +0.0f), // Normal
vec2(+1.0f, +1.0f), // UV
// Back
vec3(+1.0f, +1.0f, +1.0f), // 16
vec4(1,0,0,0), //Tangent
vec3(+0.0f, +0.0f, +1.0f), // Normal
vec2(+1.0f, +0.0f), // UV
vec3(-1.0f, +1.0f, +1.0f), // 17
vec4(1,0,0,0), //Tangent
vec3(+0.0f, +0.0f, +1.0f), // Normal
//.........这里部分代码省略.........
开发者ID:tiliff,项目名称:Projectgit,代码行数:101,代码来源:MyGLWindow.cpp
示例5: TEST_CASE
#include "../src/scene/primitives/triangle.hpp"
using glm::vec3;
TEST_CASE( "Triangle intersection with rays", "[Triangle]" ) {
vec3 a(-1, -1, 1);
vec3 b(1, -1, 1);
vec3 c(1, 1, 1);
Triangle tri(a, b, c);
std::unique_ptr<Hit> hit;
float t = std::numeric_limits<float>::infinity();
SECTION( "Intersects when the ray cross over the triangle" ) {
Ray ray(vec3(0.5, -0.5, 0), vec3(0, 0, 1));
vec3 expecthit = vec3(0.5, -0.5, 1);
//auto intersect = tri.intersect(ray, hit, t);
//REQUIRE(intersect == true);
//CHECK(hit->position().x == expecthit.x);
//CHECK(hit->position().y == expecthit.y);
//CHECK(hit->position().z == expecthit.z);
//CHECK(t == glm::distance(hit->position(), ray.origin()));
}
SECTION( "Intersects when the ray cross over a line of the triangle" ) {
Ray ray(vec3(0, 0, 0), vec3(0, 0, 1));
vec3 expecthit = vec3(0, 0, 1);
//auto intersect = tri.intersect(ray, hit, t);
开发者ID:LesleyLai,项目名称:RayTracer,代码行数:30,代码来源:triangletest.cpp
示例6: setModelI
/* set the model transform to the identity */
void setModelI() {
phong->setModelMatrix(mat4(1.0f));
}
开发者ID:Milez213,项目名称:CityTrial,代码行数:4,代码来源:main.cpp
示例7:
}
// ===== end Export Objects =====
// lighting stuff
int g_flat = 1;
int g_material = 1;
LightInfo g_lightInfo;
GLuint g_showNormals;
PhongShader *phong;
PhongMaterial g_materials[NUM_MATERIALS] = {
{vec3(0.2, 0.2, 0.2), // amb
vec3(0.7, 0.4, 0.4), // diff
vec3(1, 1, 1), // spec
20.0}, // shine
{vec3(0.0, 0.0, 0.0),
vec3(H2_3f(0xfff852)),
vec3(1, 1, 1),
10.0},
{vec3(0.5, 0.1, 0.1),
vec3(0.6, 0.1, 0.1),
vec3(0.1, 0.1, 0.7),
20.0},
{vec3(0, 1, 1), // for drawing light
开发者ID:Milez213,项目名称:CityTrial,代码行数:30,代码来源:main.cpp
示例8: loadMap
bool loadMap(const char* filename, list<ExportObject> &map) {
FILE * file = fopen(filename, "r");
if (NULL == file) {
fprintf(stderr, "Couldn't open %s for reading the map\n", filename);
return false;
}
int num_objs = 0;
fscanf(file, "%d ", &num_objs);
list<ExportObject>::iterator it;
ExportObject reconstructedObject;
char name[100];
int matnum;
mat4 rotmat;
while (num_objs--) {
fscanf(file, "%s %d\n", name, &matnum);
read3f(reconstructedObject.t, file);
printf("read t:\n");
fprint3f(reconstructedObject.t, stdout);
read3f(reconstructedObject.s, file);
printf("read s:\n");
fprint3f(reconstructedObject.s, stdout);
read3f(reconstructedObject.r, file);
printf("read r:\n");
fprint3f(reconstructedObject.r, stdout);
reconstructedObject.materialIndex = matnum;
reconstructedObject.name = name;
reconstructedObject.xt = scale(mat4(1.0), reconstructedObject.s) *
translate(mat4(1.0), reconstructedObject.t);
map.push_back(reconstructedObject);
}
/* with mats
while (num_objs--) {
fscanf(file, "%s %d\n", name, &matnum);
readMat4(reconstructedObject.xt, file);
printf("read mat4\n");
printMat4(reconstructedObject.xt, stdout);
reconstructedObject.materialIndex = matnum;
reconstructedObject.name = name;
map.push_back(reconstructedObject);
}
*/
fclose(file);
return true;
}
开发者ID:Milez213,项目名称:CityTrial,代码行数:63,代码来源:main.cpp
示例9: Update
void Update()
{
// Compute frame time:
int t2 = SDL_GetTicks();
float dt = float(t2 - t);
t = t2;
cout << "Render time: " << dt << " ms." << endl;
Uint8* keystate = SDL_GetKeyState(0);
if (keystate[SDLK_w]){
lightPos += forwardDir;
}
if (keystate[SDLK_s]){
lightPos -= forwardDir;
}
if (keystate[SDLK_a]){
lightPos -= rightDir;
}
if (keystate[SDLK_d]){
lightPos += rightDir;
}
if (keystate[SDLK_q]){
lightPos -= downDir;
}
if (keystate[SDLK_e]){
lightPos += downDir;
}
if (keystate[SDLK_UP])
{
// Move camera forward
cameraPos += forwardDir;
}
if (keystate[SDLK_DOWN])
{
// Move camera backward
cameraPos -= forwardDir;
}
if (keystate[SDLK_LEFT])
{
/* // Move camera to the left
cameraPos.x--;
*/
// Rotate camera anti-clockwise around y-axis
yaw += dyaw;
cout << yaw;
vec3 col1(cosf(yaw), 0, -sinf(yaw));
vec3 col3(sinf(yaw), 0, cosf(yaw));
R = mat3(col1, vec3(0, 1, 0), col3);
vec3 rightDir(R[0][0], R[0][1], R[0][2]);
vec3 downDir(R[1][0], R[1][1], R[1][2]);
vec3 forwardDir(R[2][0], R[2][1], R[2][2]);
}
if (keystate[SDLK_RIGHT])
{
/*
// Move camera to the right
cameraPos.x++;
*/
// Rotate camera clockwise around y-axis
yaw -= dyaw;
vec3 col1(cosf(yaw), 0, -sinf(yaw));
vec3 col3(sinf(yaw), 0, cosf(yaw));
R = mat3(col1, vec3(0, 1, 0), col3);
vec3 rightDir(R[0][0], R[0][1], R[0][2]);
vec3 downDir(R[1][0], R[1][1], R[1][2]);
vec3 forwardDir(R[2][0], R[2][1], R[2][2]);
}
}
开发者ID:Martin36,项目名称:DH2323-Computer-Graphics,代码行数:70,代码来源:Source.cpp
示例10: sign
void ScreenGameplay7K::DrawBarlines()
{
for (auto i: MeasureBarlines)
{
float realV = (CurrentVertical - i) * SpeedMultiplier + Noteskin::GetBarlineOffset() * sign(SpeedMultiplier) + JudgmentLinePos;
if (realV > 0 && realV < ScreenWidth)
{
Barline->SetLocation (Vec2(Noteskin::GetBarlineStartX(), realV), Vec2(Noteskin::GetBarlineStartX() + Noteskin::GetBarlineWidth(), realV));
Barline->Render();
}
}
}
开发者ID:Sp3ct3r2k11,项目名称:raindrop,代码行数:12,代码来源:Renderer7K.cpp
注:本文中的glm类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论