void AUEditWindow::SetUnitToDisplay (AudioUnit editUnit, ComponentDescription& inDesc) { CloseView(); mEditUnit = editUnit; Component editComp = FindNextComponent(NULL, &inDesc); verify_noerr(OpenAComponent(editComp, &mEditView)); ControlRef rootControl; verify_noerr(GetRootControl(mWindow, &rootControl)); Rect r; ControlRef viewPane; GetControlBounds(rootControl, &r); Float32Point location = { kOffsetForAUView_X, kOffsetForAUView_Y }; Float32Point size = { Float32(r.right), Float32(r.bottom) }; verify_noerr(AudioUnitCarbonViewCreate(mEditView, mEditUnit, mWindow, rootControl, &location, &size, &viewPane)); AudioUnitCarbonViewSetEventListener(mEditView, EventListener, this); GetControlBounds(viewPane, &r); size.x = r.right-r.left + kOffsetForAUView_X; size.y = r.bottom-r.top + kOffsetForAUView_Y; Rect r2; GetControlBounds (mResizeableControl->MacControl(), &r2); if ((r.bottom - r.top) < (r2.bottom - r2.top + 20)) size.y = r2.bottom + 20; SetSize(size); }
AUEditWindow::AUEditWindow(XController *owner, IBNibRef nibRef, CFStringRef name, AudioUnit editUnit, ComponentDescription inCompDesc ) : XWindow(owner, nibRef, name), mEditUnit(editUnit) { Component editComp = FindNextComponent(NULL, &inCompDesc); verify_noerr(OpenAComponent(editComp, &mEditView)); ControlRef rootControl; verify_noerr(GetRootControl(mWindow, &rootControl)); ControlRef customControl = 0; ControlID controlID; controlID.signature = 'cust'; controlID.id = 1000; GetControlByID( mWindow, &controlID, &customControl ); ControlRef ourControl = customControl ? customControl : rootControl; Rect r = {0,0,400,400}; ControlRef viewPane; if(customControl) GetControlBounds(ourControl, &r); Float32Point location = { r.left, r.top }; Float32Point size = { Float32(r.right - r.left ), Float32(r.bottom - r.top ) }; verify_noerr(AudioUnitCarbonViewCreate(mEditView, mEditUnit, mWindow, ourControl, &location, &size, &viewPane)); GetControlBounds(viewPane, &r); size.x = r.right-r.left; size.y = r.bottom-r.top; if(!customControl) SetSize(size); Show(); }
AUEditWindow::AUEditWindow(XController *owner, IBNibRef nibRef, CFStringRef name, AudioUnit editUnit, bool forceGeneric) : XWindow(owner, nibRef, name), mEditUnit(editUnit) { OSStatus err; ComponentDescription editorComponentDesc; // set up to use generic UI component editorComponentDesc.componentType = kAudioUnitCarbonViewComponentType; editorComponentDesc.componentSubType = 'gnrc'; editorComponentDesc.componentManufacturer = 'appl'; editorComponentDesc.componentFlags = 0; editorComponentDesc.componentFlagsMask = 0; if (!forceGeneric) { // ask the AU for its first editor component UInt32 propertySize; err = AudioUnitGetPropertyInfo(editUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global, 0, &propertySize, NULL); if (!err) { int nEditors = propertySize / sizeof(ComponentDescription); ComponentDescription *editors = new ComponentDescription[nEditors]; err = AudioUnitGetProperty(editUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global, 0, editors, &propertySize); if (!err) // just pick the first one for now editorComponentDesc = editors[0]; delete[] editors; } } Component editComp = FindNextComponent(NULL, &editorComponentDesc); verify_noerr(OpenAComponent(editComp, &mEditView)); ControlRef rootControl; verify_noerr(GetRootControl(mWindow, &rootControl)); Rect r; ControlRef viewPane; GetControlBounds(rootControl, &r); Float32Point location = { 0., 0. }; Float32Point size = { Float32(r.right), Float32(r.bottom) }; verify_noerr(AudioUnitCarbonViewCreate(mEditView, mEditUnit, mWindow, rootControl, &location, &size, &viewPane)); AudioUnitCarbonViewSetEventListener(mEditView, EventListener, this); GetControlBounds(viewPane, &r); size.x = r.right-r.left; size.y = r.bottom-r.top; SetSize(size); Show(); /* EventLoopTimerRef timer; RequireNoErr( InstallEventLoopTimer( GetMainEventLoop(), 5., 0., TimerProc, this, &timer));*/ }
void Sprite::render(Renderer &renderer) const { if (!visible) { return; } if (isNoDepth()) { renderer.enableDepthTest(false); } if (isTransparent()) { renderer.setBlendFunc(blendFunc); } Int32 textureIndex = animation[frame]; Material material(texture, Color(255, 255, 255, Uint8(255 * alpha)), !isTransparent()); bool rotated = zRotation != 0.0; if (rotated) { Matrix rotate = Matrix::rotateAroundPoint(zRotation, Vector::UNIT_Z, position + rotationCentre); renderer.setModelMatrix(rotate); } bool reversed = (orientation == Orientation::Right); Vector texturePos = Vector(reversed ? 1.0f : 0.0f, 1.0f, Float32(textureIndex)); Vector textureSize = Vector(reversed ? -1.0f : 1.0f, -1.0f); renderer.quadXY(Vector(position.x, position.y, z), size, texturePos, textureSize, material); if (rotated) { renderer.setModelMatrix(Matrix::IDENTITY); } if (isNoDepth()) { renderer.enableDepthTest(true); } }
void MinusLife::onApply(Player& player, World& world, Int32 duration) const { Int32 hit = (Int32(D6_MAX_LIFE) / 7) + rand() % (Int32(D6_MAX_LIFE) / 2); if (player.hit(Float32(hit))) { player.playSound(PlayerSounds::Type::WasKilled); } world.getMessageQueue().add(player, Format("Life -{0}") << hit); }
dmz::Boolean dmz::AudioModuleFMOD::update_sound ( const Handle InstanceHandle, const SoundAttributes &Attributes) { Boolean result (False); if (_system) { String errorHeader; InstanceStruct *instance = _instanceTable.lookup (InstanceHandle); if (instance && instance->channel) { FMOD_RESULT fmodResult (FMOD_OK); fmodResult = instance->channel->setVolume ( Float32 (Attributes.get_gain_scale())); _error_check (errorHeader, fmodResult); // Set pitch/frequency with scale value fmodResult = instance->channel->setFrequency ( Float32 (Attributes.get_pitch_scale() * instance->defaultFrequency)); _error_check (errorHeader, fmodResult); // Set 3D sound position Vector pos, vel; Attributes.get_position (pos); Attributes.get_velocity (vel); FMOD_VECTOR posVal = { Float32 (pos.get_x ()), Float32 (pos.get_y ()), Float32 (pos.get_z ())}; FMOD_VECTOR velVal = { Float32 (vel.get_x ()), Float32 (vel.get_y ()), Float32 (vel.get_z ())}; fmodResult = instance->channel->set3DAttributes(&posVal, &velVal); _error_check (errorHeader, fmodResult); result = True; } } return result; }
void AudioMixerAudioNode::setVolume(float volume, int bus) { if (volume < 0) m_volume = 0; else if (volume > 1) m_volume = 1; else m_volume = volume; if (m_audioUnit){ // Float32 db = Float32(volume);//Float32(20.0 * log10(volume)); // convert to db Float32 db = Float32(volume); OSStatus err = AudioUnitSetParameter(m_audioUnit, kStereoMixerParam_Volume, kAudioUnitScope_Input, bus, db, 0); BACKEND_ASSERT2(err == noErr, "Could not set volume on audio mixer node.", NORMAL_ERROR) } }
void LyingWeapon::render(Renderer &renderer) const { Vector pos = getSpritePosition(); Material material = Material::makeMaskedTexture(weapon.getBonusTexture()); renderer.quadXY(pos, Vector(1.0f, 1.0f), Vector(0.1f, 0.9f, Float32(weapon.getBonusTextureIndex())), Vector(0.8f, -0.8f), material); }
void Bonus::render(Renderer &renderer, Texture texture) const { Vector pos = getSpritePosition(); Material material = Material::makeMaskedTexture(texture); renderer.quadXY(pos, Vector(1.0f, 1.0f), Vector(0.1f, 0.9f, Float32(textureIndex)), Vector(0.8f, -0.8f), material); }
dmz::Boolean dmz::AudioModuleFMOD::set_listener ( const Handle ListenerHandle, const Vector &Position, const Matrix &Orientation, const Vector &Velocity) { Boolean result (False); if (_system) { ListenerStruct *listener = _listenerHandleTable.lookup (ListenerHandle); if (listener) { listener->orientation = Orientation; listener->position = Position; listener->velocity = Velocity; Vector lookVector (0.0, 0.0, -1.0); Vector upVector (0.0, 1.0, 0.0); Orientation.transform_vector (lookVector); Orientation.transform_vector (upVector); FMOD_VECTOR fmodLookVector = { Float32 (lookVector.get_x ()), Float32 (lookVector.get_y ()), Float32 (lookVector.get_z ())}; FMOD_VECTOR fmodUpVector = { Float32 (upVector.get_x ()), Float32 (upVector.get_y ()), Float32 (upVector.get_z ())}; FMOD_VECTOR fmodPosition = { Float32 (Position.get_x ()), Float32 (Position.get_y ()), Float32 (Position.get_z ())}; FMOD_VECTOR vel = { Float32 (Velocity.get_x ()), Float32 (Velocity.get_y ()), Float32 (Velocity.get_z ())}; FMOD_RESULT fmodResult = _system->set3DListenerAttributes ( listener->index, &fmodPosition, &vel, &fmodLookVector, &fmodUpVector); if (_error_check ("Setting 3D Attributes", fmodResult)) { result = True; } } } return result; }
void dmz::RenderPluginWavesOSG::_init (Config &local) { activate_object_attribute ( config_to_string ("wave-time.attribute", local, "DMZ_Wave_State_Time_Seed"), ObjectTimeStampMask); _waveSpeedAttributeHandle = activate_object_attribute ( config_to_string ("wave-speed.attribute", local, "DMZ_Wave_State_Speed"), ObjectScalarMask); _waveAmplitudeAttributeHandle = activate_object_attribute ( config_to_string ("wave-amplitude.attribute", local, "DMZ_Wave_State_Amplitude"), ObjectScalarMask); _waveNumberAttributeHandle = activate_object_attribute ( config_to_string ("wave-number.attribute", local, "DMZ_Wave_State_Number"), ObjectScalarMask); _imageResource = config_to_string ("image.resource", local, "water"); _tileCountX = config_to_int32 ("count.x", local, _tileCountX); _tileCountY = config_to_int32 ("count.y", local, _tileCountY); if (_tileCountX < 1) { _log.error << "Tile count in the X axis is: " << _tileCountX << " Value must be greater than zero. Setting to 1." << endl; _tileCountX = 1; } if (_tileCountY < 1) { _log.error << "Tile count in the Y axis is: " << _tileCountY << " Value must be greater than zero. Setting to 1." << endl; _tileCountY = 1; } _minGrid = config_to_float64 ("grid.min", local, _minGrid); _maxGrid = config_to_float64 ("grid.max", local, _maxGrid); if (_minGrid >= _maxGrid) { _log.error << "Minimum grid value must be less than the maximum grid value." << endl; _maxGrid = _minGrid + 1.0f; } _tileSizeX = (_maxGrid - _minGrid) / Float32 (_tileCountX); _tileSizeY = (_maxGrid - _minGrid) / Float32 (_tileCountY); Float32 &texA = (_tileCountY > _tileCountX ? _texFactorX : _texFactorY); Float32 &texB = (_tileCountY > _tileCountX ? _texFactorY : _texFactorX); texA = 1.0f; texB = ((_tileCountY > _tileCountX) ? (Float32 (_tileCountY) / Float32 (_tileCountX)) : (Float32 (_tileCountY) / Float32 (_tileCountX))); const Float32 FloorValue = floor (texB); if ((texB - FloorValue) > 0.5f) { texB = FloorValue + 1; } else { texB = FloorValue; } }
// RenderPluginWavesOSG Interface void dmz::RenderPluginWavesOSG::_create_grid () { const String FoundFile (_rc.find_file (_imageResource)); osg::ref_ptr<osg::Image> img = (FoundFile ? osgDB::readImageFile (FoundFile.get_buffer ()) : 0); if (img.valid () && _core) { const Int32 ArraySize ((_tileCountX + 1) * (_tileCountY + 1)); if (!_gridPoints) { _gridPoints = new VertexStruct[ArraySize]; } osg::Geode* geode = new osg::Geode (); if (_gridPoints && geode) { for (Int32 ix = 0; ix <= _tileCountX; ix++) { const Float32 TheX ((Float32 (ix) * _tileSizeX) + _minGrid); for (Int32 jy = 0; jy <= _tileCountY; jy++) { const Float32 TheY ((Float32 (jy) * _tileSizeY) + _minGrid); const Int32 Offset ((ix * (_tileCountY + 1)) + jy); _gridPoints[Offset].x = TheX; _gridPoints[Offset].y = TheY; } } _surface = new osg::Geometry; osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array; normals->push_back (osg::Vec3 (0.0f, 1.0f, 0.0f)); _surface->setNormalArray (normals.get ()); _surface->setNormalBinding (osg::Geometry::BIND_OVERALL); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; //colors->push_back (osg::Vec4 (0.0f, 0.5f, 1.0f, 0.8f)); colors->push_back (osg::Vec4 (1.0f, 1.0f, 1.0f, 0.65f)); _surface->setColorArray (colors.get ()); _surface->setColorBinding (osg::Geometry::BIND_OVERALL); osg::StateSet *stateset = _surface->getOrCreateStateSet (); stateset->setMode (GL_BLEND, osg::StateAttribute::ON); stateset->setRenderingHint (osg::StateSet::TRANSPARENT_BIN); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; osg::ref_ptr<osg::Vec2Array> tcoords = new osg::Vec2Array; osg::ref_ptr<osg::Texture2D> tex = new osg::Texture2D (img.get ()); tex->setWrap (osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT); tex->setWrap (osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT); stateset->setTextureAttributeAndModes (0, tex.get (), osg::StateAttribute::ON); stateset->setAttributeAndModes (new osg::CullFace (osg::CullFace::BACK)); unsigned int count (0); for (Int32 ix = 0; ix < _tileCountX; ix++) { for (Int32 jy = 0; jy < _tileCountY; jy++) { VertexStruct *vertex (0); float height = 0.0f; vertex = &(_gridPoints[(ix * (_tileCountY + 1)) + jy + 1]); vertices->push_back (osg::Vec3 (vertex->x, height, vertex->y)); vertex = &(_gridPoints[((ix + 1) * (_tileCountY + 1)) + jy + 1]); vertices->push_back (osg::Vec3 (vertex->x, height, vertex->y)); vertex = &(_gridPoints[((ix + 1) * (_tileCountY + 1)) + jy]); vertices->push_back (osg::Vec3 (vertex->x, height, vertex->y)); vertex = &(_gridPoints[(ix * (_tileCountY + 1)) + jy]); vertices->push_back (osg::Vec3 (vertex->x, height, vertex->y)); tcoords->push_back (osg::Vec2 (0.0, 0.0)); tcoords->push_back (osg::Vec2 (0.0, _texFactorY)); tcoords->push_back (osg::Vec2 (_texFactorX, _texFactorY)); tcoords->push_back (osg::Vec2 (_texFactorX, 0.0)); count += 4; } } _surface->addPrimitiveSet (new osg::DrawArrays (GL_QUADS, 0, count)); _surface->setVertexArray (vertices.get ()); _surface->setTexCoordArray (0, tcoords.get ()); _surface->setUseDisplayList (false); _surface->setUseVertexBufferObjects (false); geode->addDrawable (_surface); osg::Group *s = _core->get_static_objects (); if (s) { s->addChild (geode); } else { _log.error << "Failed to add geode!" << endl; } } } }
void dmz::CyclesPluginGridOSG::_create_grid () { const String FoundFile (_rc.find_file (_imageResource)); osg::ref_ptr<osg::Image> img = (FoundFile ? osgDB::readImageFile (FoundFile.get_buffer ()) : 0); if (img.valid () && _core) { const Int32 GridSize (Int32 ((_maxGrid - _minGrid) / _tileSize)); const Int32 ArraySize ((GridSize + 1) * (GridSize + 1)); struct vertex { Float32 x, y; vertex () : x (0.0f), y (0.0f) { ; } }; vertex *gridPoints = new vertex[ArraySize]; osg::Geode* geode = new osg::Geode (); if (gridPoints && geode) { for (Int32 ix = 0; ix <= GridSize; ix++) { const Float32 TheX ((Float32 (ix) * _tileSize) + _minGrid); for (Int32 jy = 0; jy <= GridSize; jy++) { const Float32 TheY ((Float32 (jy) * _tileSize) + _minGrid); const Int32 Offset ((ix * (GridSize + 1)) + jy); gridPoints[Offset].x = TheX; gridPoints[Offset].y = TheY; } } osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back (osg::Vec3 (0.0f, 1.0f, 0.0f)); geom->setNormalArray (normals); geom->setNormalBinding (osg::Geometry::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back (osg::Vec4 (1.0f, 1.0, 1.0f, 1.0f)); geom->setColorArray (colors); geom->setColorBinding (osg::Geometry::BIND_OVERALL); osg::StateSet *stateset = geom->getOrCreateStateSet (); stateset->setMode (GL_BLEND, osg::StateAttribute::ON); osg::Vec3Array *vertices = new osg::Vec3Array; osg::Vec2Array *tcoords = new osg::Vec2Array; osg::Texture2D *tex = new osg::Texture2D (img.get ()); tex->setWrap (osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT); tex->setWrap (osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT); stateset->setTextureAttributeAndModes (0, tex, osg::StateAttribute::ON); stateset->setAttributeAndModes (new osg::CullFace (osg::CullFace::BACK)); unsigned int count (0); for (Int32 ix = 0; ix < GridSize; ix++) { for (Int32 jy = 0; jy < GridSize; jy++) { vertex *v (0); v = &(gridPoints[(ix * (GridSize + 1)) + jy + 1]); vertices->push_back (osg::Vec3 (v->x, 0.0, v->y)); v = &(gridPoints[((ix + 1) * (GridSize + 1)) + jy + 1]); vertices->push_back (osg::Vec3 (v->x, 0.0, v->y)); v = &(gridPoints[((ix + 1) * (GridSize + 1)) + jy]); vertices->push_back (osg::Vec3 (v->x, 0.0, v->y)); v = &(gridPoints[(ix * (GridSize + 1)) + jy]); vertices->push_back (osg::Vec3 (v->x, 0.0, v->y)); const float Factor (50.0); tcoords->push_back (osg::Vec2 (0.0, 0.0)); tcoords->push_back (osg::Vec2 (0.0, Factor)); tcoords->push_back (osg::Vec2 (Factor, Factor)); tcoords->push_back (osg::Vec2 (Factor, 0.0)); count += 4; } } geom->addPrimitiveSet (new osg::DrawArrays (GL_QUADS, 0, count)); geom->setVertexArray (vertices); geom->setTexCoordArray (0, tcoords); geode->addDrawable (geom); geom = new osg::Geometry; colors = new osg::Vec4Array; colors->push_back (osg::Vec4 (0.4f, 0.4f, 0.4f, 1.0f)); geom->setColorArray (colors); geom->setColorBinding (osg::Geometry::BIND_OVERALL); stateset = geom->getOrCreateStateSet (); stateset->setMode (GL_BLEND, osg::StateAttribute::ON); vertices = new osg::Vec3Array; stateset->setAttributeAndModes (new osg::CullFace (osg::CullFace::BACK)); count = 0; const Float32 WallHeight (30.0f); for (Int32 ix = 0; ix < GridSize; ix++) { vertex *v1 = &(gridPoints[ix]); vertex *v2 = &(gridPoints[ix + 1]); vertices->push_back (osg::Vec3 (v1->x, 0.0f, v2->y)); vertices->push_back (osg::Vec3 (v1->x, 0.0f, v1->y)); vertices->push_back (osg::Vec3 (v1->x, WallHeight, v1->y)); vertices->push_back (osg::Vec3 (v1->x, WallHeight, v2->y)); count += 4; v1 = &(gridPoints[ix + ((1 + GridSize) * GridSize)]); v2 = &(gridPoints[ix + ((1 + GridSize) * GridSize) + 1]); vertices->push_back (osg::Vec3 (v1->x, 0.0f, v1->y)); vertices->push_back (osg::Vec3 (v1->x, 0.0f, v2->y)); vertices->push_back (osg::Vec3 (v1->x, WallHeight, v2->y)); vertices->push_back (osg::Vec3 (v1->x, WallHeight, v1->y)); count += 4; v1 = &(gridPoints[ix * (1 + GridSize)]); v2 = &(gridPoints[(ix + 1) * (1 + GridSize)]); vertices->push_back (osg::Vec3 (v1->x, 0.0f, v1->y)); vertices->push_back (osg::Vec3 (v2->x, 0.0f, v1->y)); vertices->push_back (osg::Vec3 (v2->x, WallHeight, v1->y)); vertices->push_back (osg::Vec3 (v1->x, WallHeight, v1->y)); count += 4; v1 = &(gridPoints[(ix * (1 + GridSize)) + GridSize]); v2 = &(gridPoints[((ix + 1) * (1 + GridSize)) + GridSize]); vertices->push_back (osg::Vec3 (v2->x, 0.0f, v1->y)); vertices->push_back (osg::Vec3 (v1->x, 0.0f, v1->y)); vertices->push_back (osg::Vec3 (v1->x, WallHeight, v1->y)); vertices->push_back (osg::Vec3 (v2->x, WallHeight, v1->y)); count += 4; } geom->addPrimitiveSet (new osg::DrawArrays (GL_QUADS, 0, count)); geom->setVertexArray (vertices); geode->addDrawable (geom); osg::Group *s = _core->get_static_objects (); if (s) { s->addChild (geode); } else { _log.error << "Failed to add geode!" << endl; } delete []gridPoints; } else if (gridPoints) { delete []gridPoints; } } }