Page 1 of 1

WHAT IS e.normal and Scene.entityByGeomID ?!!!

PostPosted: Tue Feb 19, 2013 4:08 pm
by BAZOOKA
Hello, Algodoo Users,
I've been trying to learn how to make a mouse(cursor)-following device. I was browsing Algobox for the scenes, and some of them included "Scene.entityByGeomID" :wtf: which I have NO IDEA what it is. Also, there was another one using Material Velocity, and the "e.normal" is EXTREMELY CONFUSING. :wtf: , so can ANYONE tell me what they mean and how to make a mouse-following device?!!

Re: WHAT IS e.normal and Scene.entityByGeomID ?!!!

PostPosted: Tue Feb 19, 2013 9:19 pm
by Kilinich
There is a lot of tech how to follow mouse.
Simplest is just set geom property (works for Algodoo 2.0.2+)
Code: Select all
pos = {app.mousepos}

Or you could use scripted thrusters, sptrings, rods, motors, etc.
To understand how, you need to learn thyme, read forum, look into other's scenes, experimenting, ask questions if you stuck. Mouse following device is pretty hard to make, start from something simpler, like mouse following car.

scene.entityByGeomID - returns geom by given geomID, so you colud find geom connected with hinge inside hinge scripts;
e.normal - surface normal vector with length 1m;

Re: WHAT IS e.normal and Scene.entityByGeomID ?!!!

PostPosted: Thu Feb 21, 2013 11:55 am
by BAZOOKA
OK...what is a surface normal vector? and 'returns geom by geomID'... :?
P.S. I had the script of the mouse following car like this:
Code: Select all
scene.my.mspd = 0
scene.my.mspd = (e.pos(0) - app.mousepos(0))*5

Re: WHAT IS e.normal and Scene.entityByGeomID ?!!!

PostPosted: Thu Feb 21, 2013 12:04 pm
by Kilinich
BAZOOKA wrote:OK...what is a surface normal vector? and 'returns geom by geomID'... :?


Every geom has GeomID - unique number, in hinge there are 2 linked geom IDs: geom0, geom1.
So if you want to read pos geom property from hinge's script you must use (scene.entityByGeomID( geomID )).pos
(to read geom0 or geom1 you need to add (readable(entity)).geom0 finction call)

Normal vector: http://en.wikipedia.org/wiki/Normal_(geometry)

Re: WHAT IS e.normal and Scene.entityByGeomID ?!!!

PostPosted: Mon Jun 10, 2013 7:45 am
by racergonemad
So how could I make, say, a hinge whose speed is proportional to its attached geometry's density, or a circle's friction that's proportional to a laser's brightness that's attached to it?

Update:
Ok, I've learned how to do it on my own by reading forum posts, studying some scenes, and playing around with them. Unfortunately, I didn't find any clean examples so I thought I might as well post it here.

The function "scene.entityByGeomID" works like this:
We have "e.this.density" to call an object's own density, and we have "e.other.density" to call the density of the geometry that an object collides with, but what if you want to call the density of a totally different object that's not in the collision event? If you know that object's geomID, then you can use "(scene.entityByGeomID(#)).density" where "#" equals the geomID of the object of interest. For example, if you want a random object to gain the same color as a totally different object known geomID, without interacting with it, then you'd use the following code, while replacing "#" with the geometry of interest's geomID:
Code: Select all
(e)=>{e.this.color := (scene.entityByGeomID(#)).color}
Note, For some reason, it doesn't work on spawn objects with predetermined geomIDs, like if I use "scene.addCircle({geomID := 5})" :? .

In the case of a laser attached to a geometry, "#" can be replaced with "(readable(entity)).geom" in order to call its host geometry's geomID. For example, if you want a laser to adopt the same color as the geometry its attached to, upon shining on another random object, you'd use onLaserHit code:
Code: Select all
(e)=>{e.this.color := {(scene.entityByGeomID((readable(entity)).geom)).color}}

Re: WHAT IS e.normal and Scene.entityByGeomID ?!!!

PostPosted: Wed Jul 17, 2013 10:58 pm
by Xray
racergonemad - THANKS very much for your very detailed explanation! I wish that other intelligent people who know this stuff were half as good as you are at explaining things so that other (less intelligent) people, like myself, can understand it. Most smart people mean well when they attempt to explain a complex or confusing technical issue, but they are not good communicators, and the result is that the subject matter doesn't get learned. I hope that you will give more of your tutorials on other Thyme related subjects!

Thanks again!

Xray