Closed 1pakch closed 7 years ago
Testbed does not use dist/planck.js
, it serves and uses a live build. You could check in the browser to see if it is added.
By the way, isn't it possible to use dot
function for projection?
I even see this new method in Developer Tools sources of Vec2
in Chromium. Regardless of this it is undefined on Vec2
objects spit out by the library. I am a complete JS newbie, so maybe my comprehension of what is going on is a bit off.
I meant projection as a vector, i.e.
project = function(v, w) {
Vec2.assert(v);
Vec2.assert(w);
return w.mul(Vec2.dot(v, w));
}
IMO something like v.projectOn(w)
reads better as the geometric meaning is immediately clear.
Can you please include the exact code that you are adding?
You could either do Vec2.projectOn = function(v, w){...}
or Vec2.prootype.projectOn = function(w){...}
which are a little different. (I recommend studying prototype
s in JS if you are new to this topic.)
It is the exact code except for the name. The issue was that I did not understand the different ways of defining methods in JS. As I see it now
Vec2.projectOn = function(v, w){...}
defines a static method which can only be invoked via Vec2.projectOn(x,y)
but not x.projectOn(y)
.Vec2.prototype.projectOn = function(other){...}
defines a method for all instances that can be invoked via x.projectOn(y)
(and Vec2.prototype.projectOn(x, y)
but in this case x
will be an Object
and not a Vec2
)this
).Many thanks, you pointed me in the right direction. The only thing I am not quite sure about is the call Vec2.prototype.projectOn(x, y)
. Why and how it works so that x
is passed as an Object
and not as Vec2
? (I guess I should read a bit on JS type system as it is a bit different from what I am used to (Python, C++)).
I am porting the Top-down car demo and computing a projection of one vector on another one is quite a common operation there. Hence I implemented a
projectOn
method for theVec2
class and the issue is that I am unable to run a testbed so that it picks up the new version of theVec2
class.While I am able to rebuild
dist/planck.js
using gulp so that it includes the new method it is still not picked up by the testbed. Naturally, I am wondering what goes wrong.I am new to js so I apologize if the issue is trivial.