Comments (4)
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?
from planck.js.
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.
from planck.js.
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.)
from planck.js.
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 viaVec2.projectOn(x,y)
but notx.projectOn(y)
.Vec2.prototype.projectOn = function(other){...}
defines a method for all instances that can be invoked viax.projectOn(y)
(andVec2.prototype.projectOn(x, y)
but in this casex
will be anObject
and not aVec2
)- One can also define an instance method directly in an object constructor. Unlike the prototype version the implementation code object will not be shared across instances. The benefit is that one can use constructor parameters explicitly which is clearly not possible with prototype methods (one needs pass everything via
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++)).
from planck.js.
Related Issues (20)
- Memory leak in planck? HOT 2
- When will version 1 be released? HOT 5
- Feature Request: Implementation of b2Draw, SetDebugDraw and DebugDraw HOT 7
- Changing a circle collider's friction doesn't make it roll slower HOT 1
- Feature Request: Add the ESM button to jsDelivr
- How to change a collider's center? HOT 5
- Why does displacement cause multiple begin and end contact events? HOT 6
- Typo in the Wiki HOT 4
- setActive(true) throwing error in v1 beta 8
- ERROR changing a collider's mass cancels its linearVelocity HOT 5
- planck's npm package is quite large HOT 8
- World step error HOT 12
- possible testOverlap bug HOT 2
- Undefined Reading "x" error HOT 5
- Raycasts phasing through walls HOT 6
- clarification on the determinism limitation from docs HOT 1
- pointers on how to network planck HOT 8
- inconsistent Vec2 construction throughout examples
- DistanceJoint `getReactionForce` function not working HOT 4
- Script tag: Uncaught TypeError: t is null HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from planck.js.