About Store Forum Documentation Contact
Donations:
158$/mo



Post Reply 
light moving with object
Author Message
yvanvds Offline
Silver Supporter

Post: #1
light moving with object
Ok, this might be impossible. I can't think of a way to do it, but you never know:

I have a lamp hanging from a ceiling, and made it move with the wind using the leaves material type. Looks very good, but now I'd like a light inside the lamp that follows the leaves movement of the lamp. Can this be done?

It looks like this (without the light inside): http://www.vimeo.com/18268194

Thanks!

yvan
(This post was last modified: 12-30-2010 10:53 PM by yvanvds.)
12-29-2010 03:17 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: light moving with leaves
Hi,

not using this technique.

You can just make the lamp as skeleton+animation, and then detect the position of some SkelPoint (inside the lamp) CSkeleton::getPoint(..) and draw the light at skelpoint position.
12-29-2010 03:36 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Silver Supporter

Post: #3
RE: light moving with leaves
I didn't think of that. I thought only characters had skeletons. The getPoint part I think i can find from the tutorials, but how do I add a skeleton to an object?

I tried looking into the horse code in esenthel RPG2, but I didn't get it completely, i'm afraid. Is there a better example for this, somewhere?

Edit: Wait a minute, it's in "Extending Game Object Class.cpp", isn't it? :-)
(This post was last modified: 12-29-2010 11:32 PM by yvanvds.)
12-29-2010 11:28 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: light moving with leaves
EsenthelEngineSDK\Tutorials\Source\Advanced\2 - Animation, Physics, Rendering\Animation\02 - Skeleton Points

EsenthelEngineSDK\Tutorials\Source\Advanced\3 - Mesh, Shaders\Mesh\
Separate parts rendering 2 - Skeleton
and
Separate parts rendering 3 - Controlled Skeleton
12-30-2010 12:51 AM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Silver Supporter

Post: #5
RE: light moving with leaves
Ok, got it. Just in case someone else should be interested: this is the code.

PHP Code:
struct NewObj Game::Obj {
   
Vec position
   
MeshPtr mesh;
   
CSkeleton cskel;
   
Matrix m;

   
virtual void create(Game::ObjParams &obj); 

   
virtual Vec  pos() {return position;} 
   
virtual void pos(C Vec &pos) {T.position=pos;} 
   
virtual Matrix matrix() {return position;}
   
virtual void matrix(C Matrix &matrix) { T.position=matrix.pos;}

   
virtual Bool update();
   
virtual UInt drawPrepare();
   
virtual void drawShadow();

   
NewObj();
};

NewObj::NewObj() {
   
position.zero();
}

void NewObj::create(Game::ObjParams &obj) {
   
position obj.matrixFinal().pos
   
mesh obj.mesh(); 
   
Skeleton *skel obj.skeleton();
   
obj.matrixFinal();
   
cskel.create(*skelobj.scale(), m);
}

UInt NewObj::drawPrepare() {
   
mesh->draw(cskel);
   
C OrientP &light cskel.getPoint("light");
   
LightPoint(20light.posVec(0.811)).add();

   return 
0
}
void NewObj::drawShadow() {
   
mesh->drawShadow(cskel);
}

Bool NewObj::update() {
   
cskel.clear();
   
cskel.animate(L"obj/lamps/victorian/victorian.anim"Time.time()/10);
   
cskel.updateMatrix(m);
   return 
true;                                                                             

12-30-2010 06:29 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: light moving with leaves
Yeah!

but don't forget about save/load methods

although if you use CONST object access mode then they wont be needed.

and things like "mesh->draw(cskel);" you might wanna change to "if(mesh)mesh->"
and "cskel.create(*skel" to "if(!skel)Exit("no skeleton"); cskel.create(*skel"

moved to code snippets
12-30-2010 08:09 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Silver Supporter

Post: #7
RE: light moving with leaves
Indeed, that might be safer. I had it first, but something was wrong and then i stripped it to the bare minimum. In the end, I found out I shouldn't take the matrix from the tutorial, because it just placed all my object in the middle of the terrain. (I'm still not very good at matrixes :-)

Since they're lamps, I didn't care about saving them.

What I still don't get though, is why the set/get methods for pos and matrix are needed. They're also used in the tutorial, but none of the methods actually uses them.
12-30-2010 08:38 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: light moving with leaves
they are virtual methods, so engine can call them to know where the objects are.
12-30-2010 08:40 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Silver Supporter

Post: #9
RE: light moving with object
Ok, thanks. I hope it's all right that I changed the subject 'light moving with leaves' to 'light moving with object'. It might be clearer, now that this is filed under code snippets.
12-30-2010 10:56 PM
Find all posts by this user Quote this message in a reply
Post Reply