📄 skeletalanimation.java
字号:
/* Ogre4J
Copyright (C) 2002 macross
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.ogre4j.demo;
import org.ogre4j.AnimationState;
import org.ogre4j.ColourValue;
import org.ogre4j.Entity;
import org.ogre4j.Light;
import org.ogre4j.Root;
import org.ogre4j.SceneNode;
import org.ogre4j.event.FrameEvent;
import org.ogre4j.Plane;
import org.ogre4j.MeshManager;
import org.ogre4j.math.Vector3;
/**
* SkeletalAnimation
* This is the port of OGRE's Skeletal Animation Demo to Ogre4J
*
* Config Sheet is an additional Ogre4J Feature.
* You can switch to the config window using Alt+TAB
* Due some problems with focus that I wasn't able to figure out till now
* it is not recommended to switch back to OGRE Window with Mouse.
* Till the problems are fixed, use for switching back again Alt+TAB
*
* @author Ivica Aracic <ivica.aracic@bytelords.de>
*/
public class SkeletalAnimation extends AbstractOgreApplication {
private AnimationState walkAnim;
private AnimationState shootAnim;
protected void createScene() {
// create scene
// Set ambient light
sceneMgr.setAmbientLight(new ColourValue(0.8f, 0.8f, 0.8f));
//sceneMgr.setFog(OgreConsts.FOG_EXP2,ColourValue.White,0.008f, 0, 250);
Entity ent = sceneMgr.createEntity("robot", "robot.mesh");
// Add entity to the root scene node
SceneNode node = sceneMgr.getRootSceneNode().createChild();
node.attachObject(ent);
MeshManager.instance().createPlane("plane01",new Plane(Vector3.UNIT_Y,0), 5000, 5000, 1, 1,true,1,1,1,Vector3.UNIT_Z,0,0,false,false);
Entity pln = sceneMgr.createEntity("plane","plane01");
pln.setMaterialName("Examples/TextureEffect4");
SceneNode plnnode = sceneMgr.getRootSceneNode().createChild();
plnnode.attachObject(pln);
walkAnim = ent.getAnimationState("Walk");
walkAnim.setEnabled(true);
walkAnim.setWeight(0.8f);
shootAnim = ent.getAnimationState("Shoot");
shootAnim.setEnabled(true);
shootAnim.setWeight(1.2f);
ent.getMesh().getSkeleton().setBlendMode(1);
// Give it a little ambience with lights
Light l1;
l1 = sceneMgr.createLight("BlueLight");
l1.setPosition(-200,-80,-100);
l1.setDiffuseColour(0.7f, 0.7f, 1.0f);
Light l2;
l2 = sceneMgr.createLight("GreenLight");
l2.setPosition(0,0,-100);
l2.setDiffuseColour(0.7f, 1.0f, 0.7f);
// Position the camera
camera.setPosition(150,70,100);
camera.lookAt(-50,50,0);
configSheet.addBean(l1.getName(), l1);
configSheet.addBean(l2.getName(), l2);
configSheet.addBean("Node", node);
configSheet.setVisible(false);
}
public void destroyScene() {
}
// frame listener
public void frameStarted(FrameEvent e) {
walkAnim.addTime(e.getTimeSinceLastFrame());
shootAnim.addTime(0.75f*e.getTimeSinceLastFrame());
}
public void frameEnded(FrameEvent e) {
}
//===================================================================
public static void main(String[] args) {
Root.instance().run( new SkeletalAnimation() );
// in order to close the config window
System.exit(0);
}
//===================================================================
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -