📄 graphicscontext3d.java
字号:
doSetHiRes(hiRes); } else if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) { sendRenderMessage(false, GraphicsContext3D.SET_HI_RES, hiRes, null); } else { sendRenderMessage(true, GraphicsContext3D.SET_HI_RES, hiRes, null); } } void doSetHiRes(HiResCoord hiRes) { this.hiRes.setHiResCoord(hiRes); computeCompositeTransform(); } /** * Retrieves the current HiRes coordinate of this context. * @param hiRes a HiResCoord object that will receive the * HiRes coordinate of this context */ public void getHiRes(HiResCoord hiRes) { uHiRes.getHiResCoord(hiRes); } /** * Sets the current model transform to a copy of the specified * transform. * A BadTransformException is thrown if an attempt is made * to specify an illegal Transform3D. * @param t the new model transform * @exception BadTransformException if the transform is not affine. */ public void setModelTransform(Transform3D t) { if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active) || (Thread.currentThread() == canvas3d.screen.renderer)) { doSetModelTransform(t); } else { Transform3D uModelTransform = new Transform3D(t); //Transform3D uModelTransform = t; if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) { sendRenderMessage(false, GraphicsContext3D.SET_MODEL_TRANSFORM, uModelTransform, null); } else { sendRenderMessage(true, GraphicsContext3D.SET_MODEL_TRANSFORM, uModelTransform, null); } } } void doSetModelTransform(Transform3D t) { this.modelTransform.set(t); computeCompositeTransform(); normalTransformNeedToUpdate = true; } /** * Multiplies the current model transform by the specified * transform and stores the result back into the current * transform. The specified transformation must be affine. * @param t the model transform to be concatenated with the * current model transform * @exception BadTransformException if the transform is not affine. */ public void multiplyModelTransform(Transform3D t) { if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active) || (Thread.currentThread() == canvas3d.screen.renderer)) { doMultiplyModelTransform(t); } else { Transform3D tt = new Transform3D(t); if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) { sendRenderMessage(false, GraphicsContext3D.MULTIPLY_MODEL_TRANSFORM, tt, null); } else { sendRenderMessage(true, GraphicsContext3D.MULTIPLY_MODEL_TRANSFORM, tt, null); } } } void doMultiplyModelTransform(Transform3D t) { this.modelTransform.mul(t); computeCompositeTransform(); normalTransformNeedToUpdate = true; } /** * Retrieves the current model transform. * @param t the model transform that will receive the current * model transform */ public void getModelTransform(Transform3D t) { t.set(modelTransform); } /** * Replaces the specified sound with the sound provided. * The graphics context stores a reference to each sound * object in the list of sounds. This means that the * application may modify the sound attributes for * any of the sounds by using the appropriate methods on * that Sound node object. * @param sound the new sound * @param index which sound to replace * @exception IllegalSharingException if the Sound node * is part of or is subsequently made part of a live scene graph. * @exception NullPointerException if the Sound object is null. */ public void setSound(Sound sound, int index) { if (sound == null) { throw new NullPointerException(J3dI18N.getString("GraphicsContext3D17")); } if (sound.isLive()) { throw new IllegalSharingException(J3dI18N.getString("GraphicsContext3D23")); } uSounds.setElementAt(sound, index); if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active) || (Thread.currentThread() == canvas3d.screen.renderer)) { doSetSound(sound, index); } else if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) { sendRenderMessage(false, GraphicsContext3D.SET_SOUND, sound, new Integer(index)); } else { sendRenderMessage(true, GraphicsContext3D.SET_SOUND, sound, new Integer(index)); } } void doSetSound(Sound sound, int index) { Sound oldSound; oldSound = (Sound)(this.sounds.elementAt(index)); ((SoundRetained)sound.retained).setInImmCtx(true); if (oldSound != null) { ((SoundRetained)oldSound.retained).setInImmCtx(false); } ((SoundRetained)sound.retained).setInImmCtx(true); updateSoundState((SoundRetained)(sound.retained)); this.sounds.setElementAt(sound, index); this.soundsChanged = true; sendSoundMessage(GraphicsContext3D.SET_SOUND, sound, oldSound); } /** * Inserts the specified sound at the specified index location. * Inserting a sound to the list of sounds implicitly starts the * sound playing. Once a sound is finished playing, it can be * restarted by setting the sound's enable flag to true. * The scheduling region of all sounds in the list is ignored * for immediate-mode rendering. * @param sound the new sound * @param index at which location to insert * @exception IllegalSharingException if the Sound node * is part or is subsequently made part of a live scene graph. * @exception NullPointerException if the Sound object is null. */ public void insertSound(Sound sound, int index) { if (sound == null) { throw new NullPointerException(J3dI18N.getString("GraphicsContext3D17")); } if (sound.isLive()) { throw new IllegalSharingException(J3dI18N.getString("GraphicsContext3D23")); } uSounds.insertElementAt(sound, index); if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active) || (Thread.currentThread() == canvas3d.screen.renderer)) { doInsertSound(sound, index); } else if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) { sendRenderMessage(false, GraphicsContext3D.INSERT_SOUND, sound, new Integer(index)); } else { sendRenderMessage(true, GraphicsContext3D.INSERT_SOUND, sound, new Integer(index)); } } void doInsertSound(Sound sound, int index) { updateSoundState((SoundRetained)sound.retained); this.sounds.insertElementAt(sound, index); this.soundsChanged = true; sendSoundMessage(GraphicsContext3D.INSERT_SOUND, sound, null); } /** * Removes the sound at the specified index location. * @param index which sound to remove */ public void removeSound(int index) { uSounds.removeElementAt(index); if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active) || (Thread.currentThread() == canvas3d.screen.renderer)) { doRemoveSound(index); } else if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) { sendRenderMessage(false, GraphicsContext3D.REMOVE_SOUND, new Integer(index), null); } else { sendRenderMessage(true, GraphicsContext3D.REMOVE_SOUND, new Integer(index), null); } } void doRemoveSound(int index) { Sound sound = (Sound)(this.sounds.elementAt(index)); SoundScheduler soundScheduler = getSoundScheduler(); ((SoundRetained)(sound.retained)).setInImmCtx(false); this.sounds.removeElementAt(index); this.soundsChanged = true; // stop sound if playing on audioDevice sendSoundMessage(GraphicsContext3D.REMOVE_SOUND, null, sound); } /** * Retrieves the index selected sound. * @param index which sound to return * @return the sound at location index */ public Sound getSound(int index) { Sound sound = (Sound)(uSounds.elementAt(index)); return sound; } /** * Retrieves the enumeration object of all the sounds. * @return the enumeration object of all the sounds */ public Enumeration getAllSounds() { return uSounds.elements(); } /** * Appends the specified sound to this graphics context's list of sounds. * Adding a sound to the list of sounds implicitly starts the * sound playing. Once a sound is finished playing, it can be * restarted by setting the sound's enable flag to true. * The scheduling region of all sounds in the list is ignored * for immediate-mode rendering. * @param sound the sound to add * @exception IllegalSharingException if the Sound node * is part of or is subsequently made part of a live scene graph. * @exception NullPointerException if the Sound object is null. */ public void addSound(Sound sound) { if (sound == null) { throw new NullPointerException(J3dI18N.getString("GraphicsContext3D17")); } if (sound.isLive()) { throw new IllegalSharingException(J3dI18N.getString("GraphicsContext3D23")); } uSounds.addElement(sound); if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active) || (Thread.currentThread() == canvas3d.screen.renderer)) { doAddSound(sound); } else if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) { sendRenderMessage(false, GraphicsContext3D.ADD_SOUND, sound, null); } else { sendRenderMessage(true, GraphicsContext3D.ADD_SOUND, sound, null); } } void doAddSound(Sound sound) { ((SoundRetained)(sound.retained)).setInImmCtx(true); updateSoundState((SoundRetained)(sound.retained)); this.sounds.addElement(sound); this.soundsChanged = true; sendSoundMessage(GraphicsContext3D.ADD_SOUND, sound, null); } /** * Retrieves the current number of sounds in this graphics context. * @return the current number of sounds */ public int numSounds() { return uSounds.size(); } SoundScheduler getSoundScheduler() { if (canvas3d != null && canvas3d.view != null) return canvas3d.view.soundScheduler; // could be null as well else return (SoundScheduler)null; } void updateSoundState(SoundRetained sound) { View view = null; if (canvas3d != null) view = canvas3d.view; // Make sure that: // . Current view is not null // . The sound scheduler running (reference to it is not null) if (view != null) { SoundScheduler soundScheduler = getSoundScheduler(); if (soundScheduler == null) { // XXXX: Re-implement // start up SoundScheduler since it hasn't already been started } } // Update sound fields related to transforms if (sound instanceof ConeSoundRetained) { ConeSoundRetained cs = (ConeSoundRetained) sound; this.modelTransform.transform(cs.direction, cs.xformDirection); cs.xformDirection.normalize(); this.modelTransform.transform(cs.position, cs.xformPosition); // XXXX (Question) Is drawTranform equivalent to Vworld-to-Local? cs.trans.setWithLock(drawTransform); } else if (sound instanceof PointSoundRetained) { PointSoundRetained ps = (PointSoundRetained) sound; this.modelTransform.transform(ps.position, ps.xformPosition); // XXXX (Question) Is drawTranform equivalent to Vworld-to-Local? ps.trans.setWithLock(drawTransform); } } /** * Retrieves the sound playing flag. * @param index which sound * @return flag denoting if sound is currently playing */ public boolean isSoundPlaying(int index) { Sound sound; // uSounds isPlaying field is NOT updated, sounds elements are used sound = (Sound)(this.sounds.elementAt(index)); return sound.isPlaying(); } /** * Sets the current AuralAttributes object to the specified * AuralAttributes component object. * This means that the application may modify individual * audio attributes by using the appropriate methods in * the Aural-Attributes object. * @param attributes the new AuralAttributes object */ public void setAuralAttributes(AuralAttributes attributes) { uAuralAttributes = attributes; if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active) || (Thread.currentThread() == canvas3d.screen.renderer)) { doSetAuralAttributes(attributes); } else if (Thread.currentThread() == canvas3d.view.universe.behaviorScheduler) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -