void GfxBody::setAllBonesManuallyControlled (bool v) { if (dead) THROW_DEAD(className); for (unsigned i=0 ; i<manualBones.size() ; ++i) { manualBones[i] = v; } updateBones(); }
void AudioBody::setVelocity (const Vector3& v) { if (destroyed) THROW_DEAD(className); if (ambient) return; velocity = v; alSource3f(alSourceLeft, AL_VELOCITY, v.x, v.y, v.z); alSource3f(alSourceRight, AL_VELOCITY, v.x, v.y, v.z); }
void AudioBody::destroy (void) { if (destroyed) THROW_DEAD(className); destroyed = true; resource->unregisterReloadWatcher(this); alDeleteSources(1, &alSourceLeft); alDeleteSources(1, &alSourceRight); resource = nullptr; }
void GfxBody::checkBone (unsigned n) const { if (dead) THROW_DEAD(className); if (manualBones.size()==0) GRIT_EXCEPT("GfxBody has no skeleton"); if (n >= manualBones.size()) { std::stringstream ss; ss << "Bone " << n << " out of range [0," << manualBones.size() << ")"; GRIT_EXCEPT(ss.str()); } }
void GfxBody::setFirstPerson (bool v) { if (dead) THROW_DEAD(className); if (firstPerson == v) return; firstPerson = v; if (firstPerson) { first_person_bodies.insert(this); } else { first_person_bodies.erase(this); } }
void AudioBody::updatePositions (void) { if (destroyed) THROW_DEAD(className); if (ambient) return; // put them on top of each other if not stereo float off = resource->getStereo() ? separation/2 : 0; Vector3 v_l = position + orientation * Vector3(-off,0,0); Vector3 v_r = position + orientation * Vector3( off,0,0); alSource3f(alSourceLeft, AL_POSITION, v_l.x, v_l.y, v_l.z); alSource3f(alSourceRight, AL_POSITION, v_r.x, v_r.y, v_r.z); }
std::vector<std::string> GfxBody::getAnimationNames (void) { std::vector<std::string> r; if (dead) THROW_DEAD(className); if (skeleton == NULL) GRIT_EXCEPT("GfxBody has no skeleton"); Ogre::AnimationStateIterator it = animationState.getAnimationStateIterator(); while (it.hasMoreElements()) r.push_back(it.getNext()->getAnimationName()); return r; }
void GfxLight::update (const Vector3 &cam_pos) { if (dead) THROW_DEAD(className); light->setPosition(to_ogre(getWorldTransform().pos)); light->setDirection(to_ogre(getWorldTransform().removeTranslation()*Vector3(0,1,0))); corona->pos = getWorldTransform() * coronaLocalPos; Vector3 col = enabled ? fade * coronaColour : Vector3(0,0,0); corona->dimensions = Vector3(coronaSize, coronaSize, coronaSize); Vector3 light_dir_ws = (cam_pos - getWorldTransform().pos).normalisedCopy(); Vector3 light_aim_ws_ = getWorldTransform().removeTranslation() * Vector3(0,1,0); float angle = light_aim_ws_.dot(light_dir_ws); float inner = gritcos(coronaInnerAngle); float outer = gritcos(coronaOuterAngle); if (outer != inner) { float occlusion = std::min(std::max((angle-inner)/(outer-inner), 0.0f), 1.0f); col *= (1-occlusion); } corona->diffuse = Vector3(0, 0, 0); corona->emissive = col; }
void AudioBody::reinitialise (void) { if (destroyed) THROW_DEAD(className); alSourcei(alSourceLeft, AL_BUFFER, AL_NONE); alSourcei(alSourceRight, AL_BUFFER, AL_NONE); if (!resource->isLoaded()) { CERR << "Cannot create an AudioBody for an unloaded audio resource: " << resource->getName() << std::endl; return; } if (ambient) { // will be mono or stereo, whatever the wav file was alSourcei(alSourceLeft, AL_BUFFER, resource->getALBufferAll()); } else { // get the two channels separate for two separate sources alSourcei(alSourceLeft, AL_BUFFER, resource->getALBufferLeft()); if (resource->getStereo()) { alSourcei(alSourceRight, AL_BUFFER, resource->getALBufferLeft()); } } }
Degree GfxLight::getCoronaOuterAngle (void) { if (dead) THROW_DEAD(className); return coronaOuterAngle; }
void GfxLight::setOuterAngle (Degree v) { if (dead) THROW_DEAD(className); light->setSpotlightOuterAngle(to_ogre(v)); }
Degree GfxLight::getOuterAngle (void) { if (dead) THROW_DEAD(className); return from_ogre(light->getSpotlightOuterAngle()); }
void GfxLight::setRange (float v) { if (dead) THROW_DEAD(className); light->setAttenuation(v, 0, 0, 0); }
float GfxLight::getCoronaSize (void) { if (dead) THROW_DEAD(className); return coronaSize; }
void GfxLight::setFade (float f) { if (dead) THROW_DEAD(className); fade = f; updateVisibility(); }
void GfxLight::setEnabled (bool v) { if (dead) THROW_DEAD(className); enabled = v; updateVisibility(); }
Vector3 GfxLight::getSpecularColour (void) { if (dead) THROW_DEAD(className); return specular; }
Vector3 GfxLight::getCoronaColour (void) { if (dead) THROW_DEAD(className); return coronaColour; }
void GfxLight::setCoronaColour (const Vector3 &v) { if (dead) THROW_DEAD(className); coronaColour = v; }
void GfxLight::setCoronaLocalPosition (const Vector3 &v) { if (dead) THROW_DEAD(className); coronaLocalPos = v; }
Vector3 GfxLight::getCoronaLocalPosition (void) { if (dead) THROW_DEAD(className); return coronaLocalPos; }
void GfxLight::setCoronaSize (float v) { if (dead) THROW_DEAD(className); coronaSize = v; }
void GfxLight::setCoronaOuterAngle (Degree v) { if (dead) THROW_DEAD(className); coronaOuterAngle = v; }
void GfxLight::setDiffuseColour (const Vector3 &v) { if (dead) THROW_DEAD(className); diffuse = v; updateVisibility(); }
bool GfxLight::isEnabled (void) { if (dead) THROW_DEAD(className); return enabled; }
void GfxLight::setSpecularColour (const Vector3 &v) { if (dead) THROW_DEAD(className); specular = v; updateVisibility(); }
float GfxLight::getFade (void) { if (dead) THROW_DEAD(className); return fade; }
float GfxLight::getRange (void) { if (dead) THROW_DEAD(className); return light->getAttenuationRange(); }
Vector3 GfxLight::getDiffuseColour (void) { if (dead) THROW_DEAD(className); return diffuse; }
void AudioBody::stop (void) { if (destroyed) THROW_DEAD(className); alSourceStop(alSourceLeft); alSourceStop(alSourceRight); }