本文整理汇总了C++中Vec3d::magnitude方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec3d::magnitude方法的具体用法?C++ Vec3d::magnitude怎么用?C++ Vec3d::magnitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec3d
的用法示例。
在下文中一共展示了Vec3d::magnitude方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Lines::update()
{
//Skip update if count hasn't changed
//To force update, set geometry->reload = true
if (reload) elements = 0;
if (elements > 0 && (linetotal == (unsigned int)elements || total == 0)) return;
tris->clear();
tris->setView(view);
//Count 2d lines
linetotal = 0;
for (unsigned int i=0; i<geom.size(); i++)
{ //Force true as default here, global default is false for "flat"
if (all2d || (geom[i]->draw->properties.getBool("flat", true) && !geom[i]->draw->properties["tubes"]))
linetotal += geom[i]->count;
}
//Copy data to Vertex Buffer Object
// VBO - copy normals/colours/positions to buffer object
unsigned char *p, *ptr;
ptr = p = NULL;
int datasize = sizeof(float) * 3 + sizeof(Colour); //Vertex(3), and 32-bit colour
int bsize = linetotal * datasize;
if (linetotal > 0)
{
//Initialise vertex buffer
if (!vbo) glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
if (glIsBuffer(vbo))
{
glBufferData(GL_ARRAY_BUFFER, bsize, NULL, GL_STATIC_DRAW);
debug_print(" %d byte VBO created for LINES, holds %d vertices\n", bsize, bsize/datasize);
ptr = p = (unsigned char*)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
GL_Error_Check;
}
if (!p) abort_program("VBO setup failed");
}
clock_t t1,t2,tt;
tt=clock();
counts.clear();
counts.resize(geom.size());
any3d = false;
for (unsigned int i=0; i<geom.size(); i++)
{
t1=tt=clock();
Properties& props = geom[i]->draw->properties;
//Calibrate colour maps on range for this object
geom[i]->colourCalibrate();
float limit = props["limit"];
bool linked = props["link"];
if (all2d || (props.getBool("flat", true) && !props["tubes"]))
{
int hasColours = geom[i]->colourCount();
int colrange = hasColours ? geom[i]->count / hasColours : 1;
if (colrange < 1) colrange = 1;
debug_print("Using 1 colour per %d vertices (%d : %d)\n", colrange, geom[i]->count, hasColours);
Colour colour;
for (unsigned int v=0; v < geom[i]->count; v++)
{
if (!internal && geom[i]->filter(i)) continue;
//Check length limit if applied (used for periodic boundary conditions)
//NOTE: will not work with linked lines, require separated segments
if (!linked && v%2 == 0 && v < geom[i]->count-1 && limit > 0.f)
{
Vec3d line;
vectorSubtract(line, geom[i]->vertices[v+1], geom[i]->vertices[v]);
if (line.magnitude() > limit)
{
//Skip next two vertices
v++;
continue;
}
}
//Have colour values but not enough for per-vertex, spread over range (eg: per segment)
int cidx = v / colrange;
if (cidx >= hasColours) cidx = hasColours - 1;
geom[i]->getColour(colour, cidx);
//if (cidx%100 ==0) printf("COLOUR %d => %d,%d,%d\n", cidx, colour.r, colour.g, colour.b);
//Write vertex data to vbo
assert((int)(ptr-p) < bsize);
//Copies vertex bytes
memcpy(ptr, &geom[i]->vertices[v][0], sizeof(float) * 3);
ptr += sizeof(float) * 3;
//Copies colour bytes
memcpy(ptr, &colour, sizeof(Colour));
ptr += sizeof(Colour);
//Count of vertices actually plotted
counts[i]++;
}
t2 = clock();
debug_print(" %.4lf seconds to reload %d vertices\n", (t2-t1)/(double)CLOCKS_PER_SEC, counts[i]);
t1 = clock();
//.........这里部分代码省略.........