void UpdateRiversTask::getTilesToUpdate(TerrainInfo &terrain, ptr<TerrainQuad> q) { if (q->visible == SceneManager::INVISIBLE) { return; } if (q->isLeaf() == false) { getTilesToUpdate(terrain, q->children[0]); getTilesToUpdate(terrain, q->children[1]); getTilesToUpdate(terrain, q->children[2]); getTilesToUpdate(terrain, q->children[3]); return; } vec3i v = vec3i(q->level, q->tx, q->ty); vec3f f = vec3f(q->ox, q->oy, q->l); terrain.displayedTiles.push_back(make_pair(v, f)); }
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(); }
/* draw * * Draw the model. Don't forget to apply the transformations necessary * for position, orientation, and scale. */ void objecthdl::draw(canvashdl *canvas) { canvas->translate(position); canvas->rotate(orientation[0], vec3f(1.0, 0.0, 0.0)); canvas->rotate(orientation[1], vec3f(0.0, 1.0, 0.0)); canvas->rotate(orientation[2], vec3f(0.0, 0.0, 1.0)); canvas->scale(vec3f(scale, scale, scale)); for (int i = 0; i < rigid.size(); i++) { canvas->uniform["material"] = material[rigid[i].material]; rigid[i].draw(canvas); } canvas->scale(vec3f(1.0/scale, 1.0/scale, 1.0/scale)); canvas->rotate(-orientation[2], vec3f(0.0, 0.0, 1.0)); canvas->rotate(-orientation[1], vec3f(0.0, 1.0, 0.0)); canvas->rotate(-orientation[0], vec3f(1.0, 0.0, 0.0)); canvas->translate(-position); }
void Renderer::commit() { autoEpsilon = getParam1i("autoEpsilon", true); epsilon = getParam1f("epsilon", 1e-6f); spp = std::max(1, getParam1i("spp", 1)); const int32 maxDepth = getParam1i("maxDepth", 20); const float minContribution = getParam1f("minContribution", 0.001f); errorThreshold = getParam1f("varianceThreshold", 0.f); maxDepthTexture = (Texture2D*)getParamObject("maxDepthTexture", nullptr); model = (Model*)getParamObject("model", getParamObject("world")); if (maxDepthTexture) { if (maxDepthTexture->type != OSP_TEXTURE_R32F || !(maxDepthTexture->flags & OSP_TEXTURE_FILTER_NEAREST)) { static WarnOnce warning("maxDepthTexture provided to the renderer " "needs to be of type OSP_TEXTURE_R32F and have " "the OSP_TEXTURE_FILTER_NEAREST flag"); } } vec3f bgColor3 = getParam3f("bgColor", vec3f(getParam1f("bgColor", 0.f))); bgColor = getParam4f("bgColor", vec4f(bgColor3, 0.f)); if (getIE()) { ManagedObject* camera = getParamObject("camera"); if (model) { const float diameter = model->bounds.empty() ? 1.0f : length(model->bounds.size()); epsilon *= diameter; } ispc::Renderer_set(getIE() , model ? model->getIE() : nullptr , camera ? camera->getIE() : nullptr , autoEpsilon , epsilon , spp , maxDepth , minContribution , (ispc::vec4f&)bgColor , maxDepthTexture ? maxDepthTexture->getIE() : nullptr ); } }
bool ForestOrthoLayer::doCreateTile(int level, int tx, int ty, TileStorage::Slot *data) { if (Logger::DEBUG_LOGGER != NULL) { ostringstream oss; oss << "OrthoForest tile " << getProducerId() << " " << level << " " << tx << " " << ty; Logger::DEBUG_LOGGER->log("ORTHO", oss.str()); } if (level >= displayLevel) { ptr<FrameBuffer> fb = SceneManager::getCurrentFrameBuffer(); TileCache::Tile * t = graphProducer->findTile(level, tx, ty); assert(t != NULL); ObjectTileStorage::ObjectSlot *graphData = dynamic_cast<ObjectTileStorage::ObjectSlot*>(t->getData()); GraphPtr g = graphData->data.cast<Graph>(); if (g != NULL) { vec3d q = getTileCoords(level, tx, ty); float scale = 2.0f * (1.0f - getTileBorder() * 2.0f / getTileSize()) / q.z; vec3d tileOffset = vec3d(q.x + q.z / 2.0f, q.y + q.z / 2.0f, scale); //offsetU->set(vec3f(q.x + q.z / 2.0f, q.y + q.z / 2.0f, scale)); offsetU->set(vec3f(0.0, 0.0, 1.0)); colorU->set(vec4f(color.x, color.y, color.z, color.w)); mesh->setMode(TRIANGLES); mesh->clear(); ptr<Graph::AreaIterator> ai = g->getAreas(); while (ai->hasNext()) { AreaPtr a = ai->next(); tess->beginPolygon(mesh); drawArea(tileOffset, a, *tess); tess->endPolygon(); } fb->draw(layerProgram, *mesh); } else { if (Logger::DEBUG_LOGGER != NULL) { ostringstream oss; oss << "NULL Graph : " << level << " " << tx << " " << ty; Logger::DEBUG_LOGGER->log("GRAPH", oss.str()); } } } return true; }
PositionSlider::PositionSlider(float percent) { this->percent = percent; font = fontmanager.grab("FreeSans.ttf", 16); font.dropShadow(true); int gap = display.width / 30; bounds.update(vec2f(gap, display.height - gap*2)); bounds.update(vec2f(display.width - gap, display.height - gap)); slidercol = vec3f(1.0, 1.0, 1.0); mouseover = -1.0; mouseover_elapsed = 1.0; fade_time = 1.0; alpha = 0.0; }
void ZoomCamera::logic(float dt) { vec3f dp = (dest - pos); vec3f dpt = dp * dt * speed; if(lockon) { dpt = dpt * lockon_time + dp * (1.0-lockon_time); if(lockon_time>0.0) { lockon_time = std::max(0.0f, lockon_time-dt*0.5f); } } if(dpt.length2() > dp.length2()) dpt = dp; pos += dpt; target = vec3f(pos.x, pos.y, 0.0); }
void polyline_road::xml_read(xmlpp::TextReader &reader, const vec3f &scale) { assert(is_opening_element(reader, "line_rep")); read_to_open(reader, "points"); std::cout<<"abcd"<<std::endl; do { read_skip_comment(reader); if(reader.get_node_type() == xmlpp::TextReader::Text || reader.get_node_type() == xmlpp::TextReader::SignificantWhitespace) { //std::cout<<"BE CAREFUL, NEED TEST! (hwm_xml_read.cpp)"<<std::endl; std::string res(reader.get_value()); std::stringstream s1(res); std::string line; while(getline(s1, line, '\n')) { std::istringstream s2(line); vec3f pos; s2 >> pos[0]; s2 >> pos[1]; s2 >> pos[2]; if((std::abs(pos[0] - 0) < 1e-6 && std::abs(pos[1] - 0) < 1e-6 && std::abs(pos[2] - 0) < 1e-6)) continue; points_.push_back(vec3f(pos*scale)); } } } while(!is_closing_element(reader, "points")); if(!initialize()) throw xml_error(reader, "Failed to initialize polyine"); read_to_close(reader, "line_rep"); }
//---------------------------------------------------------------------- void ReverbArea::loadReverbAreasFromXMLFile( const std::string& filePath, const std::string& file ) { std::string fullFilePath = filePath + file; XMLParser parser( fullFilePath.c_str() ); XMLDocument& doc = parser.getDocument(); XMLNode* root = doc.FirstChildElement( "ReverbAreas" ); XMLNode* reverbAreaElement = nullptr; for( reverbAreaElement = root->FirstChildElement( "ReverbArea" ); reverbAreaElement != nullptr; reverbAreaElement = reverbAreaElement->NextSiblingElement( "ReverbArea" ) ) { parser.validateXMLAttributes( reverbAreaElement, "name,pos,minDist,maxDist", "preset" ); std::string raName = parser.getXMLAttributeAsString( reverbAreaElement, "name", "" ); vec3f pos = parser.getXMLAttributeAsVec3( reverbAreaElement, "pos", vec3f() ); float minDist = parser.getXMLAttributeAsFloat( reverbAreaElement, "minDist", 0.0f ); float maxDist = parser.getXMLAttributeAsFloat( reverbAreaElement, "maxDist", 0.1f ); std::string preset = parser.getXMLAttributeAsString( reverbAreaElement, "preset", "MONKY_PRESET_OFF" ); ReverbArea* ra = ReverbArea::createOrGetReverbArea( raName, getMonkyReverbPresetFromString( preset ) ); ra->set3DAttributes( pos, minDist, maxDist ); } }
vec3f DirectionalLight::shadowAttenuation( const vec3f& P ) const { vec3f d = getDirection(P); // loop to get the attenuation vec3f curP = P; isect isecP; vec3f ret = getColor(P); ray r = ray(curP, d); while (scene->intersect(r, isecP)) { //if not transparent return black if (isecP.getMaterial().kt.iszero()) return vec3f(0, 0, 0); //use current intersection point as new light source curP = r.at(isecP.t); r = ray(curP, d); ret = prod(ret, isecP.getMaterial().kt); } return ret; }
GLLightScreen::GLLightScreen():lightPos(0, 0, 0) { glClearColor(0, 0, 0, 1); P.frustum(-0.01, 0.01, -0.006, 0.006, 0.01, 1000); GLShaderPtr vertShader = new GLShader("D:/GitHub/GPEngine/GPGame/Shaders/GLSL/pointlight.vert", ShaderType::VERTEX_SHADER); GLShaderPtr fragShader = new GLShader("D:/GitHub/GPEngine/GPGame/Shaders/GLSL/pointlight.frag", ShaderType::FRAG_SHADER); program.attachShader(vertShader); program.attachShader(fragShader); program.link(); posHandle = glGetAttribLocation(program, "vPos"); normalHandle = glGetAttribLocation(program, "vNormal"); lightPosHandle = glGetUniformLocation(program, "vLightPos"); mvpHandle = glGetUniformLocation(program, "vMVP"); mHandle = glGetUniformLocation(program, "vMV"); shininessHandle = glGetUniformLocation(program, "shininess"); createCube(vec3f(0, 0, -25), 10); }
int main () { printf ("Results of utility_quat_to_matrix_test:\n"); quatf q = to_quat (degree (90.0f), vec3f (0, 0, 1)); dump ("q", q); dump ("to_matrix (q)", to_matrix (q)); mat3f m1; mat4f m2; to_matrix (q, m1); to_matrix (q, m2); dump ("to_matrix (q, m1)", m1); dump ("to_matrix (q, m2)", m2); return 0; }
void PlanarRectangle::InitBary( const Rectangle & rect, const vec3f & integrationPoint ) { // copy src points here std::memcpy( &p0, &rect.p0, 4 * sizeof( vec3f ) ); const vec3f bary = ( p0 + p1 + p2 + p3 ) * 0.25f; vec3f org = Normalize( bary - integrationPoint ); const f32 rayLenSqr = Dot( org, org ); const f32 rayLen = std::sqrt( rayLenSqr ); const vec3f nrm = org / rayLen; // org is bary in relative coordinates const Plane P{ org, nrm }; // project each point on the plane P vec3f *verts = &p0; for ( int i = 0; i < 4; ++i ) { vec3f rayDir = Normalize( verts[i] - integrationPoint ); // with 0 as origin since the vertices are in relative coordinates already verts[i] = P.RayIntersection( vec3f( 0 ), rayDir ); } const vec3f d0 = p1 - p0; const vec3f d1 = p3 - p0; const vec3f d2 = p2 - p3; const vec3f d3 = p2 - p1; w = Len( d0 ); h = Len( d1 ); ex = d0 / w; ey = d1 / h; ez = nrm; // normal pointing away from origin area = 0.5f * ( w * h + Len( d2 ) * Len( d3 ) ); }
void Logger::recordSignatureColorPostDraw(MyD3DAssets &assets, const DrawParameters ¶ms, const GPUDrawBuffers &buffers) { if (!capturingColorSignature) { return; } assets.context->readRenderTarget(postRenderImage); vec3f diffSum = vec3f::origin; int diffCount = 0; for (auto &p : postRenderImage) { if (p.value != preRenderImage(p.x, p.y)) { diffSum += vec3f(p.value.getVec3()) / 255.0f; diffCount++; } } newSignaturesThisFrame++; colorMap.record(params.signature, diffCount == 0 ? vec3f::origin : diffSum / (float)diffCount, diffCount); if (!geoDatabase.hasSignature(params.signature)) { LocalizedObject object; object.load(assets, params, buffers, true); object.center(); if (object.data.signature != params.signature) logErrorFile << "inconsistent signatures" << endl; Bitmap diffImage = postRenderImage; for (auto &p : diffImage) { if (p.value == preRenderImage(p.x, p.y)) { p.value = vec4uc(0, 0, 0, 255); } } geoDatabase.record(object, diffImage); } }
vec3f HuetoRGB(float h) { float r, g, b; h /= ( 2.0 * M_PI * (1.0 / 6.0) ); while(h >= 6.0f) h -= 6.0f; int i = floor( h ); float f = h - i; float q = 1 - 1 * f; float t = 1 - 1 * ( 1 - f ); switch( i ) { case 0: r = 1; g = t; b = 0; break; case 1: r = q; g = 1; b = 0; break; case 2: r = 0; g = 1; b = t; break; case 3: r = 0; g = q; b = 1; break; case 4: r = t; g = 0; b = 1; break; case 5: default: r = 1; g = 0; b = q; break; } return vec3f(r,g,b); }
vec3f PointLight::_shadowAttenuation(const vec3f& P, const ray& r) const { double distance = (position - P).length(); vec3f d = r.getDirection(); vec3f result = getColor(P); vec3f curP = r.getPosition(); isect isecP; ray newr(curP, d); while (scene->intersect(newr, isecP)) { //prevent going beyond this light if ((distance -= isecP.t) < RAY_EPSILON) return result; //if not transparent return black if (isecP.getMaterial().kt.iszero()) return vec3f(0, 0, 0); //use current intersection point as new light source curP = r.at(isecP.t); newr = ray(curP, d); result = prod(result, isecP.getMaterial().kt); } return result; }
void CComponent_PlayerCollision::Shutdown(void) { m_bPrevInGoo = false; m_bInGoo = false; m_pSoundComponent = nullptr; m_fInitiateWallSlideTimer = 0.0f; _isWallSliding = false; m_pAnimationComponent = nullptr; _CollidingWallRight = false; _CollidingWallLeft = false; m_WallJumpPushOutVector = vec3f(0.0f, 0.0f, 0.0f); m_InputMng = nullptr; m_pPlayerCollisionVolume = nullptr; m_pHealthComponent = nullptr; m_pInputComp = nullptr; this->CleanRemoveVelocity(); CParticleManager::GetInstance()->DestroyEffect( m_pWallSlideEffect ); }
void StackGraph::drawTransition(float dt) { Bounds2D moving_bounds; moving_bounds.min = selected_bounds.min * in_transition + section_bounds.min * (1.0 - in_transition); moving_bounds.max = selected_bounds.max * in_transition + section_bounds.max * (1.0 - in_transition); vec3f moving_colour = vec3f(1.0, 1.0, 1.0); vec3f moving_colour2 = moving_colour * 0.3; glBegin(GL_QUADS); glColor3fv(moving_colour); glVertex2f(moving_bounds.min.x, moving_bounds.min.y); glVertex2f(moving_bounds.max.x, moving_bounds.min.y); glColor3fv(moving_colour2); glVertex2f(moving_bounds.max.x, moving_bounds.max.y); glVertex2f(moving_bounds.min.x, moving_bounds.max.y); glEnd(); }
void nailConstraintNode::computeWorldMatrix(const MPlug& plug, MDataBlock& data) { // std::cout << "nailConstraintNode::computeWorldMatrix" << std::endl; MObject thisObject(thisMObject()); MFnDagNode fnDagNode(thisObject); MObject update; MPlug(thisObject, ca_constraint).getValue(update); MPlug(thisObject, ca_constraintParam).getValue(update); MStatus status; MFnTransform fnParentTransform(fnDagNode.parent(0, &status)); MVector mtranslation = fnParentTransform.getTranslation(MSpace::kTransform, &status); // MQuaternion mrotation; // fnParentTransform.getRotation(mrotation, MSpace::kTransform); if(m_constraint) { vec3f world; m_constraint->get_world(world); if(world[0] != float(mtranslation.x) || world[1] != float(mtranslation.y) || world[2] != float(mtranslation.z)) { /* mat4x4f xform; m_constraint->rigid_body()->get_transform(xform); vec4f pivot = prod(trans(xform), vec4f(mtranslation.x, mtranslation.y, mtranslation.z, 1.0)); std::cout << "pivot (" << pivot[0] << "," << pivot[0] << "," << pivot[0] << ")" << std::endl; */ // std::cout << "mtranslation (" << mtranslation[0] << "," << mtranslation[0] << "," << mtranslation[0] << ")" << std::endl; m_constraint->set_world(vec3f((float) mtranslation[0], (float) mtranslation[1], (float) mtranslation[2])); } } data.setClean(plug); }
void init(TRIANGLE * t, int n) { for(int i = 0; i < n; ++i) { vec3f v1(t[i].p[0].x,t[i].p[0].y,t[i].p[0].z); vec3f v2(t[i].p[1].x,t[i].p[1].y,t[i].p[1].z); vec3f v3(t[i].p[2].x,t[i].p[2].y,t[i].p[2].z); Tri tri; tri.i = insertPoint(v1); tri.j = insertPoint(v2); tri.k = insertPoint(v3); tri.norm = vec3f(t[i].norm.x,t[i].norm.y, t[i].norm.z); tris.push_back(tri); } std::cout << "Inserted " << vecs.size() << " unique points from " << n*3 << "original points\n"; calcNormals(); }
void teleport(int n, game::dynent *d) { // also used by monsters #if 0 // TODO int e = -1, tag = ents[n].attr1, beenhere = -1; for (;;) { e = world::findentity(TELEDEST, e+1); if (e==beenhere || e<0) { con::out("no teleport destination for tag %d", tag); return; } if (beenhere<0) beenhere = e; if (ents[e].attr2==tag) { d->o = vec3f(ents[e].x, ents[e].y, ents[e].z); d->vel = zero; d->ypr.x = ents[e].attr1; d->ypr.y = 0.f; entinmap(d); sound::playc(sound::TELEPORT); break; } } #endif }
void ParticleUpsampling::draw(void) { GLuint prevFBO = 0; // Enum has MANY names based on extension/version // but they all map to 0x8CA6 glGetIntegerv(0x8CA6, (GLint*)&prevFBO); CHECK_GL_ERROR(); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); matrix4f rotationMatrix, translationMatrix; nv::rotationY(rotationMatrix, m_transformer->getRotationVec().y); nv::translation(translationMatrix, 0.f, 0.f, -5.f); translationMatrix.set_scale(vec3f(-1.0, 1.0, -1.0)); m_sceneRenderer->setEyeViewMatrix(translationMatrix * rotationMatrix); m_sceneRenderer->renderFrame(); glBindFramebuffer(GL_FRAMEBUFFER, prevFBO); glViewport(0, 0, m_width, m_height); }
frame3f shape_sample_uniform(Shape* shape, const vec2f& uv) { if(is<Sphere>(shape)) { auto sphere = cast<Sphere>(shape); // see: http://mathworld.wolfram.com/SpherePointPicking.html float z = 1 - 2*uv.y; float rxy = sqrt(1-z*z); float phi = 2*pif*uv.x; vec3f pl = vec3f(rxy*cos(phi),rxy*sin(phi),z); frame3f f; f.o = sphere->center + pl * sphere->radius; f.z = normalize(pl); f = orthonormalize(f); return f; } else if(is<Quad>(shape)) { auto quad = cast<Quad>(shape); frame3f f = identity_frame3f; f.o = (uv.x-0.5f)*quad->width*x3f + (uv.y-0.5f)*quad->height*y3f; return f; } else { not_implemented_error(); return identity_frame3f; } }
float snoise3d_tricerp_file(vector3f p) { #define _data(vx, vy, vz) snoise3d_data[((vx) % snoise_size.x) + ((vy) % snoise_size.y)*snoise_size.x + ((vz) % snoise_size.z)*snoise_size.x*snoise_size.y] int int_px = (int) p.x; int int_py = (int) p.y; int int_pz = (int) p.z; float v000 = _data( int_px, int_py, int_pz ); float v100 = _data( int_px + 1, int_py, int_pz ); float v101 = _data( int_px + 1, int_py, int_pz + 1 ); float v001 = _data( int_px, int_py, int_pz + 1 ); float v010 = _data( int_px, int_py + 1, int_pz ); float v110 = _data( int_px + 1, int_py + 1, int_pz ); float v111 = _data( int_px + 1, int_py + 1, int_pz + 1 ); float v011 = _data( int_px, int_py + 1, int_pz + 1 ); vector3f t = vec3f( p.x-int_px, p.y-int_py, p.z-int_pz); return tricerp(v000, v100, v101, v001, v010, v110, v111, v011, t); }
/* draw_bound * * Create a representation for the bounding box and * render it. */ void objecthdl::draw_bound(canvashdl *canvas) { canvas->translate(position); canvas->rotate(orientation[0], vec3f(1.0, 0.0, 0.0)); canvas->rotate(orientation[1], vec3f(0.0, 1.0, 0.0)); canvas->rotate(orientation[2], vec3f(0.0, 0.0, 1.0)); canvas->scale(vec3f(scale, scale, scale)); vector<vec8f> bound_geometry; vector<int> bound_indices; bound_geometry.reserve(8); bound_geometry.push_back(vec8f(bound[0], bound[2], bound[4], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_geometry.push_back(vec8f(bound[1], bound[2], bound[4], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_geometry.push_back(vec8f(bound[1], bound[3], bound[4], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_geometry.push_back(vec8f(bound[0], bound[3], bound[4], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_geometry.push_back(vec8f(bound[0], bound[2], bound[5], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_geometry.push_back(vec8f(bound[1], bound[2], bound[5], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_geometry.push_back(vec8f(bound[1], bound[3], bound[5], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_geometry.push_back(vec8f(bound[0], bound[3], bound[5], 0.0, 0.0, 0.0, 0.0, 0.0)); bound_indices.reserve(24); for (int i = 0; i < 4; i++) { bound_indices.push_back(i); bound_indices.push_back((i+1)%4); bound_indices.push_back(4+i); bound_indices.push_back(4+(i+1)%4); bound_indices.push_back(i); bound_indices.push_back(4+i); } canvas->uniform["material"] = NULL; canvas->draw_lines(bound_geometry, bound_indices); canvas->scale(vec3f(1.0/scale, 1.0/scale, 1.0/scale)); canvas->rotate(-orientation[2], vec3f(0.0, 0.0, 1.0)); canvas->rotate(-orientation[1], vec3f(0.0, 1.0, 0.0)); canvas->rotate(-orientation[0], vec3f(1.0, 0.0, 0.0)); canvas->translate(-position); }
void snoise3d_init_file(const char *filename, vector3ui snoise3d_size) { IF_FAILED(filename); FILE *file = NULL; snoise_size = snoise3d_size; // существует файл с шумом ?... if((file = fopen(filename, "rb")) == NULL) { // ...файла нет, значит нужно создать ERROR_MSG("cannot open file %s with noise; creating it\n", filename); snoise3d_data = (float*) malloc(sizeof(float) * snoise_size.x*snoise_size.y*snoise_size.z); file = fopen(filename, "w"); for(unsigned k = 0; k < snoise_size.z; k++) { for(unsigned j = 0; j < snoise_size.y; j++) { for(unsigned i = 0; i < snoise_size.x; i++) { snoise3d_data[i + j*snoise_size.x + k*snoise_size.x*snoise_size.y] = simplex_noise_3d(vec3f(i, j ,k)); } } } fwrite((void*) snoise3d_data, sizeof(float), snoise_size.x*snoise_size.y*snoise_size.z, file); fclose(file); } else { unsigned size = snoise3d_size.x*snoise3d_size.y*snoise3d_size.z; // ...файл есть, читаем данные snoise3d_data = (float*) malloc(sizeof(float) * size); unsigned read_bytes = fread((void*) snoise3d_data, sizeof(float), size, file); if(read_bytes*sizeof(float) != size*sizeof(float)) { ERROR_MSG("cannot read 3d noise data; file = %s\n", filename); } fclose(file); } }
RFile::RFile(const std::string & name, const vec3f & colour, const vec2f & pos, int tagid) : Pawn(name,pos,tagid) { hidden = true; size = gGourceFileDiameter; radius = size * 0.5; setGraphic(gGourceSettings.file_graphic); speed = 5.0; nametime = 4.0; name_interval = nametime; namecol = vec3f(1.0, 1.0, 1.0); file_colour = colour; last_action = 0.0; expiring=false; removing=false; shadow = true; distance = 0; this->fullpath = name; this->name = name; path_hash = 0; setPath(); namelist = glGenLists(1); font = 0; setSelected(false); dir = 0; if(path.size()) path_hash = stringHash(path); }
dynent *newdynent() { dynent *d = (dynent*) MALLOC(sizeof(dynent)); d->o = zero; d->ypr = vec3f(270.f,0.f,0.f); d->maxspeed = 22.f; d->outsidemap = false; d->inwater = false; d->radius = 0.5f; d->o.y = d->eyeheight = 1.8f; d->aboveeye = 0.2f; d->frags = 0; d->plag = 0; d->ping = 0; d->lastupdate = int(lastmillis()); d->enemy = NULL; d->monsterstate = 0; d->name[0] = d->team[0] = 0; d->blocked = false; d->lifesequence = 0; d->state = CS_ALIVE; spawnstate(d); return d; }
int main () { printf ("Results of node_transform_scale_test:\n"); Node::Pointer node (Node::Create ()); printf ("set scale vec3f result: "); node->SetScale (vec3f (14.4f, 17.1f, -6.66f)); dump_scale (*node); printf ("\n"); printf ("set scale (sx, sy, sz) result: "); node->SetScale (0.f, 27.14f, 6.12f); dump_scale (*node); printf ("\n"); printf ("reset scale result: "); node->ResetScale (); dump_scale (*node); printf ("\n"); return 0; }
MSMap::MSMap( const vec2f& mapOffsetFromPlayerPos, float floorTileX, float floorTileY, float mapWidth, float mapHeight, const std::string& floorTileMaterial ) : m_mapSize( mapWidth, floorTileY ) , m_screenSize( mapWidth, mapHeight ) , m_lastLayerSpawnedOn( 0 ) , m_rateToDecreaseSpawnRate( 0.5f ) , m_currentSpawnRate( MAX_SPAWN_RATE ) , m_spawnTimer( MAX_SPAWN_RATE ) , m_verticalOffsetBetweenLayers( 50.0f ) , m_playerSpawn( vec2f( mapWidth * 0.5f, mapHeight * 0.5f ) - vec2f(0.0f, 50.0f ) ) , m_mapOffsetFromPlayerPos( mapOffsetFromPlayerPos ) { m_currentObstaclesOnMap.resize( STARTING_NUMBER_LAYERS ); GenerateMapMesh( floorTileX, floorTileY, mapWidth, floorTileMaterial ); m_mapYPos = ( m_screenSize.y - m_mapSize.y ) * 0.5f; for( int i = 0; i < NUM_PLATFORMS_TO_SPAWN; ++i ) { m_platformRenderLocations.push_back( vec3f( m_mapSize.x * i, m_mapYPos ) ); } }