About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Clicked Object Properties
Author Message
WiLLyRS Offline
Member

Post: #1
Clicked Object Properties
Hi guys, from the "doors" tutorial I've managed to click on an object and recognise which object
type is, in particular i would like to recognise an animatable object, doing this:

Code:
if(Game::Animatable *Animatables=CAST(Game::Animatable,phys_hit.obj))[/php]
The declaration of Animatables is [code]Game::ObjMemx<Game::Animatable> Animatables;
And I load with the normal
Code:
.setObjType(Animatables, OBJ_ANIMATABLE)
in the game world init.

The debug show me that it goes correctly into the if, so the code until here is correct. My
problem is that after this cast I don't know how to access to that object properties, like meshes
etc. I saw the struct is:
Code:
STRUCT(Animatable , Obj) // Game Animatable Object
//{
   Flt         scale    ; // scale
   MeshPtr     mesh     ; // mesh
   MaterialPtr material ; // overriding material
   CSkeleton   cskel    ; // controlled skeleton
   SkelAnim   *skel_anim; // skeleton animation
   PhysBodyPtr phys     ; // physical body
   Actor       actor    ; // actor

   // manage
   virtual void create(ObjParams &obj); // create from object parameters

   // get / set
   virtual Vec    pos   (                ); // get position
   virtual void   pos   (C Vec    &pos   ); // set position
   virtual Matrix matrix(                ); // get matrix  , returned matrix is normalized
   virtual void   matrix(C Matrix &matrix); // set matrix  , 'matrix' must be normalized

   // callbacks
   virtual void memoryAddressChanged(); // called when object memory address has been
changed, you should override it and adjust Actor::obj pointer for all actors

   // update
   virtual Bool update(); // update, return false when object wants to be deleted, and true if wants to exist

   // draw
   virtual UInt drawPrepare(); // prepare for drawing, this will be called in RM_PREPARE mode, in this method you should add the meshes to the draw list (Mesh::draw), and return a combination of bits of which additional render modes will be required for custom drawing of the object (for example "return IndexToFlag(RM_BLEND)" requests blend mode rendering)
   virtual void drawShadow (); // in this method you should add the meshes to the shadow draw list (Mesh::drawShadow)

   // io
   virtual void save(File &f); // save
   virtual Bool load(File &f); // load, false on fail

  ~Animatable();
   Animatable();

protected:
   Matrix _matrix;
};

So, I've tried the normal access to a struct variable namestruct.namevariable but without
success. The -> too doesn't show me the properties, and the word Animatables is not either
recognised to be a variable, am I missing something?
(This post was last modified: 05-10-2011 03:11 PM by WiLLyRS.)
05-09-2011 09:10 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: Clicked Object Properties
You probably shouldn't call the clicked object Animatables since Animatables is already defined as the ObjMemx.

Code:
if(Game::Animatable *animatable=CAST(Game::Animatable,phys_hit.obj))
{
    animatable->
}
(This post was last modified: 05-10-2011 08:43 AM by Driklyn.)
05-10-2011 08:43 AM
Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #3
RE: Clicked Object Properties
can't believe it was for that .-.
thanks! I'm a master in stupid errors pfft
Now that i can access the struct's function I've got another question... Ok, i can use the variables and the function declared in the struct, but how about the parameters added to the object with the world editor?
05-10-2011 03:01 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #4
RE: Clicked Object Properties
Either by creating a custom class like in "EsenthelEngineSDK\Tutorials\Source\Advanced\4 - Demos, Game Basics\Game Basics\08 - Custom Parameters.cpp" or load in a .obj file directly wherever you need it:

Code:
Game::ObjParams obj = *Game::Objs.ptrRequire("Obj/chr/Human/0.obj");

Str name;
if (Param *param = obj.findParam("Name")) name = param->asText();
05-10-2011 07:29 PM
Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #5
RE: Clicked Object Properties
Mmh, *trying to find how the world loading works* so when I load the world objects with
.setObjType(Animatables, OBJ_ANIMATABLE) it automatically create this class with the attributed that I've set in the world editor?
if it is the case, I have the
Code:
if(Game::Animatable *clicked=CAST(Game::Animatable,phys_hit.obj))
which contain the pointer to the animatable object that I have clicked and the code to take these
Code:
if (Param *param = obj.findParam("Name")) name = param->asText();
but "clicked" doesn't have the findParam options, in fact if I "clicked." VS2010 tells me that there aren't any member that can be applied to "clicked" :\
05-10-2011 08:10 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #6
RE: Clicked Object Properties
Parameters are not automatically loaded. They are given to you in the create method of an Obj class. From the tutorial:

Code:
void Item::create(Game::ObjParams &obj)
{
    super::create(obj); // default create

    // now setup custom parameters from 'obj'
    if(Param *par=obj.findParam("name" ))Set(name ,par->asText());
    if(Param *par=obj.findParam("value"))    value=par->asInt () ;
}

If you want to do it this way so you can store the params as a variable on the object itself, you will need to create a custom class:

Code:
struct Animatable : Game::Animatable
{
    var name;

    void Animatable::create(Game::ObjParams &obj)
    {
        super::create(obj);
        if(Param *par=obj.findParam("name" )) name = par->asText();
    }
}
Game::ObjMemx<Animatable> Animatables;

Then:

Code:
if(Animatable *clicked=CAST(Animatable,phys_hit.obj))
{
    clicked->name
}

This is probably the way to go, but if you only need to access a certain parameter and don't want to make a custom class just for that, you can load the .obj file directly in the code and access it that way, like so:

Code:
if(Game::Animatable *clicked=CAST(Game::Animatable,phys_hit.obj))
{
    Game::ObjParams obj = *Game::Objs.ptrRequire("Obj/path/to/obj/0.obj");

    Str name = S;
    if (Param *param = obj.findParam("Name")) name = param->asText();
}
(This post was last modified: 05-12-2011 03:58 AM by Driklyn.)
05-12-2011 03:55 AM
Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #7
RE: Clicked Object Properties
Thanks, now I've understood ^^
05-12-2011 07:32 PM
Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #8
RE: Clicked Object Properties
Sorry for the double post, I've tried the first way, by creating a custom class.
I've made an animatables.h file that contain the definiction of the struct (this is the tutorial version, but I've tried too with yours:
Code:
#ifndef _GAME_ANIMATABLES_H
#define _GAME_ANIMATABLES_H

/******************************/

STRUCT(Animatable, Game::Animatable)
//{
    Char name[20];
    virtual void create (Game::ObjParams &obj);    //extend default creation

    //constructor
    Animatable();
};
/*******************/
#endif

and an animatables.cpp

Code:
#include "stdafx.h"
#include "../Main.h"
/****************/
void Game::Animatable::create(Game::ObjParams &obj)
{
    super::create(obj);    //default creation

    //now adding the custom param
    if(Param *par=obj.findParam("name" ))Set(name ,par->asText());
}

/****************/
Game::Animatable::Animatable()
{
    //initializing
    name[0] = 0;
}

The error is on "name" in the .cpp, it tells me that it's not declared :\
05-13-2011 01:44 PM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #9
RE: Clicked Object Properties
Remove the "Game::" in your cpp file... its looking probably in the wrong class. But you need to reference it to your custom class.

There is always evil somewhere, you just have to look for it properly.
(This post was last modified: 05-13-2011 03:19 PM by Dynad.)
05-13-2011 03:18 PM
Visit this user's website Find all posts by this user Quote this message in a reply
WiLLyRS Offline
Member

Post: #10
RE: Clicked Object Properties
Finally it works! Thanks a lot guys wink
05-13-2011 03:28 PM
Find all posts by this user Quote this message in a reply
Post Reply