glm::quat angleToQuatForExtraRotation(const Anglef & angle) { Anglef vt1; vt1.setYaw(angle.getRoll()); vt1.setPitch(angle.getPitch()); vt1.setRoll(angle.getYaw()); return QuatFromAngles(vt1); }
glm::mat4 toRotationMatrix(const Anglef & angle) { float yaw = glm::radians(angle.getYaw()); float pitch = glm::radians(angle.getPitch()); float roll = glm::radians(angle.getRoll()); glm::mat4 rotateX = glm::eulerAngleX(yaw); glm::mat4 rotateY = glm::eulerAngleY(pitch); glm::mat4 rotateZ = glm::eulerAngleZ(-roll); return rotateZ * rotateX * rotateY; }
void EERIE_TRANSFORM::updateFromAngle(const Anglef &angle) { float pitch = glm::radians(angle.getPitch()); xcos = std::cos(pitch); xsin = std::sin(pitch); float yaw = glm::radians(angle.getYaw()); ycos = std::cos(yaw); ysin = std::sin(yaw); float roll = glm::radians(angle.getRoll()); zcos = std::cos(roll); zsin = std::sin(roll); glm::mat4 translation = glm::translate(glm::mat4(1), -pos); worldToView = toRotationMatrix(angle) * translation; }
//************************************************************************************* // Converts euler angles to a unit quaternion. //************************************************************************************* glm::quat QuatFromAngles(const Anglef & angle) { float A, B; A = glm::radians(angle.getYaw()) * ( 1.0f / 2 ); B = glm::radians(angle.getPitch()) * ( 1.0f / 2 ); float fSinYaw = glm::sin(A); float fCosYaw = glm::cos(A); float fSinPitch = glm::sin(B); float fCosPitch = glm::cos(B); A = glm::radians(angle.getRoll()) * ( 1.0f / 2 ); float fSinRoll = glm::sin(A); float fCosRoll = glm::cos(A); A = fCosRoll * fCosPitch; B = fSinRoll * fSinPitch; glm::quat q; q.x = fSinRoll * fCosPitch * fCosYaw - fCosRoll * fSinPitch * fSinYaw; q.y = fCosRoll * fSinPitch * fCosYaw + fSinRoll * fCosPitch * fSinYaw; q.z = A * fSinYaw - B * fCosYaw; q.w = A * fCosYaw + B * fSinYaw; return q; }
void CMagicMissile::Render() { Vec3f lastpos, newpos; Vec3f v; if(ulCurrentTime >= ulDuration) return; RenderMaterial mat; mat.setCulling(Renderer::CullNone); mat.setDepthTest(true); mat.setBlendType(RenderMaterial::Additive); if(tex_mm) mat.setTexture(tex_mm); if(bMove) { float fOneOnDuration = 1.f / (float)(ulDuration); fTrail = (ulCurrentTime * fOneOnDuration) * (iBezierPrecision + 2) * 5; } newpos = lastpos = pathways[0]; for(int i = 0; i < 5; i++) { int kp = i; int kpprec = (i > 0) ? kp - 1 : kp ; int kpsuiv = kp + 1 ; int kpsuivsuiv = (i < (5 - 2)) ? kpsuiv + 1 : kpsuiv; for(int toto = 1; toto < iBezierPrecision; toto++) { if(fTrail < i * iBezierPrecision + toto) break; float t = toto * fOneOnBezierPrecision; float t1 = t; float t2 = t1 * t1 ; float t3 = t2 * t1 ; float f0 = 2.f * t3 - 3.f * t2 + 1.f ; float f1 = -2.f * t3 + 3.f * t2 ; float f2 = t3 - 2.f * t2 + t1 ; float f3 = t3 - t2 ; float val = pathways[kpsuiv].x; float p0 = 0.5f * (val - pathways[kpprec].x) ; float p1 = 0.5f * (pathways[kpsuivsuiv].x - pathways[kp].x) ; v.x = f0 * pathways[kp].x + f1 * val + f2 * p0 + f3 * p1 ; val = pathways[kpsuiv].y ; p0 = 0.5f * (val - pathways[kpprec].y) ; p1 = 0.5f * (pathways[kpsuivsuiv].y - pathways[kp].y) ; v.y = f0 * pathways[kp].y + f1 * val + f2 * p0 + f3 * p1 ; val = pathways[kpsuiv].z ; p0 = 0.5f * (val - pathways[kpprec].z) ; p1 = 0.5f * (pathways[kpsuivsuiv].z - pathways[kp].z) ; v.z = f0 * pathways[kp].z + f1 * val + f2 * p0 + f3 * p1 ; newpos = v; if(!((fTrail - (i * iBezierPrecision + toto)) > iLength)) { float c; if(fTrail < iLength) { c = 1.0f - ((fTrail - (i * iBezierPrecision + toto)) / fTrail); } else { c = 1.0f - ((fTrail - (i * iBezierPrecision + toto)) / (float)iLength); } float fsize = c; float alpha = c - 0.2f; if(alpha < 0.2f) alpha = 0.2f; c += Random::getf(-0.1f, 0.1f); c = glm::clamp(c, 0.f, 1.f); Color color = (m_trailColor * (c * alpha)).to<u8>(); if(fsize < 0.5f) fsize = fsize * 2 * 3; else fsize = (1.0f - fsize + 0.5f) * 2 * (3 * 0.5f); float fs = fsize * 6 + Random::getf(0.f, 0.3f); float fe = fsize * 6 + Random::getf(0.f, 0.3f); Draw3DLineTexNew(mat, lastpos, newpos, color, color, fs, fe); } Vec3f temp_vector = lastpos; lastpos = newpos; newpos = temp_vector; } } Vec3f av = newpos - lastpos; float bubu = getAngle(av.x, av.z, 0, 0); float bubu1 = getAngle(av.x, av.y, 0, 0); eCurPos = lastpos; Anglef stiteangle; stiteangle.setPitch(-glm::degrees(bubu)); stiteangle.setYaw(0); stiteangle.setRoll(-(glm::degrees(bubu1))); if(av.x < 0) stiteangle.setRoll(stiteangle.getRoll() - 90); if(av.x > 0) stiteangle.setRoll(stiteangle.getRoll() + 90); if(stiteangle.getRoll() < 0) stiteangle.setRoll(stiteangle.getRoll() + 360.0f); Draw3DObject(smissile, stiteangle, eCurPos, Vec3f_ONE, m_projectileColor, mat); }
bool Manage3DCursor(Entity * io, bool simulate) { arx_assert(io); if(BLOCK_PLAYER_CONTROLS) return false; float ag = player.angle.getYaw(); if(ag > 180) ag = ag - 360; float drop_miny = (float)(g_size.center().y) - g_size.center().y * (ag * (1.f/70)); if(DANAEMouse.y < drop_miny) return false; Anglef temp = Anglef::ZERO; if(io->ioflags & IO_INVERTED) { temp.setYaw(180.f); temp.setPitch(-MAKEANGLE(270.f - io->angle.getPitch() - (player.angle.getPitch() - STARTED_ANGLE))); } else { temp.setPitch(MAKEANGLE(270.f - io->angle.getPitch() - (player.angle.getPitch() - STARTED_ANGLE))); } EERIE_3D_BBOX bbox; for(size_t i = 0; i < io->obj->vertexlist.size(); i++) { bbox.add(io->obj->vertexlist[i].v); } Vec3f mvectx = angleToVectorXZ(player.angle.getPitch() - 90.f); Vec2f mod = Vec2f(Vec2i(DANAEMouse) - g_size.center()) / Vec2f(g_size.center()) * Vec2f(160.f, 220.f); mvectx *= mod.x; Vec3f mvecty(0, mod.y, 0); Vec3f orgn = player.pos; orgn += angleToVector(player.angle) * 50.f; orgn += mvectx; orgn.y += mvecty.y; Vec3f dest = player.pos; dest += angleToVector(player.angle) * 10000.f; dest += mvectx; dest.y += mvecty.y * 5.f; Vec3f pos = orgn; Vec3f movev = glm::normalize(dest - orgn); float lastanything = 0.f; float height = -(bbox.max.y - bbox.min.y); if(height > -30.f) height = -30.f; Vec3f objcenter = bbox.min + (bbox.max - bbox.min) * Vec3f(0.5f); Vec3f collidpos = Vec3f_ZERO; bool collidpos_ok = false; { float maxdist = 0.f; for(size_t i = 0; i < io->obj->vertexlist.size(); i++) { const EERIE_VERTEX & vert = io->obj->vertexlist[i]; float dist = glm::distance(Vec2f(objcenter.x, objcenter.z), Vec2f(vert.v.x, vert.v.z)) - 4.f; maxdist = std::max(maxdist, dist); } if(io->obj->pbox) { Vec2f tmpVert(io->obj->pbox->vert[0].initpos.x, io->obj->pbox->vert[0].initpos.z); for(int i = 1; i < io->obj->pbox->nb_physvert; i++) { const PHYSVERT & physVert = io->obj->pbox->vert[i]; float dist = glm::distance(tmpVert, Vec2f(physVert.initpos.x, physVert.initpos.z)) + 14.f; maxdist = std::max(maxdist, dist); } } Cylinder cyl2; const float inc = 10.f; long iterating = 40; cyl2.height = std::min(-30.f, height); cyl2.radius = glm::clamp(maxdist, 20.f, 150.f); while(iterating > 0) { cyl2.origin = pos + movev * inc + Vec3f(0.f, bbox.max.y, 0.f); float anything = CheckAnythingInCylinder(cyl2, io, CFLAG_JUST_TEST | CFLAG_COLLIDE_NOCOL | CFLAG_NO_NPC_COLLIDE); if(anything < 0.f) { if(iterating == 40) { CANNOT_PUT_IT_HERE = 1; // TODO is this correct ? return true; } iterating = 0; collidpos = cyl2.origin; if(lastanything < 0.f) { pos.y += lastanything; collidpos.y += lastanything; } } else { pos = cyl2.origin; lastanything = anything; } iterating--; } collidpos_ok = iterating == -1; } objcenter = VRotateY(objcenter, temp.getPitch()); collidpos.x -= objcenter.x; collidpos.z -= objcenter.z; pos.x -= objcenter.x; pos.z -= objcenter.z; if(!collidpos_ok) { CANNOT_PUT_IT_HERE = 1; return false; } if(collidpos_ok && closerThan(player.pos, pos, 300.f)) { if(simulate) { ARX_INTERACTIVE_Teleport(io, pos, true); io->gameFlags &= ~GFLAG_NOCOMPUTATION; glm::quat rotation = glm::toQuat(toRotationMatrix(temp)); if(SPECIAL_DRAGINTER_RENDER) { if(glm::abs(lastanything) > glm::abs(height)) { TransformInfo t(collidpos, rotation, io->scale); static const float invisibility = 0.5f; DrawEERIEInter(io->obj, t, io, false, invisibility); } else { TransformInfo t(pos, rotation, io->scale); float invisibility = Cedric_GetInvisibility(io); DrawEERIEInter(io->obj, t, io, false, invisibility); } } } else { if(glm::abs(lastanything) > std::min(glm::abs(height), 12.0f)) { Entity * io = DRAGINTER; ARX_PLAYER_Remove_Invisibility(); io->obj->pbox->active = 1; io->obj->pbox->stopcount = 0; io->pos = collidpos; io->velocity = Vec3f_ZERO; io->stopped = 1; movev.x *= 0.0001f; movev.y = 0.1f; movev.z *= 0.0001f; Vec3f viewvector = movev; Anglef angle = temp; io->soundtime = 0; io->soundcount = 0; EERIE_PHYSICS_BOX_Launch(io->obj, io->pos, angle, viewvector); ARX_SOUND_PlaySFX(SND_WHOOSH, &pos); io->show = SHOW_FLAG_IN_SCENE; Set_DragInter(NULL); } else { ARX_PLAYER_Remove_Invisibility(); ARX_SOUND_PlayInterface(SND_INVSTD); ARX_INTERACTIVE_Teleport(io, pos, true); io->angle.setYaw(temp.getYaw()); io->angle.setPitch(270.f - temp.getPitch()); io->angle.setRoll(temp.getRoll()); io->stopped = 0; io->show = SHOW_FLAG_IN_SCENE; io->obj->pbox->active = 0; Set_DragInter(NULL); } } GRenderer->SetCulling(Renderer::CullNone); return true; } else { CANNOT_PUT_IT_HERE=-1; } return false; }
void add(std::string key, const Anglef value) { m_maxKeyLen = std::max(m_maxKeyLen, key.length()); std::string valueStr = boost::str(boost::format("%4.2f %4.2f %4.2f") % value.getYaw() % value.getPitch() % value.getRoll()); m_elements.push_back(std::pair<std::string, std::string>(key, valueStr)); }
void CMagicMissile::Render() { Vec3f lastpos, newpos; Vec3f v; if(ulCurrentTime >= ulDuration) return; // Set Appropriate Renderstates GRenderer->SetCulling(Renderer::CullNone); GRenderer->SetRenderState(Renderer::DepthWrite, false); GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne); GRenderer->SetRenderState(Renderer::AlphaBlending, true); // Set Texture if(tex_mm) { if(spells[spellinstance].caster == 0 && cur_mr == 3) GRenderer->ResetTexture(0); else GRenderer->SetTexture(0, tex_mm); } if(bMove) fTrail = (ulCurrentTime * fOneOnDuration) * (iBezierPrecision + 2) * 5; newpos = lastpos = pathways[0].p; for(int i = 0; i < 5; i++) { int kp = i; int kpprec = (i > 0) ? kp - 1 : kp ; int kpsuiv = kp + 1 ; int kpsuivsuiv = (i < (5 - 2)) ? kpsuiv + 1 : kpsuiv; for(int toto = 1; toto < iBezierPrecision; toto++) { if(fTrail < i * iBezierPrecision + toto) break; float t = toto * fOneOnBezierPrecision; float t1 = t; float t2 = t1 * t1 ; float t3 = t2 * t1 ; float f0 = 2.f * t3 - 3.f * t2 + 1.f ; float f1 = -2.f * t3 + 3.f * t2 ; float f2 = t3 - 2.f * t2 + t1 ; float f3 = t3 - t2 ; float val = pathways[kpsuiv].p.x; float p0 = 0.5f * (val - pathways[kpprec].p.x) ; float p1 = 0.5f * (pathways[kpsuivsuiv].p.x - pathways[kp].p.x) ; v.x = f0 * pathways[kp].p.x + f1 * val + f2 * p0 + f3 * p1 ; val = pathways[kpsuiv].p.y ; p0 = 0.5f * (val - pathways[kpprec].p.y) ; p1 = 0.5f * (pathways[kpsuivsuiv].p.y - pathways[kp].p.y) ; v.y = f0 * pathways[kp].p.y + f1 * val + f2 * p0 + f3 * p1 ; val = pathways[kpsuiv].p.z ; p0 = 0.5f * (val - pathways[kpprec].p.z) ; p1 = 0.5f * (pathways[kpsuivsuiv].p.z - pathways[kp].p.z) ; v.z = f0 * pathways[kp].p.z + f1 * val + f2 * p0 + f3 * p1 ; newpos = v; if(!((fTrail - (i * iBezierPrecision + toto)) > iLength)) { float c; if(fTrail < iLength) { c = 1.0f - ((fTrail - (i * iBezierPrecision + toto)) / fTrail); } else { c = 1.0f - ((fTrail - (i * iBezierPrecision + toto)) / (float)iLength); } float fsize = c; float alpha = c - 0.2f; if(alpha < 0.2f) alpha = 0.2f; c += frand2() * 0.1f; if (c < 0) c = 0; else if (c > 1) c = 1; Color color = (fColor * (c * alpha)).to<u8>(); if(fsize < 0.5f) fsize = fsize * 2 * 3; else fsize = (1.0f - fsize + 0.5f) * 2 * (3 * 0.5f); float fs = fsize * 6 + rnd() * 0.3f; float fe = fsize * 6 + rnd() * 0.3f; Draw3DLineTex(lastpos, newpos, color, fs, fe); } Vec3f temp_vector = lastpos; lastpos = newpos; newpos = temp_vector; } } Vec3f av = newpos - lastpos; float bubu = getAngle(av.x, av.z, 0, 0); float bubu1 = getAngle(av.x, av.y, 0, 0); Vec3f stitepos = lastpos; Anglef stiteangle; stiteangle.setPitch(-degrees(bubu)); stiteangle.setYaw(0); stiteangle.setRoll(-(degrees(bubu1))); if(av.x < 0) stiteangle.setRoll(stiteangle.getRoll() - 90); if(av.x > 0) stiteangle.setRoll(stiteangle.getRoll() + 90); if(stiteangle.getRoll() < 0) stiteangle.setRoll(stiteangle.getRoll() + 360.0f); Color3f stitecolor; if(spells[spellinstance].caster == 0 && cur_mr == 3) { stitecolor.r = 1.f; stitecolor.g = 0.f; stitecolor.b = 0.2f; } else { stitecolor.r = 0.3f; stitecolor.g = 0.3f; stitecolor.b = 0.5f; } Vec3f stitescale = Vec3f_ONE; if(smissile) DrawEERIEObjEx(smissile, &stiteangle, &stitepos, &stitescale, stitecolor); eCurPos = lastpos; }
void CMagicMissile::Render() { Vec3f lastpos, newpos; Vec3f v; if(ulCurrentTime >= ulDuration) return; RenderMaterial mat; mat.setCulling(CullNone); mat.setDepthTest(true); mat.setBlendType(RenderMaterial::Additive); if(tex_mm) mat.setTexture(tex_mm); if(bMove) { float fOneOnDuration = 1.f / (float)(ulDuration); fTrail = (ulCurrentTime * fOneOnDuration) * (iBezierPrecision + 2) * 5; } newpos = lastpos = pathways[0]; for(int i = 0; i < 5; i++) { const Vec3f v1 = pathways[std::max(0, i - 1)]; const Vec3f v2 = pathways[i]; const Vec3f v3 = pathways[i + 1]; const Vec3f v4 = pathways[std::min(5, i + 2)]; for(int toto = 1; toto < iBezierPrecision; toto++) { if(fTrail < i * iBezierPrecision + toto) break; float t = toto * (1.0f / iBezierPrecision); v = glm::catmullRom(v1, v2, v3, v4, t); newpos = v; if(!((fTrail - (i * iBezierPrecision + toto)) > iLength)) { float c; if(fTrail < iLength) { c = 1.0f - ((fTrail - (i * iBezierPrecision + toto)) / fTrail); } else { c = 1.0f - ((fTrail - (i * iBezierPrecision + toto)) / (float)iLength); } float fsize = c; float alpha = c - 0.2f; if(alpha < 0.2f) alpha = 0.2f; c += Random::getf(-0.1f, 0.1f); c = glm::clamp(c, 0.f, 1.f); Color color = (m_trailColor * (c * alpha)).to<u8>(); if(fsize < 0.5f) fsize = fsize * 2 * 3; else fsize = (1.0f - fsize + 0.5f) * 2 * (3 * 0.5f); float fs = fsize * 6 + Random::getf(0.f, 0.3f); float fe = fsize * 6 + Random::getf(0.f, 0.3f); Draw3DLineTexNew(mat, lastpos, newpos, color, color, fs, fe); } Vec3f temp_vector = lastpos; lastpos = newpos; newpos = temp_vector; } } Vec3f av = newpos - lastpos; float bubu = getAngle(av.x, av.z, 0, 0); float bubu1 = getAngle(av.x, av.y, 0, 0); eCurPos = lastpos; Anglef stiteangle; stiteangle.setPitch(-glm::degrees(bubu)); stiteangle.setYaw(0); stiteangle.setRoll(-(glm::degrees(bubu1))); if(av.x < 0) stiteangle.setRoll(stiteangle.getRoll() - 90); if(av.x > 0) stiteangle.setRoll(stiteangle.getRoll() + 90); if(stiteangle.getRoll() < 0) stiteangle.setRoll(stiteangle.getRoll() + 360.0f); Draw3DObject(smissile, stiteangle, eCurPos, Vec3f_ONE, m_projectileColor, mat); }