i'm currently using chasecam as my camera. I was trying to get another model to face the avatar model when it's charging, but i ended up with my window having a seizure upon runtime. The camera flickers everywhere and i'm not sure if the problem is my code or the camera. It's alot like having double vision, actually. If a screenie is needed just tell. If you need the rest of the code please tell.
public Vector3f getDirection(Vector3f a, Vector3f b){
Vector3f vec = new Vector3f();
vec.x = b.x - a.x;
vec.y = b.y - a.y;
vec.z = b.z = a.z;
return vec;
}
public void chargeTo(Node character, Timer gametime){
if (moving == false){
Quaternion roller = new Quaternion();
float xdir = character.getLocalTranslation().x-model.getLocalTranslation().x;
roller.fromAngleAxis(0*FastMath.DEG_TO_RAD , new Vector3f(0,1,0));
model.setLocalRotation(roller);
final int lookup = 10;
model.setLocalScale(10f);
Quaternion q = new Quaternion();
q.lookAt(getDirection(model.getWorldTranslation(),character.getWorldTranslation()), model.getWorldTranslation());
modelMover = new SpatialTransformer(2);
modelMover.setObject(model, 0, -1);
modelMover.setObject(model, 1, -1);
final int timetaken =
(int) Math.abs(model.getLocalTranslation().x - character.getLocalTranslation().x)+
(int) Math.abs(model.getLocalTranslation().z - character.getLocalTranslation().z);
mainControl.setNewAnimationTimes(2, 14);
mainControl.setSpeed(20f);
Vector3f face = character.getLocalTranslation();
modelMover.setRotation(1, 0, model.getLocalRotation());
modelMover.setRotation(1, timetaken / 3, q);
//gametime.getTimeInSeconds()
modelMover.setPosition(0,0 ,model.getLocalTranslation());
modelMover.setPosition(0, timetaken,
new Vector3f(character.getLocalTranslation().x, character.getLocalTranslation().y,character.getLocalTranslation().z));
//System.out.println("Time: 0 to "+ timetaken+ " from "+model.getLocalTranslation().toString()+ " to "+character.getLocalTranslation().toString() );
modelMover.interpolateMissing();
modelMover.setSpeed(20f);
model.addController(modelMover);
model.addController(mainControl);
model.updateModelBound();
model.updateWorldBound();
moving = true;
}
else {
if (!(model.getLocalTranslation().equals(character.getLocalTranslation()))){
moving = false;
//System.out.println(model.getLocalRotation().toString());
//System.out.println(" from "+model.getLocalTranslation().toString()+ " to "+character.getLocalTranslation().toString() );
}
}
Yes, please do post all your code, since I spent some time trying to fill the gaps, but gave up.
well, im hungry so i just read the first part of ur code
i think the getdirection function is wrong.
public Vector3f getDirection(Vector3f a, Vector3f b){
Vector3f vec = new Vector3f();
vec.x = b.x - a.x;
vec.y = b.y - a.y;
vec.z = b.z = a.z;
return vec;
}
i think it should be like this.
public Vector3f getDirection(Vector3f a, Vector3f b) {
// You dont want to modify the original vector. it might cause some problems. so clone them
Vector3f v1 = a.clone();
Vector3f v2 = b.clone();
// Then calculate direction. The direction should be a unit vector.
Vector3f dir = v2.subtractLocal(v1).normalizeLocal();
return dir;
}
hope this helps~gtg to get some subway!!! :D
@neakor: But he is allocating a new Vector in that function… the only real difference is that you are allocating twice, and that is not necessary. Also, you normalize, and I am not sure this is intended.
duenez said:
@neakor: But he is allocating a new Vector in that function... the only real difference is that you are allocating twice, and that is not necessary. Also, you normalize, and I am not sure this is intended.
he allocates a new vector to return, but when u do b.x - a.x, u still modify the x coordinate of b.
i had a similar problem b4, and i solved it by using clone which wont modify the original vector at all.
actually, b.x - a.x does not modify either vector. These are just floats.
This is another way that works without modifying a or b.
public Vector3f getDirection(Vector3f a, Vector3f b){
Vector3f vec = new Vector3f(b);
vec.subtractLocal(a);
return vec;
}
here's the rest
i'll try out the helpful comments when i have time… well here's the code
public class helloWorldV3 extends SimpleGame
{
ChaseCamera chase;
Node myChar;
private CameraNode camNode;
private TerrainPage page;
private Skybox skybox;
private Timer gametime;
private static int shift= -7;
ooblah ooga;
KeyframeController mainControl;
protected void turn(float amount){
//Quaternion added = new Quaternion();
//added.fromAngleAxis(amountFastMath.DEG_TO_RAD, myChar.getLocalTranslation());
//added = myChar.getLocalRotation().add(added);
//myChar.setLocalRotation(added);
myChar.getLocalRotation().normalize();
myChar.getLocalRotation().y += 5f;
}
protected void simpleUpdate() {
timer.update();
//turn(180f);
System.out.println("Rotation of character" + myChar.getLocalRotation());
if (gametime != null) myChar.updateGeometricState(gametime.getTime(), false);
if (gametime != null) ooga.getModel().updateGeometricState(gametime.getTime(), false);
//if ((ooga.getModel() != null) &&(timer.getTimeInSeconds()>10)) ooga.chargeTo(myChar, gametime);
skybox.setLocalTranslation(cam.getLocation());
//System.out.println(cam.getLocation().toString());
chase.update(tpf);
float camMinHeight = page.getHeight(cam.getLocation()) + 2f;
if (!Float.isInfinite(camMinHeight) && !Float.isNaN(camMinHeight)
&& cam.getLocation().y <= camMinHeight) {
cam.getLocation().y = camMinHeight;
cam.update();
}
float characterMinHeight = page.getHeight(myChar
.getLocalTranslation())+((BoundingBox)myChar.getWorldBound()).yExtent;
if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
myChar.getLocalTranslation().y = characterMinHeight + shift;
myChar.setLocalRotation(quickRotation(-45, new Vector3f(0,1,0)));
}
checkKeys();
}
protected void simpleInitGame() {
//makes the game smoother
ooga = new ooblah(display.getRenderer().createTextureState(), "hellpig/hellpig.md3","hellpig/hellpig.jpg", 10);
ooga.setCullMode(display.getRenderer().createCullState());
rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
fpsNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
DirectionalLight dl = new DirectionalLight();
dl.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
dl.setDirection(new Vector3f(1, 0.5f, 1));
dl.setEnabled(true);
lightState.attach(dl);
setupTerrain();
setupActor();
setupCamera();
setupKeys();
mainControl.setRepeatType(Controller.RT_WRAP);
DirectionalLight dr = new DirectionalLight();
dr.setEnabled(true);
dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
dr.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
dr.setDirection(new Vector3f(0.5f, -0.5f, 0).normalizeLocal());
// makes the terrain faster my not rendering not shown triangles.
CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
cs.setEnabled(true);
rootNode.setRenderState(cs);
lightState.attach(dr);
//loads my map
Node housenode = new Node("for the houses");
Node n= getObj("houseA_mesh.obj","mtllib","mesh_houseA//");
n.setLocalScale(10f);
n.setLocalTranslation(-917,page.getHeight(-917,361),361);
housenode.attachChild(n);
Node treenode =new Node("node with all the trees.");
Node tree = getObj("broadleavedtreeC_mesh.obj","mtllib", "mesh_broadleavedtreeC//");
TriMesh[] triGroup = getMeshFromNode(tree,2);
Random r = new Random();
Float x,z;
for (int f = 0; f < 100; f++){
x=(float)(r.nextInt(1000)-1);
z = (float)(r.nextInt(400));
for (int treenum = 0; treenum < triGroup.length; treenum++){
Spatial treeChild = new SharedMesh("tree"+ f,triGroup[treenum]);
treeChild.setLocalScale(5);
treeChild.setLocalTranslation(x, page.getHeight(x,z)+14, z);
treenode.attachChild(treeChild);
}
}
rootNode.attachChild(treenode);
rootNode.attachChild(housenode);
ooga.setLocation(490, (int)page.getHeight(300,-300), -300);
rootNode.attachChild(ooga.getModel());
}
public void setupKeys(){
KeyBindingManager.getKeyBindingManager().set("attack",KeyInput.KEY_X);
KeyBindingManager.getKeyBindingManager().set("left",KeyInput.KEY_A);
KeyBindingManager.getKeyBindingManager().set("right",KeyInput.KEY_D);
KeyBindingManager.getKeyBindingManager().set("jump",KeyInput.KEY_Z);
KeyBindingManager.getKeyBindingManager().set("forward",KeyInput.KEY_W);
KeyBindingManager.getKeyBindingManager().set("check",KeyInput.KEY_A);
}
public void checkKeys(){
float angle = 0f;
Vector3f axisRotation = new Vector3f(0, 1, 0);
if (KeyBindingManager
.getKeyBindingManager()
.isValidCommand("forward", false)) {
mainControl.setNewAnimationTimes(2, 14);
mainControl.setSpeed(10f);
}
else if (KeyBindingManager
.getKeyBindingManager()
.isValidCommand("left", true)) {
angle =+ -5;
mainControl.setNewAnimationTimes(2, 14);
mainControl.setSpeed(10f);
}
else if (KeyBindingManager
.getKeyBindingManager()
.isValidCommand("right", true)) {
angle =+ 5;
mainControl.setNewAnimationTimes(2, 14);
mainControl.setSpeed(10f);
}
else if (KeyBindingManager
.getKeyBindingManager()
.isValidCommand("jump", true)) {
angle =+ 5;
mainControl.setNewAnimationTimes(169, 180);
mainControl.setSpeed(4f);
}
else if (KeyBindingManager
.getKeyBindingManager()
.isValidCommand("attack", false)) {
mainControl.setNewAnimationTimes(33, 50);
mainControl.setSpeed(6f);
}
else if (KeyBindingManager
.getKeyBindingManager()
.isValidCommand("check", false)) {
mainControl.setSpeed(4f);
mainControl.setNewAnimationTimes(52, 70);
}
}
public static void main(String[] args) {
try {
JoystickInput.setProvider(InputSystem.INPUT_SYSTEM_LWJGL);
} catch (Exception e) {
e.printStackTrace();
}
helloWorldV3 app = new helloWorldV3();
app.setDialogBehaviour(NEVER_SHOW_PROPS_DIALOG);
app.start();
}
/**
* builds the trimesh.
*
* @see com.jme.app.SimpleGame#initGame()
/
public void setupActor(){
//Box b = new Box("box", new Vector3f(0,0,0), new Vector3f(4,4,4));
//b.setModelBound(new BoundingBox());
//b.updateModelBound();
Node mainChar = getMd2("hellpig/hellpig.md3","hellpig/hellpig.jpg");
mainChar.setModelBound(new BoundingBox());
float angle = 90;
Vector3f axisRotation = new Vector3f(0, 1, 0);
mainChar.getChild(0).getLocalRotation().fromAngleAxis(angle * FastMath.DEG_TO_RAD, axisRotation);
mainControl = (KeyframeController)mainChar.getChild(0).getController(0);
mainControl.setSpeed(10f);
mainControl.setNewAnimationTimes(2, 14);
mainChar.updateModelBound();
myChar = mainChar;
myChar.setLocalScale(10f);
myChar.setLocalTranslation(500, page.getHeight(500,-300), -300);
myChar.toString();
CullState c = display.getRenderer().createCullState();
c.setCullMode(CullState.CS_FRONT);
myChar.setRenderState©;
rootNode.attachChild(myChar);
myChar.updateWorldBound();
}
public void setupCamera(){
Vector3f camerafromchar = new Vector3f();
float factor = 2f;
BoundingBox focalvol = (BoundingBox)myChar.getWorldBound();
focalvol.toString();
camerafromchar.y=focalvol.yExtentfactor;
chase = new ChaseCamera(cam,myChar);
chase.setTargetOffset(camerafromchar);
chase.setStayBehindTarget(true);
setupInput();
setupJoystick();
}
private void setupInput() {
HashMap<String, Object> handlerProps = new HashMap<String, Object>();
handlerProps.put(ThirdPersonHandler.PROP_DOGRADUAL, "true");
handlerProps.put(ThirdPersonHandler.PROP_TURNSPEED, ""+(1.5f * FastMath.PI));
handlerProps.put(ThirdPersonHandler.PROP_LOCKBACKWARDS, "false");
handlerProps.put(ThirdPersonHandler.PROP_CAMERAALIGNEDMOVE, "true");
input = new ThirdPersonHandler(myChar, cam, handlerProps);
input.setActionSpeed(100f);
}
private void setupJoystick() {
ArrayList<Joystick> joys = JoystickInput.get().findJoysticksByAxis("X Axis", "Y Axis", "Z Axis", "Z Rotation");
Joystick joy = joys.size() >= 1 ? joys.get(0) : null;
if (joy != null) {
ThirdPersonJoystickPlugin plugin = new ThirdPersonJoystickPlugin(joy, joy.findAxis("X Axis"), joy.findAxis("Y Axis"), joy.findAxis("Z Axis"), joy.findAxis("Z Rotation"));
((ThirdPersonHandler)input).setJoystickPlugin(plugin);
chase.getMouseLook().setJoystickPlugin(plugin);
}
}
public void setupTerrain(){
URL greyscale =
HelloModelLoading.class.getClassLoader().getResource(
"repository/heightmap.png"
);
System.out.println(greyscale.toString());
ImageIcon i =new ImageIcon(greyscale);
i.toString();
ImageBasedHeightMap ib=new ImageBasedHeightMap(i.getImage());
ib.setSize(513);
//sets vertical scale of terrain+
Vector3f terrainScale = new Vector3f(10,5,10);
ib.setHeightScale( 20f);
page = new TerrainPage("Terrain", 33, ib.getSize(), terrainScale,
ib.getHeightMap(), false);
page.setDetailTexture(1, 16);
TextureState pagetexstate = display.getRenderer().createTextureState();
Texture t1 = getTexture("repository/colormap.png");
t1.setApply(Texture.AM_COMBINE);
t1.setCombineFuncRGB(Texture.ACF_MODULATE);
t1.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t1.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t1.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
t1.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t1.setCombineScaleRGB(1.0f);
pagetexstate.setTexture(t1);
page.setRenderState(pagetexstate);
page.setNormalsMode(2);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(t1, 0);
Texture t2 = getTexture("jmetest/data/texture/Detail.jpg");
ts.setTexture(t2, 1);
t2.setWrap(Texture.WM_WRAP_S_WRAP_T);
t2.setApply(Texture.AM_COMBINE);
t2.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
t2.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t2.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t2.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
t2.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t2.setCombineScaleRGB(1.0f);
page.setRenderState(ts);
FogState fs = display.getRenderer().createFogState();
fs.setDensity(0.3f);
fs.setEnabled(true);
fs.setColor(ColorRGBA.darkGray);
fs.setEnd(1000);
fs.setStart(500);
fs.setDensityFunction(FogState.DF_LINEAR);
fs.setApplyFunction(FogState.AF_PER_VERTEX);
rootNode.setRenderState(fs);
createSkybox();
rootNode.attachChild(skybox);
rootNode.attachChild(page);
}
public Texture getTexture(String textureName, String folder){
URL path=
HelloModelLoading.class.getClassLoader().getResource(
"repository//"+ folder + "//"+textureName);
System.out.println(path.toString());
Texture tex =
TextureManager.loadTexture(path,
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR,
Texture.AM_BLEND, false);
return tex;
}
public Texture getTexture(String textureName){
URL path=
HelloModelLoading.class.getClassLoader().getResource(
textureName);
System.out.println(path.toString());
Texture tex =
TextureManager.loadTexture(path,
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR,
Texture.AM_BLEND, false);
return tex;
}
public void createSkybox(){
skybox = new Skybox("skybox", 500, 500, 500);
Texture north = TextureManager.loadTexture(
Lesson4.class.getClassLoader().getResource(
"jmetest/data/texture/north.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture south = TextureManager.loadTexture(
Lesson4.class.getClassLoader().getResource(
"jmetest/data/texture/south.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture east = TextureManager.loadTexture(
Lesson4.class.getClassLoader().getResource(
"jmetest/data/texture/east.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture west = TextureManager.loadTexture(
Lesson4.class.getClassLoader().getResource(
"jmetest/data/texture/west.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture up = TextureManager.loadTexture(
Lesson4.class.getClassLoader().getResource(
"jmetest/data/texture/top.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture down = TextureManager.loadTexture(
Lesson4.class.getClassLoader().getResource(
"jmetest/data/texture/bottom.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
skybox.setTexture(Skybox.NORTH, north);
skybox.setTexture(Skybox.WEST, west);
skybox.setTexture(Skybox.SOUTH, south);
skybox.setTexture(Skybox.EAST, east);
skybox.setTexture(Skybox.UP, up);
skybox.setTexture(Skybox.DOWN, down);
}
public Node getObj(String mdlName, String mtlName, String folder){
System.out.println("loading");
URL model = null;
model=HelloModelLoading.class.getClassLoader().getResource("repository//"+folder+mdlName);
System.out.println(model.toString());
FormatConverter f = new ObjToJme();
f.setProperty(mtlName, model);
ByteArrayOutputStream output=new ByteArrayOutputStream();
try {
f.convert(model.openStream(), output);
Node modelnode =(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(output.toByteArray()));
modelnode.setModelBound(new BoundingBox());
modelnode.updateModelBound();
System.out.println("got past loader…");
return modelnode;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public TriMesh[] getMeshFromNode(Node n, int end){<br />
boolean atend = false;
TriMesh[] tri = new TriMesh[end];
for(int i = 0; i< end; i++){
tri=(TriMesh)n.getChild(i);
}
return tri;
}
public Node getMd2(String path, String texPath){
URL tex = HelloModelLoading.class.getClassLoader().getResource("repository//"+texPath);
URL mdl = HelloModelLoading.class.getClassLoader().getResource("repository//"+path);
System.out.println(tex.toString());
System.out.println(mdl.toString());
Node model = null;
FormatConverter conv = new Md3ToJme();
ByteArrayOutputStream mdlFin = new ByteArrayOutputStream();
try {
conv.convert(mdl.openStream(), mdlFin);
} catch (IOException e) {
System.out.println("didn't work…");
e.printStackTrace();
}
try {
model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(mdlFin.toByteArray()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TextureState texture = display.getRenderer().createTextureState();
texture.setEnabled(true);
Texture mdlTexture= TextureManager.loadTexture(
tex,
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR);
texture.setTexture(mdlTexture);
model.setRenderState(texture);
return model;
}
public Quaternion quickRotation(int degree, Vector3f vec){
Quaternion x180 = new Quaternion();
x180.fromAngleAxis(FastMath.DEG_TO_RADdegree,vec);
return x180;
}
public Quaternion quickRotation(int degree, String axis){
Quaternion x180 = new Quaternion();
if (axis.equals("y"))
x180.fromAngleAxis(FastMath.DEG_TO_RADdegree,new Vector3f(0,1,0));
else if (axis.equals("x"))
x180.fromAngleAxis(FastMath.DEG_TO_RADdegree,new Vector3f(1,0,0));
else
x180.fromAngleAxis(FastMath.DEG_TO_RADdegree,new Vector3f(0,0,1));
return x180;
}
}
public class ooblah {
Node model;
SpatialTransformer modelMover;
KeyframeController mainControl;
boolean moving = false;
public ooblah(TextureState state, String modelpath, String texturePath, int detectRadius){
model = getMd2(modelpath, texturePath, state);
BoundingSphere temp = new BoundingSphere();
model.setLocalScale(10f);
temp.setRadius(detectRadius);
model.setModelBound(temp);
Vector3f face = model.getWorldTranslation();
System.out.println(model.getLocalRotation().toString());
mainControl = (KeyframeController)model.getChild(0).getController(0);
mainControl.setSpeed(10f);
mainControl.setNewAnimationTimes(2, 14);
model.updateModelBound();
model.setIsCollidable(true);
modelMover = new SpatialTransformer(1);
modelMover.setObject(model, 0, -1);
}
public Node getModel(){
return model;
}
public void setCullMode(CullState c){
c.setEnabled(true);
c.setCullMode(CullState.CS_FRONT);
model.setRenderState©;
}
public void setLocation(int x, int y, int z){
model.setLocalTranslation(x, y, z);
model.updateModelBound();
model.updateWorldBound();
}
public void check(Node character){
}
public void scan(){
}
public Vector3f getDirection(Vector3f a, Vector3f b){
Vector3f vec = new Vector3f();
vec.x = b.x - a.x;
vec.y = b.y - a.y;
vec.z = b.z = a.z;
return vec;
}
public void chargeTo(Node character, Timer gametime){
if (moving == false){
Quaternion roller = new Quaternion();
float xdir = character.getLocalTranslation().x-model.getLocalTranslation().x;
roller.fromAngleAxis(0*FastMath.DEG_TO_RAD , new Vector3f(0,1,0));
model.setLocalRotation(roller);
final int lookup = 10;
model.setLocalScale(10f);
Quaternion q = new Quaternion();
q.lookAt(getDirection(model.getWorldTranslation(),character.getWorldTranslation()), model.getWorldTranslation());
modelMover = new SpatialTransformer(2);
modelMover.setObject(model, 0, -1);
modelMover.setObject(model, 1, -1);
final int timetaken =
(int) Math.abs(model.getLocalTranslation().x - character.getLocalTranslation().x)+
(int) Math.abs(model.getLocalTranslation().z - character.getLocalTranslation().z);
mainControl.setNewAnimationTimes(2, 14);
mainControl.setSpeed(20f);
Vector3f face = character.getLocalTranslation();
modelMover.setRotation(1, 0, model.getLocalRotation());
modelMover.setRotation(1, timetaken / 3, q);
//gametime.getTimeInSeconds()
modelMover.setPosition(0,0 ,model.getLocalTranslation());
modelMover.setPosition(0, timetaken,
new Vector3f(character.getLocalTranslation().x, character.getLocalTranslation().y,character.getLocalTranslation().z));
//System.out.println("Time: 0 to "+ timetaken+ " from "+model.getLocalTranslation().toString()+ " to "+character.getLocalTranslation().toString() );
modelMover.interpolateMissing();
modelMover.setSpeed(20f);
model.addController(modelMover);
model.addController(mainControl);
model.updateModelBound();
model.updateWorldBound();
moving = true;
}
else {
if (!(model.getLocalTranslation().equals(character.getLocalTranslation()))){
moving = false;
//System.out.println(model.getLocalRotation().toString());
//System.out.println(" from "+model.getLocalTranslation().toString()+ " to "+character.getLocalTranslation().toString() );
}
}
}
public Node getMd2(String path, String texPath, TextureState state){
URL tex = HelloModelLoading.class.getClassLoader().getResource("repository//"+texPath);
URL mdl = HelloModelLoading.class.getClassLoader().getResource("repository//"+path);
System.out.println(tex.toString());
System.out.println(mdl.toString());
Node model = null;
FormatConverter conv = new Md3ToJme();
ByteArrayOutputStream mdlFin = new ByteArrayOutputStream();
try {
conv.convert(mdl.openStream(), mdlFin);
} catch (IOException e) {
System.out.println("didn't work…");
e.printStackTrace();
}
try {
model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(mdlFin.toByteArray()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
state.setEnabled(true);
Texture mdlTexture= TextureManager.loadTexture(
tex,
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR);
state.setTexture(mdlTexture);
model.setRenderState(state);
return model;
}
}
Ok, I finally got your program to compile and run, but now I don't quite understand what you mean by charge, I do not see any camera flickering while moving.
//if ((ooga.getModel() != null) &&(timer.getTimeInSeconds()>10)) ooga.chargeTo(myChar, gametime);
oops sorry comment out the line above
i think i commented to play with something else
once you remove the comment marks, it should start the crazy camera movement
Ok, it does… I will check it out!
You probably don't want to hear this but here it goes anyway:
public Vector3f getDirection(Vector3f a, Vector3f b)
{
Vector3f vec = new Vector3f();
vec.x = b.x - a.x;
vec.y = b.y - a.y;
vec.z = b.z = a.z;
return vec;
}
This function is WRONG in a very peculiar way... The line before the return has an equals instead of a minus. 8)
That gets rid of the flickering... but the model still does not move :|
I also got rid of the lines:
float camMinHeight = page.getHeight(cam.getLocation()) + 2f;
if (!Float.isInfinite(camMinHeight) && !Float.isNaN(camMinHeight) && cam.getLocation().y <= camMinHeight)
{
cam.getLocation().y = camMinHeight;
cam.update();
}
float characterMinHeight = page.getHeight(myChar.getLocalTranslation())+((BoundingBox)myChar.getWorldBound()).yExtent;
if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight))
{
myChar.getLocalTranslation().y = characterMinHeight + shift;
myChar.setLocalRotation(quickRotation(-45, new Vector3f(0,1,0)));
}
Because they messed with the chasing camera. Good luck.
oh lol. Leave it to me to make some really juvinille mistake and waste someone else's time solving it lol! thank you so much for helping a fairly confuzzled newbie i'll be sure to play a bit more with it and post my results
Maybe one day, when i get better at this i'll make a tutorial for everbody
faraway said:
Maybe one day, when i get better at this i'll make a tutorial for everybody ;)
Glad to hear that. Keep it up, and don't feel bad... It happens to everybody. :P Just one week ago I was still a n00b in these forums, and now I am on my way to a Sr. Member XD (granted this is only related to the number of posts, but I like to think it means something else ;))
Yes, you have been a busy poster! 8)
nymon said:
Yes, you have been a busy poster! 8)
Under risks of going way off-topic: Just trying to do my part XD My motto has always been:
Learn from everybody else's mistakes... you don't have enough time to make them all.
The best way to do this is by means of this forum :D