cool, I coudn't even imagine - we can do almost everything with maratis )
I decided to create new behavior
That's one problem - my behavior doesn't take place in behavior list
Could you have a look?
MouseClick.h
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleGamePlugin
// MouseClick.h
//
// Code : Anael Seghezzi
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef _MOUSE_CLICK_H
#define _MOUSE_CLICK_H
#include <MEngine.h>
class MouseClick : public MBehavior
{
public:
// constructors / destructors
MouseClick(MObject3d * parentObject);
MouseClick(MouseClick & behavior, MObject3d * parentObject);
~MouseClick(void);
private:
// custom variables
const char* m_cameraName;
public:
// destroy
void destroy(void);
// get new
static MBehavior * getNew(MObject3d * parentObject);
// get copy
MBehavior * getCopy(MObject3d * parentObject);
// name
static const char * getStaticName(void){ return "MouseClick"; }
const char * getName(void){ return getStaticName(); }
// variables
unsigned int getVariablesNumber(void);
MVariable getVariable(unsigned int id);
// events (virtuals from MBehavior class)
void update(void);
void onBeginScene(void);
void runEvent(int param){}
};
#endif
MouseClick.cpp
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// SimpleGamePlugin
// MouseClick.cpp
//
// Code : Anael Seghezzi
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "MouseClick.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Init, this part is always similar, constructor, copy constructor etc
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// constructor
MouseClick::MouseClick(MObject3d * parentObject):
MBehavior(parentObject),
m_cameraName(NULL)
{}
// copy constructor
MouseClick::MouseClick(MouseClick & behavior, MObject3d * parentObject):
MBehavior(parentObject),
m_cameraName(behavior.m_cameraName)
{}
// destructor
MouseClick::~MouseClick(void)
{}
// destroy function : always similar
void MouseClick::destroy(void)
{
delete this;
}
// getNew function : always similar
MBehavior * MouseClick::getNew(MObject3d * parentObject)
{
return new MouseClick(parentObject);
}
// getCopy function : always similar
MBehavior * MouseClick::getCopy(MObject3d * parentObject)
{
return new MouseClick(*this, parentObject);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables, allow to access custom variable from script and from Maratis Editor
/////////////////////////////////////////////////////////////////////////////////////////////////////////
unsigned int MouseClick::getVariablesNumber(void){
return 1;
}
MVariable MouseClick::getVariable(unsigned int id)
{
switch(id)
{
default:
return MVariable("NULL", NULL, M_VARIABLE_NULL);
case 0:
return MVariable("Camera name", &m_cameraName, M_VARIABLE_STRING);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Events
/////////////////////////////////////////////////////////////////////////////////////////////////////////
MScene * MenuScene = NULL;
MOText * MenuText = NULL;
MLevel * MenuLevel=NULL;
MOCamera * MenuCamera=NULL;
MInputContext * input=NULL;
void MouseClick::onBeginScene(void)
{
//MGame::onBeginScene();
MEngine * engine = MEngine::getInstance(); // get the engine instance
MLevel * level = engine->getLevel(); // get the current level
MObject3d * parent = getParentObject();
//printf("use");
//MenuScene=level->getSceneByName("menu");
MenuText=MenuScene->getTextByName(parent->getName());
MenuLevel= engine->getLevel();
MenuCamera=MenuScene->getCameraByName(m_cameraName);
}
// update function (called by MGame class by default)
void MouseClick::update(void)
{
MEngine * engine = MEngine::getInstance();
MGame * game = engine->getGame();
unsigned int width = 0;
unsigned int height = 0;
MSystemContext * system = engine->getSystemContext();
system->getScreenSize(&width, &height);
if(! game->isRunning())
return;
float mouseX = input->getAxis("MOUSE_X");
float mouseY = input->getAxis("MOUSE_Y");
MVector3 origin = MenuCamera->getTransformedPosition();
MVector3 dest = MenuCamera->getUnProjectedPoint(MVector3(mouseX*width, (1.0f - mouseY)*height, 1.0f));
MBox3d * bbox = MenuText->getBoundingBox();
if(isEdgeToBoxCollision(origin, dest, bbox->min, bbox->max)){
printf("it works!");
}
// get the associated parent object (who is using this behavior)
//MObject3d * parent = getParentObject();
// lets rotate the parent object around the z axis, using our custom "rotationSpeed" variable
//parent->addAxisAngleRotation(MVector3(0, 0, 1), m_rotationSpeed);
}
And did you have any project now? Really interesting
Last edited by hog (2014-05-21 09:15:15)