forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
AvatarGraphic.java
1 package mygame;
2 
3 import com.jme3.animation.AnimChannel;
4 import com.jme3.animation.AnimControl;
5 import com.jme3.asset.AssetManager;
6 import com.jme3.math.Vector3f;
7 import com.jme3.scene.Node;
8 
13 public class AvatarGraphic {
14  public double x;
15  public double y;
16  public int comtree;
17  public int numVis;
18  public int numNear;
19  public int id;
20  public String fAdr;
21  public Vector3f dir;
22  public Node user;
23  public AnimControl control;
24  public AnimChannel channel;
25  //gets information and stores it; attached the node to the scene
26  public AvatarGraphic(AvatarStatus as, AssetManager am, Node rootNode) {
27  double degreeDir = as.dir;
28  this.x = as.x;
29  this.y = as.y;
30  this.id = as.id;
31  this.fAdr = ((id >> 16) & 0xffff) + "." + (id & 0xffff);
32  this.numNear = as.numNear;
33  this.numVis = as.numVisible;
34  this.dir = new Vector3f((float) Math.sin(degreeDir*Math.PI/180),0f,(float)Math.cos(degreeDir*Math.PI/180));
35  this.user = (Node) am.loadModel("Models/Oto.j3o");
36  //now that we have data, update how the avatar is shown.
37  user.lookAt(user.getLocalTranslation().add(dir), new Vector3f(0,1,0));
38  user.setLocalTranslation((float) x,9.5f,(float) y);
39  user.setLocalScale(2f);
40  rootNode.attachChild(user);
41  control = user.getControl(AnimControl.class);
42  channel = control.createChannel();
43  channel.setAnim("Walk");
44  }
45  public void remove(Node rootNode) {
46  rootNode.detachChild(user);
47  }
48  public void update(AvatarStatus as) {
49  double degreeDir = as.dir;
50  this.x = as.x;
51  this.y = as.y;
52  this.numNear = as.numNear;
53  this.numVis = as.numVisible;
54  this.dir = new Vector3f((float) Math.sin(degreeDir*Math.PI/180),0f,(float)Math.cos(degreeDir*Math.PI/180));
55 
56  //now that we have data, update how the avatar is shown.
57  //TODO: this is cheating, need to use dir instead
58  user.lookAt(new Vector3f((float)this.x,9.5f,(float)this.y), new Vector3f(0,1,0));
59  user.setLocalTranslation(new Vector3f((float) this.x,9.5f,(float) this.y));
60  //user.lookAt(user.getWorldTranslation().add(dir), new Vector3f(0,1,0));
61  }
62 }