Main Menu

Fresh Veiw

Started by KittenKoder, November 06, 2012, 07:17:50 PM

Previous topic - Next topic

KittenKoder

Alright, I am literally stumped on this and would like some alternative ideas as to why it happens. Here's the code first:


public void moveInBounds() {
this.tempvector = this.object.getTransformedCenter(this.tempvector);
if(this.origin != null) this.tempvector.sub(this.origin);

if(this.bounds.x > 0.0f) this.tempvector.x = (this.tempvector.x < -this.bounds.x) ? -this.bounds.x :
((this.tempvector.x > this.bounds.x) ? this.bounds.x : this.tempvector.x);

if(this.bounds.y > 0.0f) this.tempvector.y = (this.tempvector.y < -this.bounds.y) ? -this.bounds.y :
((this.tempvector.y > this.bounds.y) ? this.bounds.y : this.tempvector.y);

if(this.bounds.z > 0.0f) this.tempvector.z = (this.tempvector.z < -this.bounds.z) ? -this.bounds.z :
((this.tempvector.z > this.bounds.z) ? this.bounds.z : this.tempvector.z);

if(this.origin != null) this.tempvector.add(this.origin);

this.object.clearTranslation();
this.object.translate(this.tempvector);
}


Now the problem is that when moving the object, then checking for if it's in bounds, the x and z directions work as expected, the object stops at the edge like there's an invisible wall. However the y acts funny, moving down(+) there's a bounce, and moving up(-) it takes a large value to pull it back down from the edge. I seriously have no idea why it's doing this, if anyone has an idea let me know.

The bounds are how far the object can move from it's origin, not the jPCT origin but the origin set for the actor.
When life throws you lemons, make lemon juice, then drop life into a pile of razors and pour the lemon juice over it.

EgonOlsen

And origin is null or filled in this case? And if it's filled, with which value?

Personally, i would get rid of all these ternary ifs and use "real" ifs instead to ease debugging by adding some log output of inbetween states (or use a debugger, if you are weak... ;) ).

I'm not totally sure what this code is supposed to do, which is mainly caused by the fact that i'm not sure what "origin" exactly is.

KittenKoder

Quote from: EgonOlsen on November 06, 2012, 08:19:10 PM
And origin is null or filled in this case? And if it's filled, with which value?

Personally, i would get rid of all these ternary ifs and use "real" ifs instead to ease debugging by adding some log output of inbetween states (or use a debugger, if you are weak... ;) ).

I'm not totally sure what this code is supposed to do, which is mainly caused by the fact that i'm not sure what "origin" exactly is.

I'm not that great at explaining things so no surprise. ;)

Origin is like the center point of the bounds, but the odd part is that it should work just fine, I can't think of why it's behaving so oddly, like somehow it's increasing the y translation. I tend to use System.out for debugging, debuggers really drain resources and my computer isn't that impressive. I have traced all the calls prior to it, and there is nothing moving the object "up." This is the only location the problem could be. I was thinking it may be a precision error, but then the others would be effected as well. I'm really just banging my head right now. lol
When life throws you lemons, make lemon juice, then drop life into a pile of razors and pour the lemon juice over it.

EgonOlsen

I'm still not sure what this is supposed to do. I mean if everything is within the bounds, what this does is:


  • store the transformed center in tempvector
  • subtract origin
  • assign tempvector's attributes to themselves (i.e. a nop)
  • add origin
  • clear the translation
  • translate to tempvector

This can be simplified to


  • store the transformed center in tempvector
  • clear the translation
  • translate to tempvector

Which basically translates it along the direction vector from it's current translation to the position of its center in world space...or did i miss something (most likely...)?

I fail to see the point in that operation...


KittenKoder

Quote from: EgonOlsen on November 06, 2012, 09:15:48 PM
I'm still not sure what this is supposed to do. I mean if everything is within the bounds, what this does is:


  • store the transformed center in tempvector
  • subtract origin
  • assign tempvector's attributes to themselves (i.e. a nop)
  • add origin
  • clear the translation
  • translate to tempvector

This can be simplified to


  • store the transformed center in tempvector
  • clear the translation
  • translate to tempvector

Which basically translates it along the direction vector from it's current translation to the position of its center in world space...or did i miss something (most likely...)?

I fail to see the point in that operation...

It's not just assigning, it's comparing to the bounds as if they are minimum and maximum values. So it's like clipping or constraints.

I think I discovered the problem, it's in the object's transformed center and the point it translates from, they are not the same point in the object. I was looking at the incorrect point, I needed to change getTransformedCenter with getTranslation.
When life throws you lemons, make lemon juice, then drop life into a pile of razors and pour the lemon juice over it.

EgonOlsen

Quote from: KittenKoder on November 06, 2012, 09:25:10 PM
It's not just assigning, it's comparing to the bounds as if they are minimum and maximum values. So it's like clipping or constraints.
I know. That's why i wrote "if everything is within the bounds". I tried to simplify the case.

Quote from: KittenKoder on November 06, 2012, 09:25:10 PM
I think I discovered the problem, it's in the object's transformed center and the point it translates from, they are not the same point in the object. I was looking at the incorrect point, I needed to change getTransformedCenter with getTranslation.
That was the confusing part...but if you use getTranslation(), then where's the actual translation? You read the translation, subtract the origin, do a nop if everything is within the bounds, add origin again, clear the translation and translate again to the unchanged translation vector. If everything works now, all is well...i would just like to understand how you translate things with something that appears to be a large nop to me...what am i missing?

KittenKoder

Quote from: EgonOlsen on November 06, 2012, 09:37:23 PM
Quote from: KittenKoder on November 06, 2012, 09:25:10 PM
It's not just assigning, it's comparing to the bounds as if they are minimum and maximum values. So it's like clipping or constraints.
I know. That's why i wrote "if everything is within the bounds". I tried to simplify the case.

Quote from: KittenKoder on November 06, 2012, 09:25:10 PM
I think I discovered the problem, it's in the object's transformed center and the point it translates from, they are not the same point in the object. I was looking at the incorrect point, I needed to change getTransformedCenter with getTranslation.
That was the confusing part...but if you use getTranslation(), then where's the actual translation? You read the translation, subtract the origin, do a nop if everything is within the bounds, add origin again, clear the translation and translate again to the unchanged translation vector. If everything works now, all is well...i would just like to understand how you translate things with something that appears to be a large nop to me...what am i missing?

Oh, that's what you're talking about, yeah, I write the code I need first, make sure it works, then optimize after it's working as expected. It will be in the final method.
When life throws you lemons, make lemon juice, then drop life into a pile of razors and pour the lemon juice over it.

EgonOlsen


KittenKoder

Alright, the final method, which is only called if the object fails and "in bounds" check.


public void moveInBounds() {
this.tempvector = this.object.getTranslation(this.tempvector);
this.center = this.object.getTranslation(this.center);
if(this.origin != null) this.tempvector.sub(this.origin);

if(this.bounds.x > 0.0f) this.tempvector.x = (this.tempvector.x < -this.bounds.x) ? -this.bounds.x :
((this.tempvector.x > this.bounds.x) ? this.bounds.x : this.tempvector.x);

if(this.bounds.y > 0.0f) this.tempvector.y = (this.tempvector.y < -this.bounds.y) ? -this.bounds.y :
((this.tempvector.y > this.bounds.y) ? this.bounds.y : this.tempvector.y);

if(this.bounds.z > 0.0f) this.tempvector.z = (this.tempvector.z < -this.bounds.z) ? -this.bounds.z :
((this.tempvector.z > this.bounds.z) ? this.bounds.z : this.tempvector.z);

if(this.origin != null) this.tempvector.add(this.origin);
this.tempvector.sub(this.center);

this.object.translate(this.tempvector);
}


The "in bounds" check is done in a different method, primarily because it has other uses. "center" is a temp SimpleVector that I always use to get the object's center point or translation, I forgot I had that in the class already. lol But I found a reason to have two, so it's all good.
When life throws you lemons, make lemon juice, then drop life into a pile of razors and pour the lemon juice over it.