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

Introduce yourself to the Algodoo community!

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

Postby BAZOOKA » Tue Feb 19, 2013 4:08 pm

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?!!
User avatar
BAZOOKA
 
Posts: 22
Joined: Fri Oct 26, 2012 5:45 pm

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

Postby Kilinich » Tue Feb 19, 2013 9:19 pm

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;
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

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

Postby BAZOOKA » Thu Feb 21, 2013 11:55 am

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
Some science teacher said one day,'Remember to leave the water dry...'
User avatar
BAZOOKA
 
Posts: 22
Joined: Fri Oct 26, 2012 5:45 pm

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

Postby Kilinich » Thu Feb 21, 2013 12:04 pm

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)
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

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

Postby racergonemad » Mon Jun 10, 2013 7:45 am

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}}
My signature is worth a lot of money, So I'm gonna put this stamp instead:
[$20 PER AUTOGRAPH]
racergonemad
 
Posts: 26
Joined: Tue Aug 17, 2010 7:37 am

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

Postby Xray » Wed Jul 17, 2013 10:58 pm

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
User avatar
Xray
 
Posts: 489
Joined: Sun Jun 17, 2012 6:12 am
Location: USA


Return to Introduction

Who is online

Users browsing this forum: No registered users and 1 guest