Vec3d PerspectiveCamera::SampleAndEvaluate( const Vec2d& pixelSample, Ray& ray, double& pdf ) { // Raster position in [-1, 1]^2 auto ndcRasterPos = Vec3d(pixelSample * 2.0 - 1.0, 0.0); // Convert raster position to camera coordinates auto dirTCam4 = invProjectionMatrix * Vec4d(ndcRasterPos, 1.0); auto dirTCam3 = Math::Normalize(Vec3d(dirTCam4) / dirTCam4.w); ray.d = Math::Normalize(Vec3d(invViewMatrix * Vec4d(dirTCam3, 0.0))); ray.o = position; ray.minT = 0.0; ray.maxT = Inf; pdf = EvaluateImportance(-dirTCam3.z); assert(pdf != 0.0); // Returns // W_e(z_0\to z_1) / p_A(z_0) / p_\sigma(z_0\to z_1) // = 1 // where // W_e(z_0\to z_1) = p_\sigma(z_0\to z_1), // p_A(z_0) = 1 return Vec3d(1.0); }
bool Primitive::Intersect( Ray& ray, Intersection& isect ) { Ray localRay(ray); localRay.o = Vec3d(worldToLocal * Vec4d(ray.o, 1.0)); localRay.d = Vec3d(worldToLocal * Vec4d(ray.d, 0.0)); if (!shape->Intersect(localRay, isect)) { return false; } ray.minT = localRay.minT; ray.maxT = localRay.maxT; if (localToWorld != Mat4d(1.0)) { isect.p = Vec3d(localToWorld * Vec4d(isect.p, 1.0)); isect.sn = Math::Normalize(normalLocalToWorld * isect.sn); isect.gn = Math::Normalize(normalLocalToWorld * isect.gn); isect.ss = Math::Normalize(Vec3d(localToWorld * Vec4d(isect.ss, 0.0))); isect.st = Math::Normalize(Vec3d(localToWorld * Vec4d(isect.st, 0.0))); } return true; }
HINATA_NAMESPACE_BEGIN PerspectiveCamera::PerspectiveCamera( const Mat4d& viewMatrix, const Mat4d& projectionMatrix ) : viewMatrix(viewMatrix) , projectionMatrix(projectionMatrix) { invProjectionMatrix = Math::Inverse(projectionMatrix); invViewMatrix = Math::Inverse(viewMatrix); // Position of the camera (in world coordinates) position = Vec3d(invViewMatrix * Vec4d(Vec3d(), 1.0)); // Calculate area of the sensor used for SampleAndEvaluate auto ndcP1 = Vec3d(-1.0, -1.0, 0.0); auto ndcP2 = Vec3d(1.0, 1.0, 0.0); auto invProjectionMatrix = Math::Inverse(projectionMatrix); auto camP1_4 = invProjectionMatrix * Vec4d(ndcP1, 1.0); auto camP2_4 = invProjectionMatrix * Vec4d(ndcP2, 1.0); auto camP1 = Vec3d(camP1_4) / camP1_4.w; auto camP2 = Vec3d(camP2_4) / camP1_4.w; camP1 /= Vec3d(camP1.z); camP2 /= Vec3d(camP2.z); double A = (camP2.x - camP1.x) * (camP2.y - camP1.y); invA = 1.0 / A; }
bool GeometryUtils::project(const Mat4d& projectionMultViewMatrix, const Vec2i& viewportPosition, const Vec2ui& viewportSize, const Vec3d& point, Vec3d* out) { CVF_ASSERT(out); Vec4d v = projectionMultViewMatrix * Vec4d(point, 1.0); if (v.w() == 0.0f) { return false; } v.x() /= v.w(); v.y() /= v.w(); v.z() /= v.w(); // map to range 0-1 out->x() = v.x()*0.5 + 0.5; out->y() = v.y()*0.5 + 0.5; out->z() = v.z()*0.5 + 0.5; // map to viewport out->x() = out->x() * viewportSize.x() + viewportPosition.x(); out->y() = out->y() * viewportSize.y() + viewportPosition.y(); return true; }
Vec3d PerspectiveCamera::SampleAndEvaluate( const Vec3d& ref, Vec2d& rasterPos, double& pdf ) { // Reference point in camera coordinates auto refCam4 = viewMatrix * Vec4d(ref, 1.0); auto refCam3 = Vec3d(refCam4); // Reference point in NDC auto refNdc4 = projectionMatrix * refCam4; auto refNdc3 = Vec3d(refNdc4) / refNdc4.w; // Raster position in [0, 1]^2 rasterPos = (Vec2d(refNdc3.x, refNdc3.y) + 1.0) * 0.5; // Check visibility if (rasterPos.x < 0 || rasterPos.x > 1 || rasterPos.y < 0 || rasterPos.y > 1) { pdf = 0.0; return Vec3d(); } // Importance double We = EvaluateImportance(-Math::Normalize(refCam3).z); if (We == 0.0) { pdf = 0.0; return Vec3d(); } // Distance to the reference point to camera origin double dist2 = Math::Length2(refCam3); pdf = 1.0; return Vec3d(We / dist2); }
void WarSpace::drawOverlay(wardraw_t *wd){ Player *ppl = getPlayer(); for(int i = 0; i < 2; i++) for(WarField::EntityList::iterator it = (this->*list[i]).begin(); it != (this->*list[i]).end(); it++){ if(!*it) continue; Entity *pe = *it; double pixels; if(ppl && WarDraw::r_overlay && 0. < (pixels = wd->vw->gc->scale(pe->pos) * pe->getHitRadius()) && pixels * 20. < wd->vw->vp.m){ Vec4d spos = wd->vw->trans.vp(Vec4d(pe->pos, 1)); glPushMatrix(); glLoadIdentity(); glTranslated((spos[0] / spos[3] + 1.) * wd->vw->vp.w / 2., (1. - spos[1] / spos[3]) * wd->vw->vp.h / 2., 0.); glScaled(20, 20, 1); glColor4f(GLfloat(pe->race % 2), 1, GLfloat((pe->race + 1) % 2), GLfloat(1. - pixels * 20. / wd->vw->vp.m)); try{ pe->drawOverlay(wd); } catch(std::exception e){ fprintf(stderr, __FILE__"(%d) Exception in %p->%s::drawOverlay(): %s\n", __LINE__, pe, pe->idname(), e.what()); } catch(...){ fprintf(stderr, __FILE__"(%d) Exception in %p->%s::drawOverlay(): ?\n", __LINE__, pe, pe->idname()); } glPopMatrix(); } } }
void TransformNode::UpdateUpMatrix(Mat4d currTransform, Mat4d invHeadMatrix) { mParentTransform = currTransform; mLocalTransform = vl_I; for( int i = 0; i < mTransforms.size(); i++ ) mLocalTransform *= mTransforms[i]->GetTransform(); currTransform *= mLocalTransform; mCurrentTransform = currTransform; for(int i = 0; i < mHandles.size(); i++){ Vec3d tempVec3; tempVec3 = mHandles[i]->mOffset; Vec4d tempVec4 = Vec4d(tempVec3[0], tempVec3[1], tempVec3[2], 1); tempVec4 = currTransform * tempVec4; mHandles[i]->mGlobalPos = Vec3d(tempVec4[0], tempVec4[1], tempVec4[2]); } for(int i = 0; i < mChildren.size(); i++ ) mChildren[i]->UpdateUpMatrix(currTransform, invHeadMatrix); for(int i = 0; i < mPrimitive.size(); i++ ) mPrimitive[i]->UpdateUpMatrix(currTransform, invHeadMatrix); }
TileSet::TileSet(const std::string& filename) : Resource(filename) { p_texture = 0; reload(); badTile.position = Vec2i(-1, -1); badTile.type = -1; badTile.destroyTime = 0; badTile.debrisColor = Vec4d(0.0, 0.0, 0.0, 0.0); }
std::vector<Vec4d> SimpleDraw::RandomColors( int count ) { std::vector<Vec4d> colors; for (int i = 0; i < count; i++){ float r = ((rand() % 225) + 30) / 255.0f; float g = ((rand() % 230) + 25) / 255.0f; float b = ((rand() % 235) + 20) / 255.0f; colors.push_back(Vec4d(r, g, b, 1.0)); } return colors; }
/* Decompose 4x4 affine matrix A as TFRUK(U transpose), where t contains the * translation components, q contains the rotation R, u contains U, k contains * scale factors, and f contains the sign of the determinant. * Assumes A transforms column vectors in right-handed coordinates. * See Ken Shoemake and Tom Duff. Matrix Animation and Polar Decomposition. * Proceedings of Graphics Interface 1992. */ void decompAffine(_HMatrix A, _affineParts * parts) { _HMatrix Q, S, U; Quat p; //Translation component. parts->t = Vec4d(A[X][W], A[Y][W], A[Z][W], 0); double det = polarDecomp(A, Q, S); if (det<0.0) { matrixCopy(Q, =, -Q, 3); parts->f = -1; }
// use phong shading model Vec4d PhongMaterial::shade( const RayIntersection& intersection, const Light& light) const { // calculate diffuse part of the equation Vec3d lightDirection = (light.position() - intersection.position()).normalize(); Vec3d diffuse = this->color() * std::max(dot(intersection.normal(), lightDirection), 0.d); // calculate specular part Vec3d viewDirection = intersection.ray().direction(); Vec3d reflection = reflect(lightDirection, intersection.normal()); Vec3d lightcolor = light.spectralIntensity() / 255; Vec3d specular = ((mShininess + 2) / (2 * M_PI)) * SPECULAR_REFLECTION_DEGREE * pow(std::max(dot(reflection, viewDirection), 0.d), mShininess) * lightcolor; // calculcate sum -> result return Vec4d(diffuse + specular, 1); }
CCGame::CCGame() { gameNode = new Group(); map = new CCMap(); map->buildBuiltInWorld(); gameNode->addChild(map->getMapNode()); player = new ControlledCycle(); gameNode->addChild(player->getNode()); //lighting stuff ref_ptr<LightSource> ls = new LightSource(); ref_ptr<Light> ambientLight = new Light(); ambientLight->setAmbient(Vec4d(1.0,1.0,1.0,1.0)); ls->setLight(ambientLight); gameNode->addChild(ls); }
void Enemy::onCollect(Player* p_player) { if(p_player->isTeleporting()) return; if(subType == 0) { if(!eatCounter) { ParticleSystem* p_particleSystem = level.getParticleSystem(); ParticleSystem::Particle p; // die Metzelei hinter einer Staubwolke verstecken for(int i = 0; i < 150; i++) { p.lifetime = 100; p.damping = 0.99f; p.gravity = 0.005f; p.positionOnTexture = Vec2b(0, 0); p.sizeOnTexture = Vec2b(16, 16); p.position = position * 16 + Vec2i(random(4, 12), random(4, 12)); double a = random(0.0, 1000.0); p.velocity = Vec2d(sin(a), cos(a)) * random(0.05, 1.0); double c = random(0.6, 1.0); p.color = p_player->getDebrisColor(); p.color.a *= random(0.5f, 1.2f); p.deltaColor = Vec4d(0.0, 0.0, 0.0, -p.color.a / p.lifetime); p.rotation = random(0.0f, 10.0f); p.deltaRotation = random(-0.1f, 0.1f); p.size = random(0.3f, 0.5f); p.deltaSize = random(0.01f, 0.05f); p_particleSystem->addParticle(p); } Engine::inst().playSound("enemy1_eat.ogg", false, 0.1); p_player->disappear(1.5); p_player->censored = true; moveCounter = 130; eatCounter = 130; burpCounter = 100; slideDir = -1; } } else if(subType == 1) { if(!eatCounter) { ParticleSystem* p_particleSystem = level.getParticleSystem(); ParticleSystem::Particle p; // die Metzelei hinter einer Staubwolke verstecken for(int i = 0; i < 150; i++) { p.lifetime = 100; p.damping = 0.99f; p.gravity = 0.005f; p.positionOnTexture = Vec2b(0, 0); p.sizeOnTexture = Vec2b(16, 16); p.position = position * 16 + Vec2i(random(4, 12), random(4, 12)); double a = random(0.0, 1000.0); p.velocity = Vec2d(sin(a), cos(a)) * random(0.05, 1.0); double c = random(0.6, 1.0); p.color = p_player->getDebrisColor(); p.color.a *= random(0.5f, 1.2f); p.deltaColor = Vec4d(0.0, 0.0, 0.0, -p.color.a / p.lifetime); p.rotation = random(0.0f, 10.0f); p.deltaRotation = random(-0.1f, 0.1f); p.size = random(0.3f, 0.5f); p.deltaSize = random(0.01f, 0.05f); p_particleSystem->addParticle(p); } Engine::inst().playSound("enemy2_eat.ogg", false, 0.1); p_player->disappear(1.5); p_player->censored = true; moveCounter = 130; eatCounter = 130; burpCounter = 100; slideDir = -1; } } }
void Scarry::drawtra(wardraw_t *wd){ st::drawtra(wd); Scarry *p = this; Scarry *pt = this; Mat4d mat; Vec3d pa, pb, pa0(.01, 0, 0), pb0(-.01, 0, 0); double scale; /* if(scarry_cull(pt, wd)) return;*/ if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; scale = fabs(wd->vw->gc->scale(this->pos)); transform(mat); const double blastscale = .04; drawCapitalBlast(wd, Vec3d(0, 0, .55), blastscale); drawCapitalBlast(wd, Vec3d(.08, .08, .55), blastscale); drawCapitalBlast(wd, Vec3d(-.08, .08, .55), blastscale); drawCapitalBlast(wd, Vec3d(-.08, -.08, .55), blastscale); drawCapitalBlast(wd, Vec3d(.08, -.08, .55), blastscale); pa = pt->rot.trans(pa0); pa += pt->pos; pb = pt->rot.trans(pb0); pb += pt->pos; glColor4ub(255,255,9,255); glBegin(GL_LINES); glVertex3dv(pa); glVertex3dv(pb); glEnd(); { int i; static const avec3_t lights[] = { {0, 520 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {0, -520 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {-140 * SCARRY_SCALE, 370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {-140 * SCARRY_SCALE, -370 * SCARRY_SCALE, 220 * SCARRY_SCALE}, {100 * SCARRY_SCALE, -360 * SCARRY_SCALE, -600 * SCARRY_SCALE}, {100 * SCARRY_SCALE, 360 * SCARRY_SCALE, -600 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, 20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, -20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, 20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, -20 * SCARRY_SCALE, 520 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, 20 * SCARRY_SCALE, -300 * SCARRY_SCALE}, {-280 * SCARRY_SCALE, -20 * SCARRY_SCALE, -300 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, 20 * SCARRY_SCALE, -480 * SCARRY_SCALE}, { 280 * SCARRY_SCALE, -20 * SCARRY_SCALE, -480 * SCARRY_SCALE}, }; avec3_t pos; double rad = .01; double t; GLubyte col[4] = {255, 31, 31, 255}; random_sequence rs; init_rseq(&rs, (unsigned long)this); /* color calculation of static navlights */ t = fmod(wd->vw->viewtime + drseq(&rs) * 2., 2.); if(t < 1.){ rad *= (t + 1.) / 2.; col[3] *= t; } else{ rad *= (2. - t + 1.) / 2.; col[3] *= 2. - t; } for(i = 0 ; i < numof(lights); i++){ mat4vp3(pos, mat, lights[i]); gldSpriteGlow(pos, rad, col, wd->vw->irot); } /* runway lights */ if(1 < scale * .01){ col[0] = 0; col[1] = 191; col[2] = 255; for(i = 0 ; i <= 10; i++){ avec3_t pos0; pos0[0] = -160 * SCARRY_SCALE; pos0[1] = 20 * SCARRY_SCALE + .0025; pos0[2] = (i * -460 + (10 - i) * -960) * SCARRY_SCALE / 10; rad = .005 * (1. - fmod(i / 10. + t / 2., 1.)); col[3] = 255/*rad * 255 / .01*/; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = -40 * SCARRY_SCALE; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[1] = -20 * SCARRY_SCALE - .0025; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); pos0[0] = -160 * SCARRY_SCALE; mat4vp3(pos, mat, pos0); gldSpriteGlow(pos, rad, col, wd->vw->irot); } } /* for(i = 0; i < numof(p->turrets); i++) mturret_drawtra(&p->turrets[i], pt, wd);*/ } static int init = 0; static suftex_t *pst; static suf_t *sufbase = NULL; if(init == 0) do{ init = 1; sufbase = CallLoadSUF("models/spacecarrier.bin"); } while(0); if(sufbase){ static const double normal[3] = {0., 1., 0.}; double scale = SCARRY_SCALE; static const GLdouble rotaxis[16] = { -1,0,0,0, 0,1,0,0, 0,0,-1,0, 0,0,0,1, }; Mat4d mat; glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT); glEnable(GL_CULL_FACE); glPushMatrix(); transform(mat); glMultMatrixd(mat); extern GLuint screentex; glBindTexture(GL_TEXTURE_2D, screentex); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); glColor4f(1.,1.,1.,1.); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); Mat4d modelview, proj; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, proj); Mat4d trans = proj * modelview; texture((glPushMatrix(), glScaled(1./2., 1./2., 1.), glTranslated(1, 1, 0), glMultMatrixd(trans) )); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(.9,0,0,0)); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,.9,0,0)); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_R, GL_EYE_PLANE, Vec4d(0,0,.9,0)); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1)); glEnable(GL_TEXTURE_GEN_Q); glPushMatrix(); glScaled(-scale, scale, -scale); DrawSUF(sufbase, 0, NULL); glPopMatrix(); texture((glPopMatrix())); glPopMatrix(); glPopAttrib(); } }
void GUI_Button::onRender() { GUI& gui = GUI::inst(); int offset = 0; if(useSkin()) { if(style == 0) { // Button zeichnen gui.renderFrame(Vec2i(0, 0), size, pushed && mouseOver ? Vec2i(48, 96) : Vec2i(0, 96)); offset = -1; } else { Vec2i t = positionOnTexture; if(pushed && mouseOver) t = clickedPositionOnTexture; glPushMatrix(); glTranslated(size.x / 2, size.y / 2, 0.0); glScaled(currentScaling, currentScaling, 1.0); Engine::inst().renderSprite(p_image, -size / 2, t, size, currentColor); glPopMatrix(); } } else { // Hintergrund zeichnen glBegin(GL_QUADS); if(pushed && mouseOver) glColor4d(0.9, 0.9, 0.9, 1.0); else glColor4d(0.75, 0.75, 0.75, 1.0); glVertex2i(0, 0); glVertex2i(size.x, 0); if(pushed && mouseOver) glColor4d(0.8, 0.8, 0.8, 1.0); else glColor4d(0.65, 0.65, 0.65, 1.0); glVertex2i(size.x, size.y); glVertex2i(0, size.y); glEnd(); // Rahmen zeichnen glColor4d(0.0, 0.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); glVertex2i(0, 0); glVertex2i(size.x, 0); glVertex2i(size.x, size.y); glVertex2i(0, size.y); glEnd(); } // Titel schreiben Vec2i dim; std::string title = localizeString(this->title); p_font->measureText(title, &dim, 0); if(style == 0) { p_font->renderText(title, (size - dim) / 2 + Vec2i(0, offset), active ? Vec4d(1.0, 1.0, 1.0, 1.0) : Vec4d(0.5, 0.5, 0.5, 1.0)); if(p_image) { // Bild rendern Engine::inst().renderSprite(p_image, Vec2i(0, offset), positionOnTexture, size, Vec4d(1.0)); } } else { p_font->renderText(title, Vec2i((size.x - dim.x) / 2, size.y - 4), active ? currentColor : Vec4d(0.5, 0.5, 0.5, 1.0)); } }
void Enemy::onUpdate() { if(invisibility) invisibility--; Vec2i facing = intToDir(dir); if(level.getAIFlags(position) & 2) { // Vergiftung contamination--; } if(contamination <= 0) burst(); if(!thinkCounter--) { // den nächsten Spieler suchen, der für den Gegner sichtbar ist Player* p_closestPlayer = 0; int closestDist = 0; const std::list<Player*>& players = Player::getInstances(); for(std::list<Player*>::const_iterator i = players.begin(); i != players.end(); ++i) { if(!(*i)->isTeleporting()) { int dist = (position - (*i)->getPosition()).lengthSq(); if(dist < closestDist || !p_closestPlayer) { if(canSee((*i)->getPosition())) { p_closestPlayer = *i; closestDist = dist; } } } } if(p_closestPlayer) { targetPosition = p_closestPlayer->getPosition(); interest += 2225 - closestDist; } thinkCounter = random(2, 5); } if(subType == 0) { int oldDir = dir; if(moveCounter-- <= 0 && fabs(shownDir - dir) < 0.4) { int r = random(0, 8); if(interest >= 10000) r = random(0, 40); if(contamination < 50) { if(random() % 2) r = 0; } interest /= 2; switch(r) { case 0: { int d = random(-22, 22) / 10; if(d) dir += d, anim += 16; } break; case 1: case 2: case 3: if(!tryToMove(facing)) dir += random(-22, 22) / 10; anim += 16; break; default: if(r >= 6 && targetPosition.x != -1) { // zum Ziel laufen Vec2i toTarget = targetPosition - position; if(toTarget.x && toTarget.y) toTarget.value[random(0, 1)] = 0; int d = dirToInt(toTarget); toTarget = intToDir(d); if(tryToMove(toTarget)) { dir = d; anim += 16; interest *= 2; } } break; } if(position == targetPosition || interest < 10) { targetPosition = Vec2i(-1, -1); interest = 0; } while(dir < 0) dir += 4, shownDir += 4.0; dir %= 4; moveCounter = random(4, 7); } if(anim) anim--; double dd = static_cast<double>(dir) - shownDir; if(dd > 2.0) shownDir += 4.0; else if(dd < -2.0) shownDir -= 4.0; shownDir = 0.125 * dir + 0.875 * shownDir; if(!soundCounter) { if(oldDir != dir) { // Kratz-Sound abspielen Engine::inst().playSound("enemy1_turn.ogg", false, 0.1, -100); soundCounter = random(15, 55); } } else soundCounter--; if(burpCounter) { burpCounter--; if(!burpCounter) { int s = random(0, 1); std::string sound; if(s == 0) sound = "enemy1_burp1.ogg"; else if(s == 1) sound = "enemy1_burp2.ogg"; Engine::inst().playSound(sound, false, 0.1); // Rülpspartikel erzeugen ParticleSystem* p_particleSystem = level.getParticleSystem(); ParticleSystem::Particle p; for(int i = 0; i < 10; i++) { p.lifetime = random(50, 75); p.damping = 0.99f; p.gravity = random(-0.005f, -0.02f); p.positionOnTexture = Vec2b(96, 32); p.sizeOnTexture = Vec2b(16, 16); p.position = position * 16 + Vec2i(8 + random(-4, 4), 6); p.velocity = Vec2d(random(-0.5, 0.5), random(-1.0, -0.5)); p.color = Vec4d(random(0.8, 1.0), random(0.8, 1.0), random(0.8, 1.0), 0.25); p.deltaColor = Vec4d(0.0, 0.0, 0.0, -p.color.a / p.lifetime); p.rotation = random(-0.5f, 0.5f); p.deltaRotation = random(-0.05f, 0.05f); p.size = random(0.2f, 1.0f); p.deltaSize = random(0.0f, 0.01f); p_particleSystem->addParticle(p); } } } } else if(subType == 1) { if(random() % 2) anim++; if(moveCounter-- <= 0) { int r = random(0, 1); if(interest > 6000) r = random(0, 50); if(contamination < 50) { if(random() % 2) r = 0; } interest /= 2; switch(r) { case 0: tryToMove(intToDir(random(0, 4))); break; default: if(targetPosition.x != -1) { // zum Ziel laufen Vec2i toTarget = targetPosition - position; if(toTarget.x && toTarget.y) toTarget.value[random(0, 1)] = 0; int d = dirToInt(toTarget); toTarget = intToDir(d); if(tryToMove(toTarget)) interest *= 2; } else { // Wo ist die Spur am heißesten? int bestDir = 0; uint bestTrace = 0; for(int dir = 0; dir < 4; dir++) { uint trace = level.getAITrace(position + intToDir(dir)); if(trace > bestTrace) { bestTrace = trace; bestDir = dir; } } if(bestTrace) { Vec2i bestDirV = intToDir(bestDir); if(!tryToMove(bestDirV)) { // Das ging nicht. Ist da ein anderer Gegner? bool reduceTrace = true; Object* p_obj = level.getFrontObjectAt(position + bestDirV); if(p_obj) { // Wenn da ein anderer Gegner ist, ist es egal. if(p_obj->getType() == "Enemy") reduceTrace = false; } if(reduceTrace) { // Die Spur dort etwas uninteressanter machen! level.setAITrace(position + bestDirV, bestTrace / 2); } } else { if(bestTrace > 850) interest = 160000; else if(bestTrace > 100) interest = 20000; } } } break; } if(position == targetPosition || interest < 10) { targetPosition = Vec2i(-1, -1); interest = 0; } moveCounter = random(4, 7); } if(height == 0.0) { if(!(random() % 25)) { vy = random(40.0, 80.0); height = 0.5; } } else { height += 0.02 * vy; vy -= 0.02 * 400.0; if(height < 0.5) { height = 0.0; vy = 0.0; } } int pr = 700; if(interest >= 10000) pr = 350; if(!(random() % pr)) { // Lachen abspielen Engine::inst().playSound("enemy2_laugh.ogg", false, 0.15, -100); } if(interest >= 40000) { if(!(random() % 200)) { // Knurren abspielen Engine::inst().playSound("enemy2_growl.ogg", false, 0.15, -100); } } if(interest >= 10000) { // Feuer ParticleSystem* p_particleSystem = level.getParticleSystem(); ParticleSystem* p_fireParticleSystem = level.getFireParticleSystem(); ParticleSystem::Particle p; p.lifetime = random(40, 50); p.damping = 0.9f; p.gravity = -0.04f; p.positionOnTexture = Vec2b(32, 0); p.sizeOnTexture = Vec2b(16, 16); const double r = random(0.0, 6.283); const Vec2d vr(sin(r), cos(r)); p.position = position * 16 + Vec2d(7.5, 7.5 - height) + 7.5 * vr; p.velocity = vr; p.color = Vec4d(random(0.5, 1.0), random(0.8, 1.0), random(0.0, 0.25), random(0.2, 0.4)); const double dc = -1.5 / (p.lifetime + random(-25, 25)); p.deltaColor = Vec4d(dc, dc, dc, -p.color.a / p.lifetime); p.rotation = random(0.0f, 10.0f); p.deltaRotation = random(-0.1f, 0.1f); p.size = random(0.5f, 0.9f); p.deltaSize = random(0.0075f, 0.015f); if(random() % 2) p_particleSystem->addParticle(p); else p_fireParticleSystem->addParticle(p); } } if(eatCounter) eatCounter--; }
void Fire::onUpdate() { // Feuer ParticleSystem* p_particleSystem = level.getParticleSystem(); ParticleSystem* p_fireParticleSystem = level.getFireParticleSystem(); ParticleSystem::Particle p; p.lifetime = random(60, 100); p.damping = 0.9f; p.gravity = -0.04f; p.positionOnTexture = Vec2b(32, 0); p.sizeOnTexture = Vec2b(16, 16); p.position = position * 16 + Vec2i(random(6, 10), random(6, 10)); p.velocity = Vec2d(random(-0.5, 0.5), random(-0.5, 0.5)); p.color = Vec4d(random(0.5, 1.0), random(0.8, 1.0), random(0.0, 0.25), random(0.2, 0.4)); const double dc = -1.5 / (p.lifetime + random(-25, 25)); p.deltaColor = Vec4d(dc, dc, dc, -p.color.a / p.lifetime); p.rotation = random(0.0f, 10.0f); p.deltaRotation = random(-0.1f, 0.1f); p.size = random(0.5f, 0.9f); p.deltaSize = random(-0.015f, -0.0075f); if(random() % 2) p_particleSystem->addParticle(p); else p_fireParticleSystem->addParticle(p); // Befindet sich ein Objekt auf dem Feuer? const std::vector<Object*> objectsOnMe = level.getObjectsAt(position); for(std::vector<Object*>::const_iterator i = objectsOnMe.begin(); i != objectsOnMe.end(); ++i) { Object* p_obj = *i; if(p_obj == this) continue; p_obj->onFire(); if(p_obj->getFlags() & OF_DESTROYABLE) { p_obj->setDestroyTime(p_obj->getDestroyTime() - 1); if(!p_obj->getDestroyTime()) { p_obj->disappear(0.2); debrisColor = p_obj->getDebrisColor(); Engine::inst().playSound("vaporize.ogg", false, 0.15); // Trümmer int n = random(50, 80); for(int i = 0; i < n; i++) { p.lifetime = random(60, 120); p.damping = 0.9f; p.gravity = -0.1f; p.positionOnTexture = Vec2b(96, 0); p.sizeOnTexture = Vec2b(16, 16); p.position = p_obj->getPosition() * 16 + Vec2i(random(-2, 18), random(-2, 18)); p.velocity = Vec2d(random(-0.2, 0.2), random(-0.2, 0.2)); p.color = debrisColor + Vec4d(random(-0.1, 0.1), random(-0.1, 0.1), random(-0.1, 0.1), 0.0); p.deltaColor = Vec4d(0.0, 0.0, 0.0, -p.color.a / p.lifetime); p.rotation = random(0.0f, 10.0f); p.deltaRotation = random(-0.1f, 0.1f); p.size = random(0.5f, 1.5f); p.deltaSize = random(0.01f, 0.05f); if(random() % 2) p_particleSystem->addParticle(p); else p_fireParticleSystem->addParticle(p); } if(p_obj->getFlags() & OF_KILL_FIRE) { // Das Feuer geht jetzt aus! for(int i = 0; i < 50; i++) { p.lifetime = random(80, 150); p.damping = 0.9f; p.gravity = -0.03f; p.positionOnTexture = Vec2b(0, 0); p.sizeOnTexture = Vec2b(16, 16); p.position = position * 16 + Vec2i(random(6, 10), random(6, 10)); const double r = random(0.0, 6.283); p.velocity = Vec2d(random(-0.5, 0.5), random(-0.5, 0.5)); p.color = debrisColor + Vec4d(random(-0.1, 0.1), random(-0.1, 0.1), random(-0.1, 0.1), 0.0); const double dc = -0.5 / (p.lifetime + random(-25, 25)); p.deltaColor = Vec4d(dc, dc, dc, -p.color.a / p.lifetime); p.rotation = random(0.0f, 10.0f); p.deltaRotation = random(-0.1f, 0.1f); p.size = random(0.6f, 0.9f); p.deltaSize = random(0.01f, 0.02f); if(random() % 2) p_particleSystem->addParticle(p); else p_fireParticleSystem->addParticle(p); } disappear(0.2); } } } } anim++; }
PoolTilesExample(void) : make_plane( Vec3f(), Vec3f(7.0f, 0.0f, 0.0f), Vec3f(0.0f, 0.0f,-7.0f), 48, 48 ), plane_instr(make_plane.Instructions()) , plane_indices(make_plane.Indices()) , make_shape() , shape_instr(make_shape.Instructions()) , shape_indices(make_shape.Indices()) , plane_vs(ObjectDesc("Plane vertex")) , shape_vs(ObjectDesc("Shape vertex")) , plane_fs(ObjectDesc("Plane fragment")) , shape_fs(ObjectDesc("Shape fragment")) , plane_camera_matrix(plane_prog, "CameraMatrix") , shape_camera_matrix(shape_prog, "CameraMatrix") , plane_camera_position(plane_prog, "CameraPosition") , width(800) , height(600) , refl_tex_side(width > height ? height : width) , tile_tex_side(64) { gl.RequireAtLeast(LimitQuery::MaxCombinedTextureImageUnits, 5); plane_vs.Source( "#version 140\n" "uniform vec3 LightPosition;" "uniform vec3 CameraPosition;" "uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;" "in vec4 Position;" "in vec2 TexCoord;" "out vec3 vertLightDir;" "out vec3 vertViewDir;" "out vec4 vertReflTexCoord;" "out vec2 vertTileTexCoord;" "void main(void)" "{" " gl_Position = ModelMatrix* Position;" " vertLightDir = normalize(LightPosition - gl_Position.xyz);" " vertViewDir = normalize(CameraPosition - gl_Position.xyz);" " gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;" " vertReflTexCoord = gl_Position;" " vertTileTexCoord = TexCoord;" "}" ); plane_vs.Compile(); plane_fs.Source( "#version 140\n" "uniform sampler2D RandTex, PictTex, TileTex, NormTex;" "uniform sampler2D ReflectTex;" "uniform uint TileCount;" "uniform float Aspect;" "in vec3 vertLightDir;" "in vec3 vertViewDir;" "in vec4 vertReflTexCoord;" "in vec2 vertTileTexCoord;" "out vec4 fragColor;" "void main(void)" "{" " vec3 Normal = texture(" " NormTex, " " vertTileTexCoord * TileCount" " ).rgb;" " vec3 LightRefl = reflect(" " -normalize(vertLightDir)," " normalize(Normal)" " );" " float Diffuse = max(dot(" " Normal, " " vertLightDir" " ), 0.0);" " float Specular = max(dot(" " LightRefl," " vertViewDir" " ), 0.0);" " float PlasterLight = 0.3 + max(Diffuse, 0.0);" " float TileLight = 0.3 + pow(Diffuse, 2.0)*0.9 + pow(Specular, 4.0)*2.5;" " vec2 ReflCoord = vertReflTexCoord.xy;" " ReflCoord /= vertReflTexCoord.w;" " ReflCoord *= 0.5;" " ReflCoord += vec2(Aspect*0.5, 0.5);" " ReflCoord += vec2(Normal.x, Normal.z)*0.5;" " vec3 ReflColor = texture(" " ReflectTex, " " ReflCoord" " ).rgb;" " vec3 TileProps = texture(" " TileTex, " " vertTileTexCoord * TileCount" " ).rgb;" " float Pict = texture(PictTex, vertTileTexCoord).r;" " float Rand = texture(RandTex, vertTileTexCoord).r;" " float LightVsDark = " " mix( 0.1, 0.9, Pict)+" " mix(-0.1, 0.1, Rand);" " vec3 TileColor = mix(" " vec3(0.1, 0.1, 0.5)," " vec3(0.4, 0.4, 0.9)," " LightVsDark " " );" " vec3 PlasterColor = vec3(0.9, 0.9, 0.9);" " fragColor = vec4(" " mix(" " PlasterColor * PlasterLight," " TileColor * TileLight, " " TileProps.b" " ) +" " ReflColor * TileProps.g * 0.6," " 1.0" " );" "}" ); plane_fs.Compile(); plane_prog.AttachShader(plane_vs); plane_prog.AttachShader(plane_fs); plane_prog.Link(); plane_prog.Use(); Vec3f lightPos(3.0f, 2.5f, 2.0f); Uniform<Vec3f>(plane_prog, "LightPosition").Set(lightPos); Uniform<GLuint>(plane_prog, "TileCount").Set(tile_tex_side); Uniform<Mat4f>(plane_prog, "ModelMatrix").Set( ModelMatrixf::Translation(0.0f, -0.5f, 0.0f) ); std::vector<GLfloat> data; GLuint n_per_vertex; n_per_vertex = make_plane.Positions(data); plane_verts.Data(data); DSAVertexArrayAttribEXT(plane, plane_prog, "Position") .Setup<GLfloat>(plane_verts, n_per_vertex) .Enable(); n_per_vertex = make_plane.TexCoordinates(data); plane_texcoords.Data(data); DSAVertexArrayAttribEXT(plane, plane_prog, "TexCoord") .Setup<GLfloat>(plane_texcoords, n_per_vertex) .Enable(); // rand_tex.target = Texture::Target::_2D; rand_tex.Image2D( images::RandomRedUByte( tile_tex_side, tile_tex_side ) ); rand_tex.Filter(TextureFilter::Nearest); rand_tex.Wrap(TextureWrap::Repeat); Texture::Active(0); UniformSampler(plane_prog, "RandTex").Set(0); rand_tex.Bind(); // pict_tex.target = Texture::Target::_2D; pict_tex.Image2D(images::LoadTexture("pool_pictogram")); pict_tex.Filter(TextureFilter::Linear); pict_tex.Wrap(TextureWrap::Repeat); Texture::Active(1); UniformSampler(plane_prog, "PictTex").Set(1); pict_tex.Bind(); // auto tile_image = images::LoadTexture("small_tile"); // tile_tex.target = Texture::Target::_2D; tile_tex.Image2D(tile_image); tile_tex.MinFilter(TextureMinFilter::LinearMipmapLinear); tile_tex.MagFilter(TextureMagFilter::Linear); tile_tex.Wrap(TextureWrap::Repeat); tile_tex.GenerateMipmap(); Texture::Active(2); UniformSampler(plane_prog, "TileTex").Set(2); tile_tex.Bind(); // norm_tex.target = Texture::Target::_2D; norm_tex.Image2D( images::TransformComponents<GLfloat, 3>( images::NormalMap(tile_image), Mat4d( Vec4d(1.0, 0.0, 0.0, 0.0), Vec4d(0.0, 0.0, 1.0, 0.0), Vec4d(0.0,-1.0, 0.0, 0.0), Vec4d(0.0, 0.0, 0.0, 1.0) ) ) ); norm_tex.MinFilter(TextureMinFilter::LinearMipmapLinear); norm_tex.MagFilter(TextureMagFilter::Linear); norm_tex.Wrap(TextureWrap::Repeat); norm_tex.GenerateMipmap(); Texture::Active(3); UniformSampler(plane_prog, "NormTex").Set(3); norm_tex.Bind(); // reflect_tex.target = Texture::Target::_2D; reflect_tex.Image2D( 0, PixelDataInternalFormat::RGB, refl_tex_side, refl_tex_side, 0, PixelDataFormat::RGB, PixelDataType::UnsignedByte, nullptr ); reflect_tex.Filter(TextureFilter::Linear); reflect_tex.Wrap(TextureWrap::ClampToEdge); Texture::Active(4); UniformSampler(plane_prog, "ReflectTex").Set(4); reflect_tex.Bind(); rbo.Storage( PixelDataInternalFormat::DepthComponent, refl_tex_side, refl_tex_side ); fbo.target = Framebuffer::Target::Draw; fbo.AttachTexture( FramebufferAttachment::Color, reflect_tex, 0 ); fbo.AttachRenderbuffer( FramebufferAttachment::Depth, rbo ); shape_vs.Source( "#version 140\n" "uniform vec3 LightPosition;" "uniform mat4 ProjectionMatrix, ModelMatrix, CameraMatrix;" "in vec4 Position;" "in vec3 Normal;" "out vec3 vertNormal;" "out vec3 vertLightDir;" "out vec3 vertLightRefl;" "out vec3 vertViewDir;" "out vec3 vertViewRefl;" "out vec3 vertColor;" "void main(void)" "{" " gl_Position = " " ModelMatrix *" " Position;" " vertLightDir = LightPosition - gl_Position.xyz;" " vertNormal = mat3(ModelMatrix)*Normal;" " vertLightRefl = reflect(" " -normalize(vertLightDir)," " normalize(vertNormal)" " );" " vertViewDir = (" " vec4(0.0, 0.0, 1.0, 1.0)*" " CameraMatrix" " ).xyz;" " vertViewRefl = reflect(" " -normalize(vertViewDir)," " normalize(vertNormal)" " );" " vertColor = vec3(0.3, 0.3, 0.7);" " gl_Position = " " ProjectionMatrix *" " CameraMatrix *" " gl_Position;" "}" ); shape_vs.Compile(); shape_fs.Source( "#version 140\n" "uniform sampler2D PictTex, TileTex;" "uniform uint TileCount;" "in vec3 vertNormal;" "in vec3 vertLightDir;" "in vec3 vertLightRefl;" "in vec3 vertViewDir;" "in vec3 vertViewRefl;" "in vec3 vertColor;" "out vec4 fragColor;" "void main(void)" "{" " float LtDist = length(vertLightDir);" " float Diffuse = dot(" " normalize(vertNormal), " " normalize(vertLightDir)" " ) / LtDist;" " float Specular = dot(" " normalize(vertLightRefl)," " normalize(vertViewDir)" " );" " vec3 LightColor = vec3(1.0, 1.0, 1.0);" " vec2 ReflTexCoord = -vec2(" " vertViewRefl.x," " vertViewRefl.z " " );" " ReflTexCoord *= 0.25;" " ReflTexCoord += vec2(0.5, 0.5);" " float Pict = texture(PictTex, ReflTexCoord).r;" " float LightVsDark = mix( 0.1, 0.9, Pict);" " vec3 TileColor = mix(" " vec3(0.2, 0.2, 0.6)," " vec3(0.5, 0.5, 0.9)," " LightVsDark" " );" " vec3 PlasterColor = vec3(0.7, 0.7, 0.7);" " vec3 FloorColor = mix(" " PlasterColor, " " TileColor, " " texture(TileTex, ReflTexCoord*TileCount).b" " );" " vec3 ReflColor = mix(" " vec3(0.5, 0.5, 0.4), " " FloorColor, " " pow(max((-vertViewRefl.y-0.5)*2.0, 0.0), 2.0)" " );" " fragColor = vec4(" " vertColor * 0.4 + " " ReflColor * 0.3 + " " (LightColor + vertColor)*pow(max(2.5*Diffuse, 0.0), 3) + " " LightColor * pow(max(Specular, 0.0), 64), " " 1.0" " );" "}" ); shape_fs.Compile(); shape_prog.AttachShader(shape_vs); shape_prog.AttachShader(shape_fs); shape_prog.Link(); shape_prog.Use(); Uniform<Vec3f>(shape_prog, "LightPosition").Set(lightPos); Uniform<Mat4f>(shape_prog, "ModelMatrix").Set( ModelMatrixf::Translation(0.0f, 0.6f, 0.0f) ); UniformSampler(shape_prog, "PictTex").Set(0); UniformSampler(shape_prog, "TileTex").Set(1); Uniform<GLuint>(shape_prog, "TileCount").Set(tile_tex_side); n_per_vertex = make_shape.Positions(data); shape_verts.Data(data); DSAVertexArrayAttribEXT(shape, shape_prog, "Position") .Setup<GLfloat>(shape_verts, n_per_vertex) .Enable(); n_per_vertex = make_shape.Normals(data); shape_normals.Data(data); DSAVertexArrayAttribEXT(shape, shape_prog, "Normal") .Setup<GLfloat>(shape_normals, n_per_vertex) .Enable(); // gl.ClearColor(0.5f, 0.5f, 0.4f, 0.0f); gl.ClearDepth(1.0f); gl.Enable(Capability::DepthTest); }
void Camera::setUpVec(Vec4d upVec) { //Normalize double vecLength = sqrt(upVec(0)*upVec(0) + upVec(1)*upVec(1) + upVec(2)*upVec(2)); m_upVec = Vec4d(upVec(0)/vecLength,upVec(1)/vecLength,upVec(2)/vecLength,0); }
void SimpleDraw::IdentifyLineRed( const Vec3d & p1, const Vec3d & p2, bool showVec3ds /*= true*/ ) { // Red line IdentifyLine(p1, p2, Vec4d(1.0, 0.2, 0.2, 1), showVec3ds); }
TEST(MatTest, mirZMatrix) { const Mat4x4d& m = Mat4x4d::MirZ; const Vec4d v(1.0, 1.0, 1.0, 0.0); ASSERT_VEC_EQ(Vec4d(1.0, 1.0, -1.0, 0.0), m * v); }
void Camera::setViewVec(Vec4d viewVec) { //Normalize double vecLength = sqrt(viewVec(0)*viewVec(0) + viewVec(1)*viewVec(1) + viewVec(2)*viewVec(2)); m_viewVec = Vec4d(viewVec(0)/vecLength,viewVec(1)/vecLength,viewVec(2)/vecLength,0); }
void ToxicGas::onUpdate() { if(!(random() % 3)) { ParticleSystem* p_particleSystem = level.getParticleSystem(); ParticleSystem* p_fireParticleSystem = level.getFireParticleSystem(); ParticleSystem::Particle p; p.lifetime = random(10, 20); p.damping = 0.96f; p.gravity = -0.005f; if(random() % 2) p.positionOnTexture = Vec2b(0, 64); else p.positionOnTexture = Vec2b(0, 0); p.sizeOnTexture = Vec2b(16, 16); p.position = position * 16 + Vec2i(random(2, 14), random(2, 14)); const double r = random(0.0, 6.283); p.velocity = random(0.0, 1.0) * Vec2d(sin(r), cos(r)); p.color = Vec4d(random(0.4, 1.0), random(0.75, 1.0), random(0.0, 0.5), random(0.5, 1.5)); p.deltaColor = Vec4d(0.0, 0.0, 0.0, -p.color.a / p.lifetime); p.rotation = random(0.0f, 10.0f); p.deltaRotation = random(-0.05f, 0.05f); p.size = 0.01f; p.deltaSize = random(0.05f, 0.25f); if(random() % 2) p_particleSystem->addParticle(p); else p_fireParticleSystem->addParticle(p); } std::vector<Object*> objects = level.getObjectsAt(position); for(std::vector<Object*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { if((*i)->getFlags() & OF_BLOCK_GAS) { disappear(0.0); return; } } if(spreadCounter > 0) spreadCounter--; else if(spreadCounter == 0) { // in alle freien Richtungen ausbreiten for(int dir = 0; dir < 4; dir++) { Vec2i p = position + intToDir(dir); if(!level.isValidPosition(p)) continue; // wenn da schon Gas ist, abbrechen if(level.getAIFlags(p) & 2) continue; // Tiles blockieren das Gas. uint tileID = level.getTileAt(1, p); const TileSet::TileInfo& tileInfo = level.getTileSet()->getTileInfo(tileID); if(tileInfo.type == 1 || tileInfo.type == 2) continue; // Objekte? objects = level.getObjectsAt(p); bool blocked = false; for(std::vector<Object*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { if((*i)->getFlags() & OF_BLOCK_GAS) { blocked = true; break; } } if(blocked) continue; // neues Gasobjekt erzeugen new ToxicGas(level, p); } spreadCounter = random(50, 80); } }
void TestApp::test_vector4(void) { Console::write_line(" Header: cl_vector.h"); Console::write_line(" Class: Vec4"); Console::write_line(" Function: distance3()"); { Vec4d test_a(2.0,3.0,4.0,5.0); Vec4d test_b(3.0,4.0,5.0,6.0); if (test_a.distance3(test_b) != sqrt(1.0 + 1.0 + 1.0 )) fail(); } Console::write_line(" Function: distance4()"); { Vec4d test_a(2.0,3.0,4.0,5.0); Vec4d test_b(3.0,4.0,5.0,6.0); if (test_a.distance4(test_b) != sqrt(1.0 + 1.0 + 1.0 + 1.0 )) fail(); } Console::write_line(" Function: length3()"); { Vec4d testi(3.0,4.0,5.0,6.0); if (testi.length3() != sqrt(50.0 )) fail(); } Console::write_line(" Function: length4()"); { Vec4d testi(3.0,4.0,5.0,6.0); if (testi.length4() != sqrt(86.0 )) fail(); } Console::write_line(" Function: normalize3()"); { Vec4d testi(3.0,4.0,5.0,6.0); testi.normalize3(); if (testi != Vec4d(3.0/sqrt(50.0), 4.0/sqrt(50.0), 5.0/sqrt(50.0), 6.0)) fail(); } Console::write_line(" Function: static normalize3()"); { Vec4d testi(3.0,4.0,5.0,6.0); if (Vec4d::normalize3(testi) != Vec4d(3.0/sqrt(50.0), 4.0/sqrt(50.0), 5.0/sqrt(50.0), 6.0)) fail(); } Console::write_line(" Function: dot3()"); { Vec4d test_a(3.0,4.0,5.0,6.0); Vec4d test_b(13.0,14.0,15.0,16.0); if (test_a.dot3(test_b) != ((3.0 * 13.0)+ (4.0*14.0) + (5.0 * 15.0))) fail(); } Console::write_line(" Function: dot4()"); { Vec4d test_a(3.0,4.0,5.0,6.0); Vec4d test_b(13.0,14.0,15.0,16.0); if (test_a.dot4(test_b) != ((3.0 * 13.0)+ (4.0*14.0) + (5.0 * 15.0) + (6.0 * 16.0))) fail(); } Console::write_line(" Function: normalize4()"); { Vec4d testi(3.0,4.0,5.0,6.0); testi.normalize4(); if (testi != Vec4d(3.0/sqrt(86.0), 4.0/sqrt(86.0), 5.0/sqrt(86.0), 6.0/sqrt(86.0))) fail(); } Console::write_line(" Function: static normalize4()"); { Vec4d testi(3.0,4.0,5.0,6.0); if (Vec4d::normalize4(testi) != Vec4d(3.0/sqrt(86.0), 4.0/sqrt(86.0), 5.0/sqrt(86.0), 6.0/sqrt(86.0))) fail(); } Console::write_line(" Function: operator += (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd += Vec4d(1.0, 2.0, 3.0, 4.0); if (testd.x != 3.5) fail(); if (testd.y != 5.5) fail(); if (testd.z != 7.5) fail(); if (testd.w != 9.5) fail(); Vec4i testi(2, 3, 4, 5); testi += Vec4i(1, 2, 3, 4); if (testi.x != 3) fail(); if (testi.y != 5) fail(); if (testi.z != 7) fail(); if (testi.w != 9) fail(); } Console::write_line(" Function: operator += ( Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd += valued; if (testd.x != 4.5) fail(); if (testd.y != 5.5) fail(); if (testd.z != 6.5) fail(); if (testd.w != 7.5) fail(); Vec4i testi(2, 3, 4, 5); int valuei = 2; testi += valuei; if (testi.x != 4) fail(); if (testi.y != 5) fail(); if (testi.z != 6) fail(); if (testi.w != 7) fail(); } Console::write_line(" Function: operator + (Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd = testd + valued; if (testd.x != 4.5) fail(); if (testd.y != 5.5) fail(); if (testd.z != 6.5) fail(); if (testd.w != 7.5) fail(); Vec4i testi(2, 3, 4, 5); int valuei = 2; testi = testi + valuei; if (testi.x != 4) fail(); if (testi.y != 5) fail(); if (testi.z != 6) fail(); if (testi.w != 7) fail(); } Console::write_line(" Function: operator + (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd = testd + Vec4d(1.5, 2.5, 3.5, 4.5); if (testd.x != 4.0) fail(); if (testd.y != 6.0) fail(); if (testd.z != 8.0) fail(); if (testd.w != 10.0) fail(); Vec4i testi(2, 3, 4, 5); testi = testi + Vec4i(1, 2, 3, 4); if (testi.x != 3) fail(); if (testi.y != 5) fail(); if (testi.z != 7) fail(); if (testi.w != 9) fail(); } Console::write_line(" Function: operator -= (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd -= Vec4d(1.0, 2.0, 3.0, 4.0); if (testd.x != 1.5) fail(); if (testd.y != 1.5) fail(); if (testd.z != 1.5) fail(); if (testd.w != 1.5) fail(); Vec4i testi(2, 3, 4, 5); testi -= Vec4i(1, 2, 3, 4); if (testi.x != 1) fail(); if (testi.y != 1) fail(); if (testi.z != 1) fail(); if (testi.w != 1) fail(); } Console::write_line(" Function: operator -= ( Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd -= valued; if (testd.x != 0.5) fail(); if (testd.y != 1.5) fail(); if (testd.z != 2.5) fail(); if (testd.w != 3.5) fail(); Vec4i testi(2, 3, 4, 5); int valuei = 2; testi -= valuei; if (testi.x != 0) fail(); if (testi.y != 1) fail(); if (testi.z != 2) fail(); if (testi.w != 3) fail(); } Console::write_line(" Function: operator - (Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd = testd - valued; if (testd.x != 0.5) fail(); if (testd.y != 1.5) fail(); if (testd.z != 2.5) fail(); if (testd.w != 3.5) fail(); Vec4i testi(2, 3, 4, 5); int valuei = 2; testi = testi - valuei; if (testi.x != 0) fail(); if (testi.y != 1) fail(); if (testi.z != 2) fail(); if (testi.w != 3) fail(); } Console::write_line(" Function: operator - (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd = testd - Vec4d(1.5, 2.5, 3.5, 4.5); if (testd.x != 1.0) fail(); if (testd.y != 1.0) fail(); if (testd.z != 1.0) fail(); if (testd.w != 1.0) fail(); Vec4i testi(2, 3, 4, 5); testi = testi - Vec4i(1, 2, 3, 4); if (testi.x != 1) fail(); if (testi.y != 1) fail(); if (testi.z != 1) fail(); if (testi.w != 1) fail(); } Console::write_line(" Function: operator *= (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd *= Vec4d(1.0, 2.0, 3.0, 4.0); if (testd.x != 2.5) fail(); if (testd.y != 7.0) fail(); if (testd.z != 13.5) fail(); if (testd.w != 22.0) fail(); Vec4i testi(2, 3, 4, 5); testi *= Vec4i(1, 2, 3, 4); if (testi.x != 2) fail(); if (testi.y != 6) fail(); if (testi.z != 12) fail(); if (testi.w != 20) fail(); } Console::write_line(" Function: operator *= ( Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd *= valued; if (testd.x != 5.0) fail(); if (testd.y != 7.0) fail(); if (testd.z != 9.0) fail(); if (testd.w != 11.0) fail(); Vec4i testi(2, 3, 4, 5); int valuei = 2; testi *= valuei; if (testi.x != 4) fail(); if (testi.y != 6) fail(); if (testi.z != 8) fail(); if (testi.w != 10) fail(); } Console::write_line(" Function: operator * (Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd = testd * valued; if (testd.x != 5.0) fail(); if (testd.y != 7.0) fail(); if (testd.z != 9.0) fail(); if (testd.w != 11.0) fail(); Vec4i testi(2, 3, 4, 5); int valuei = 2; testi = testi * valuei; if (testi.x != 4) fail(); if (testi.y != 6) fail(); if (testi.z != 8) fail(); if (testi.w != 10) fail(); } Console::write_line(" Function: operator * (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd = testd * Vec4d(1.5, 2.5, 3.5, 4.5); if (testd.x != 3.75) fail(); if (testd.y != 8.75) fail(); if (testd.z != 15.75) fail(); if (testd.w != 24.75) fail(); Vec4i testi(2, 3, 4, 5); testi = testi * Vec4i(1, 2, 3, 4); if (testi.x != 2) fail(); if (testi.y != 6) fail(); if (testi.z != 12) fail(); if (testi.w != 20) fail(); } Console::write_line(" Function: operator /= (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd /= Vec4d(1.0, 2.0, 3.0, 4.0); if (testd.x != 2.5) fail(); if (testd.y != 1.75) fail(); if (testd.z != 1.5) fail(); if (testd.w != 1.375) fail(); Vec4i testi(2, 10, 20, 5); testi /= Vec4i(1, 2, 3, 4); if (testi.x != 2) fail(); if (testi.y != 5) fail(); if (testi.z != 6) fail(); if (testi.w != 1) fail(); } Console::write_line(" Function: operator /= ( Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd /= valued; if (testd.x != 1.25) fail(); if (testd.y != 1.75) fail(); if (testd.z != 2.25) fail(); if (testd.w != 2.75) fail(); Vec4i testi(2, 10, 20, 5); int valuei = 2; testi /= valuei; if (testi.x != 1) fail(); if (testi.y != 5) fail(); if (testi.z != 10) fail(); if (testi.w != 2) fail(); } Console::write_line(" Function: operator / (Type value)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); double valued = 2.0; testd = testd / valued; if (testd.x != 1.25) fail(); if (testd.y != 1.75) fail(); if (testd.z != 2.25) fail(); if (testd.w != 2.75) fail(); Vec4i testi(2, 10, 20, 5); int valuei = 2; testi = testi / valuei; if (testi.x != 1) fail(); if (testi.y != 5) fail(); if (testi.z != 10) fail(); if (testi.w != 2) fail(); } Console::write_line(" Function: operator / (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 10.0); testd = testd / Vec4d(1.0, 2.5, 4.5, 2.0); if (testd.x != 2.5) fail(); if (testd.y != 1.4) fail(); if (testd.z != 1.0) fail(); if (testd.w != 5.0) fail(); Vec4i testi(2, 10, 20, 5); testi = testi / Vec4i(1, 2, 3, 4); if (testi.x != 2) fail(); if (testi.y != 5) fail(); if (testi.z != 6) fail(); if (testi.w != 1) fail(); } Console::write_line(" Function: operator = (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); testd = Vec4d(1.0, 2.0, 3.0, 4.0); if (testd.x != 1.0) fail(); if (testd.y != 2.0) fail(); if (testd.z != 3.0) fail(); if (testd.w != 4.0) fail(); Vec4i testi(2, 3, 4, 5); testi = Vec4i(1, 2, 3, 4); if (testi.x != 1) fail(); if (testi.y != 2) fail(); if (testi.z != 3) fail(); if (testi.w != 4) fail(); } Console::write_line(" Function: operator == (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); if (testd == Vec4d(1.0, 2.0, 3.0, 4.0)) fail(); if (testd == Vec4d(2.5, 2.0, 3.0, 4.0)) fail(); if (testd == Vec4d(2.5, 3.5, 3.0, 4.0)) fail(); if (testd == Vec4d(2.5, 3.5, 4.5, 4.0)) fail(); if (!(testd == Vec4d(2.5, 3.5, 4.5, 5.5))) fail(); Vec4i testi(2, 3, 4, 5); if (testi == Vec4i(1, 2, 3, 4)) fail(); if (testi == Vec4i(2, 2, 3, 4)) fail(); if (testi == Vec4i(2, 3, 3, 4)) fail(); if (testi == Vec4i(2, 3, 4, 4)) fail(); if (!(testi == Vec4i(2, 3, 4, 5))) fail(); } Console::write_line(" Function: operator != (const Vec4<Type>& vector)"); { Vec4d testd(2.5, 3.5, 4.5, 5.5); if (!(testd != Vec4d(1.0, 2.0, 3.0, 4.0))) fail(); if (!(testd != Vec4d(2.5, 2.0, 3.0, 4.0))) fail(); if (!(testd != Vec4d(2.5, 3.5, 3.0, 4.0))) fail(); if (!(testd != Vec4d(2.5, 3.5, 4.5, 4.0))) fail(); if ((testd != Vec4d(2.5, 3.5, 4.5, 5.5))) fail(); Vec4i testi(2, 3, 4, 5); if (!(testi != Vec4i(1, 2, 3, 4))) fail(); if (!(testi != Vec4i(2, 2, 3, 4))) fail(); if (!(testi != Vec4i(2, 3, 3, 4))) fail(); if (!(testi != Vec4i(2, 3, 4, 4))) fail(); if ((testi != Vec4i(2, 3, 4, 5))) fail(); } Console::write_line(" Function: round()"); { Vec4d testd(2.0, 2.5, -2.0, -2.5); testd.round(); if (testd.x != 2.0) fail(); if (testd.y != 3.0) fail(); if (testd.z != -2.0) fail(); if (testd.w != -2.0) fail(); Vec4f testf(2.0f, 2.5f, -2.0f, -2.9f); testf.round(); if (testf.x != 2.0f) fail(); if (testf.y != 3.0f) fail(); if (testf.z != -2.0f) fail(); if (testf.w != -3.0f) fail(); } Console::write_line(" Function: static round()"); { Vec4d testd(2.0, 2.5, -2.0, -2.5); Vec4d destd = Vec4d::round(testd); if (destd.x != 2.0) fail(); if (destd.y != 3.0) fail(); if (destd.z != -2.0) fail(); if (destd.w != -2.0) fail(); Vec4f testf(2.0f, 2.5f, -2.0f, -2.9f); Vec4f destf = Vec4f::round(testf); if (destf.x != 2.0f) fail(); if (destf.y != 3.0f) fail(); if (destf.z != -2.0f) fail(); if (destf.w != -3.0f) fail(); } }
Vec4d Raytracer::shade(const RayIntersection& intersection, size_t depth) const { // This offset must be added to intersection points for further // traced rays to avoid noise in the image const Vec3d offset(intersection.normal() * Math::safetyEps()); Vec4d color(0,0,0,1); std::shared_ptr<const Renderable> renderable = intersection.renderable(); std::shared_ptr<const Material> material = renderable->material(); for(size_t i=0;i <mScene->lights().size();++i) { const Light &light = *(mScene->lights()[i].get()); //Shadow ray from light to hit point. const Vec3d L = (intersection.position() + offset) - light.position(); const Ray shadowRay(light.position(), L); //Shade only if light in visible from intersection point. if (!mScene->anyIntersection(shadowRay,L.length())) color += material->shade(intersection,light); } // limit recursion depth if (depth >= mMaxDepth) return color; Vec3d dir = reflect(intersection.ray().direction(), intersection.normal()); Ray reflectedRay(intersection.position() + offset, dir); double reflectance = material->reflectance(); color = color * (1 - reflectance) + reflectance * trace(reflectedRay, depth - 1) + Vec4d(0.0,0.0,0.0,1.0); return color; }
void Scarry::draw(wardraw_t *wd){ Scarry *const p = this; static int init = 0; static suftex_t *pst; static suf_t *sufbase = NULL; if(!w) return; /* cull object */ /* if(beamer_cull(this, wd)) return;*/ // wd->lightdraws++; draw_healthbar(this, wd, health / getMaxHealth(), getHitRadius(), -1., capacitor / maxenergy()); if(wd->vw->gc->cullFrustum(pos, getHitRadius())) return; #if 0 if(init == 0) do{ init = 1; sufbase = CallLoadSUF("models/spacecarrier.bin"); if(!sufbase) break; CallCacheBitmap("bridge.bmp", "bridge.bmp", NULL, NULL); CallCacheBitmap("beamer_panel.bmp", "beamer_panel.bmp", NULL, NULL); CallCacheBitmap("bricks.bmp", "bricks.bmp", NULL, NULL); CallCacheBitmap("runway.bmp", "runway.bmp", NULL, NULL); suftexparam_t stp; stp.flags = STP_MAGFIL | STP_MINFIL | STP_ENV; stp.magfil = GL_LINEAR; stp.minfil = GL_LINEAR; stp.env = GL_ADD; stp.mipmap = 0; CallCacheBitmap5("engine2.bmp", "engine2br.bmp", &stp, "engine2.bmp", NULL); pst = AllocSUFTex(sufbase); extern GLuint screentex; glNewList(pst->a[0].list, GL_COMPILE); glBindTexture(GL_TEXTURE_2D, screentex); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); glDisable(GL_LIGHTING); glEndList(); } while(0); if(sufbase){ static const double normal[3] = {0., 1., 0.}; double scale = SCARRY_SCALE; static const GLdouble rotaxis[16] = { -1,0,0,0, 0,1,0,0, 0,0,-1,0, 0,0,0,1, }; Mat4d mat; glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT); glPushMatrix(); transform(mat); glMultMatrixd(mat); #if 1 for(int i = 0; i < nhitboxes; i++){ Mat4d rot; glPushMatrix(); gldTranslate3dv(hitboxes[i].org); rot = hitboxes[i].rot.tomat4(); glMultMatrixd(rot); hitbox_draw(this, hitboxes[i].sc); glPopMatrix(); } #endif Mat4d modelview, proj; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, proj); Mat4d trans = proj * modelview; texture((glPushMatrix(), glScaled(1./2., 1./2., 1.), glTranslated(1, 1, 0), glMultMatrixd(trans) )); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(1,0,0,0)); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,1,0,0)); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_R, GL_EYE_PLANE, Vec4<int>(0,0,1,0)); glEnable(GL_TEXTURE_GEN_R); glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1)); glEnable(GL_TEXTURE_GEN_Q); glPushMatrix(); glScaled(scale, scale, scale); glMultMatrixd(rotaxis); DecalDrawSUF(sufbase, SUF_ATR, NULL, pst, NULL, NULL); glPopMatrix(); texture((glPopMatrix())); glPopMatrix(); glPopAttrib(); } #endif }
Camera::Camera() { setUpVec(Vec4d(0,1,0,0)); setViewVec(Vec4d(0,0,-1,0)); setEyePoint(Vec4d(0,0,1,0)); }
Vec4d ConstantMaterial::shade(const RayIntersection& intersection, const Light& light) const { return Vec4d(this->color(),1.0); }
void Camera::renderGraph(const Node *graph) { if (!graph || dynamic_cast<const osg::Camera*>(graph)) return; const osg::BoundingSphered &bound = computeBoundsOf(graph); const double r = bound.radius(); const Vec3d view_center = bound.center() * qMatrix.back(); if (-view_center.z() + r < znear || -view_center.z() - r > zfar) return; bool bPopMatrix = false; const osg::StateSet *stateset = graph->getStateSet(); if (stateset) { qStateSet.push_back(qStateSet.back()); processStateSet(stateset, qStateSet.back()); } const PositionAttitudeTransform *ptrans = dynamic_cast<const PositionAttitudeTransform*>(graph); if (ptrans) { const Matrixd mat = Matrixd::translate(-ptrans->getPivotPoint()) * Matrixd::rotate(ptrans->getAttitude()) * Matrixd::scale(ptrans->getScale()) * Matrixd::translate(ptrans->getPosition()); pushMatrix(mat); bPopMatrix = true; } const MatrixTransform *mtrans = dynamic_cast<const MatrixTransform*>(graph); if (mtrans) { pushMatrix(mtrans->getMatrix()); bPopMatrix = true; } const Switch* sgroup = dynamic_cast<const Switch*>(graph); if (sgroup) { for(unsigned int i = 0, nb = sgroup->getNumChildren() ; i < nb ; ++i) if (sgroup->getValue(i)) renderGraph(sgroup->getChild(i)); } else { const Group* group = dynamic_cast<const Group*>(graph); if (group) { for(unsigned int i = 0, nb = group->getNumChildren() ; i < nb ; ++i) renderGraph(group->getChild(i)); } } const Geode *geode = dynamic_cast<const Geode*>(graph); if (geode) { glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL(); bool bParentStateApplied = false; for(unsigned int i = 0, nb = geode->getNumDrawables() ; i < nb ; ++i) { const Geometry * const geom = geode->getDrawable(i)->asGeometry(); if (!geom) { LOG_ERROR() << "[Camera] unsupported drawable : " << geode->getDrawable(i)->className() << std::endl; continue; } const Array * const vtx = geom->getVertexArray(); const Array * const normals = geom->getNormalArray(); const Array * const tcoord = geom->getTexCoordArray(0); if (!vtx) { LOG_ERROR() << "[Camera] no vertex array in Geometry object" << std::endl; continue; } StateSet *local_state = NULL; char tmp[sizeof(StateSet)]; //! Avoid dynamic allocation const osg::StateSet *geom_state = geom->getStateSet(); if (geom_state) { local_state = new(tmp) StateSet(qStateSet.back()); processStateSet(geom_state, *local_state); } if (local_state) { local_state->apply(); bParentStateApplied = false; } else if (!bParentStateApplied) { bParentStateApplied = true; qStateSet.back().apply(); } if (bDoublePrecisionMode) { if (processed_vertex_array.size() < vtx->getNumElements()) processed_vertex_array.resize(vtx->getNumElements()); const void * const ptr = vtx->getDataPointer(); const osg::Matrixd &mat = qMatrix.back() * projectionMatrix; switch(vtx->getDataType()) { case GL_FLOAT: if (vtx->getDataSize() == 4) { const size_t nb = vtx->getNumElements(); for(size_t i = 0 ; i < nb ; ++i) { const Vec4d &p = Vec4d(((const Vec4f*)ptr)[i]) * mat; processed_vertex_array[i] = p / p.w(); } } else if (vtx->getDataSize() == 3) { const size_t nb = vtx->getNumElements(); for(size_t i = 0 ; i < nb ; ++i) { const Vec4d &p = Vec4d(((const Vec3f*)ptr)[i], 1.0) * mat; processed_vertex_array[i] = p / p.w(); } } break; } glEnableClientState(GL_COLOR_ARRAY); CHECK_GL(); if (pContext->hasVBOSupport()) { glBindBuffer(GL_ARRAY_BUFFER, 0); CHECK_GL(); } glColorPointer(4, GL_FLOAT, 0, &(processed_vertex_array.front())); CHECK_GL(); } if (pContext->hasVBOSupport()) { glBindBuffer(GL_ARRAY_BUFFER, pContext->getDataVBOID(vtx->getDataPointer(), vtx->getTotalDataSize())); CHECK_GL(); glVertexPointer(vtx->getDataSize(), vtx->getDataType(), 0, 0); CHECK_GL(); if (normals) { glEnableClientState(GL_NORMAL_ARRAY); CHECK_GL(); glBindBuffer(GL_ARRAY_BUFFER, pContext->getDataVBOID(normals->getDataPointer(), normals->getTotalDataSize())); CHECK_GL(); glNormalPointer(normals->getDataType(), 0, 0); CHECK_GL(); } else { glDisableClientState(GL_NORMAL_ARRAY); CHECK_GL(); } if (tcoord) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); glBindBuffer(GL_ARRAY_BUFFER, pContext->getDataVBOID(tcoord->getDataPointer(), tcoord->getTotalDataSize())); CHECK_GL(); glTexCoordPointer(tcoord->getDataSize(), tcoord->getDataType(), 0, 0); CHECK_GL(); } else { glDisableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); } const size_t nb_prim_set = geom->getNumPrimitiveSets(); for(size_t j = 0 ; j < nb_prim_set ; ++j) { const PrimitiveSet * const pset = geom->getPrimitiveSet(j); const DrawElements * const elts = pset->getDrawElements(); switch(pset->getType()) { case DrawElements::PrimitiveType: break; case DrawElements::DrawArraysPrimitiveType: glDrawArrays(pset->getMode(), pset->index(0), pset->getNumIndices()); CHECK_GL(); break; case DrawElements::DrawArrayLengthsPrimitiveType: break; case DrawElements::DrawElementsUBytePrimitiveType: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pContext->getIndexVBOID(elts->getDataPointer(), elts->getTotalDataSize())); CHECK_GL(); glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_BYTE, 0); CHECK_GL(); break; case DrawElements::DrawElementsUShortPrimitiveType: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pContext->getIndexVBOID(elts->getDataPointer(), elts->getTotalDataSize())); CHECK_GL(); glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_SHORT, 0); CHECK_GL(); break; case DrawElements::DrawElementsUIntPrimitiveType: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pContext->getIndexVBOID(elts->getDataPointer(), elts->getTotalDataSize())); CHECK_GL(); glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_INT, 0); CHECK_GL(); break; } } } else { glVertexPointer(vtx->getDataSize(), vtx->getDataType(), 0, vtx->getDataPointer()); CHECK_GL(); if (normals) { glEnableClientState(GL_NORMAL_ARRAY); CHECK_GL(); glNormalPointer(normals->getDataType(), 0, normals->getDataPointer()); CHECK_GL(); } else { glDisableClientState(GL_NORMAL_ARRAY); CHECK_GL(); } if (tcoord) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); glTexCoordPointer(tcoord->getDataSize(), tcoord->getDataType(), 0, tcoord->getDataPointer()); CHECK_GL(); } else { glDisableClientState(GL_TEXTURE_COORD_ARRAY); CHECK_GL(); } const size_t nb_prim_set = geom->getNumPrimitiveSets(); for(size_t j = 0 ; j < nb_prim_set ; ++j) { const PrimitiveSet * const pset = geom->getPrimitiveSet(j); const DrawElements * const elts = pset->getDrawElements(); switch(pset->getType()) { case DrawElements::PrimitiveType: break; case DrawElements::DrawArraysPrimitiveType: glDrawArrays(pset->getMode(), pset->index(0), pset->getNumIndices()); CHECK_GL(); break; case DrawElements::DrawArrayLengthsPrimitiveType: break; case DrawElements::DrawElementsUBytePrimitiveType: glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_BYTE, elts->getDataPointer()); CHECK_GL(); break; case DrawElements::DrawElementsUShortPrimitiveType: glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_SHORT, elts->getDataPointer()); CHECK_GL(); break; case DrawElements::DrawElementsUIntPrimitiveType: glDrawRangeElements(elts->getMode(), 0, vtx->getNumElements() - 1, elts->getNumIndices(), GL_UNSIGNED_INT, elts->getDataPointer()); CHECK_GL(); break; } } } if (local_state) local_state->~StateSet(); } } if (bPopMatrix) popMatrix(); if (stateset) qStateSet.pop_back(); }