the component doesn’t even work at all.
void Module::OnNodeSet(Node* node)
{
// If the node pointer is non-null, this component has been created into a scene node. Subscribe to physics collisions that concern this scene node
if (node)
{
SubscribeToEvent(node, E_NODECOLLISIONSTART, URHO3D_HANDLER(Module, OnCollisionEvent));
URHO3D_LOGINFO("node set");
}
}
this actually return me “node set” in the log but that’s all this fucking component can do !
in my main.cpp, if i try to move the node with the component on it with SetWorldPosition(), nothing move at all.
i’m losing my time with this shit. 
how da fuck do this shit work really ?!
main
[spoiler][code]//engine
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Engine/Engine.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Input/InputEvents.h>
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Scene/SceneEvents.h>
#include <Urho3D/Graphics/Octree.h>
#include <Urho3D/Graphics/DebugRenderer.h>
#include <Urho3D/Graphics/Camera.h>
#include <Urho3D/Graphics/Viewport.h>
#include <Urho3D/Graphics/Renderer.h>
#include <Urho3D/Graphics/Model.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/AnimatedModel.h>
#include <Urho3D/Graphics/Material.h>
#include <Urho3D/Graphics/Light.h>
#include <Urho3D/Core/CoreEvents.h>
#include <Urho3D/Math/Vector3.h>
#include <Urho3D/UI/Window.h>
#include <Urho3D/UI/Text.h>
#include <Urho3D/UI/Font.h>
#include <Urho3D/UI/UI.h>
#include <Urho3D/IO/Log.h>
//my class
#include “CreateModule.
h”
#include “Exit.h”
#include “Counts.h”
//include
#include
#include
#include
//physic
#include <Urho3D/Physics/PhysicsWorld.h>
#include <Urho3D/Physics/PhysicsEvents.h>
using namespace Urho3D;
class projet : public Application
{
URHO3D_OBJECT(projet, Application)
public:
////______________________
//// DEFINITION
SharedPtr<Scene> my_scene;
//about camera
SharedPtr<Node> camNode;
//physic
bool drawDebug_;
//about text
Window* window;
Text* text;
projet(Context* context) : Application(context)
{
// Register an object factory for our custom CreateRagdoll component so that we can create them to scene nodes
context->RegisterFactory();
//context->RegisterFactory();
}
virtual void Setup()
{
engineParameters_["FullScreen"]=false;
engineParameters_["WindowWidth"]=1280;
engineParameters_["WindowHeight"]=720;
engineParameters_["WindowResizable"]=true;
}
virtual void Start()
{
ResourceCache* cache=GetSubsystem<ResourceCache>();
my_scene=new Scene(context_);
my_scene->CreateComponent<Octree>();
my_scene->CreateComponent<DebugRenderer>();
//physic
my_scene->CreateComponent<PhysicsWorld>();
////___________________
//// MODULES
//Dungeon dungeon(100, my_scene, cache);
Node* m_Node = my_scene->CreateChild("Test");
m_Node->CreateComponent<Module>();
Module* m_comp = m_Node->GetComponent<Module>();
m_comp->createRoom(my_scene, cache);
Node* m_Node2 = my_scene->CreateChild("Test2");
m_Node2->CreateComponent<Module>();
Module* m_comp2 = m_Node2->GetComponent<Module>();
m_comp2->createCor(my_scene, cache);
m_comp2->SetWorldPosition(Vector3(0,2,0)); //i tryed with the node as well
URHO3D_LOGINFO("test_main");
////__________________
//// CAMERA
using namespace Urho3D;
camNode=my_scene->CreateChild(“camNode”);
Camera* camObject=camNode->CreateComponent();
camObject->SetFarClip(2000);
camNode->SetWorldPosition(Vector3(0,20,-20)); //x =blender y //y =blender z hauteur //z =blender x profondeur
camNode->LookAt(Vector3::ZERO);
//camera light
{
Light* light=camNode->CreateComponent<Light>();
light->SetLightType(LIGHT_POINT);
light->SetRange(25);
light->SetBrightness(2.0);
light->SetColor(Color(.8,1,.8,1.0));
}
////________________
//// TEXT
std::string str = ("");
{
std::ostringstream ss;
ss;
//<<" module count = "<<dungeon.MODULE_COUNT
//<<"\n free exit = "<<dungeon.mainExitList.size();
std::string s(ss.str());
str.append(s/*.substr(0,60)*/);
}
String s(str.c_str(),str.size());
window=new Window(context_);
GetSubsystem<UI>()->GetRoot()->AddChild(window);
window->SetStyle("Window");
window->SetSize(500,200);
window->SetColor(Color(.0,.15,.3,.5));
window->SetAlignment(HA_LEFT,VA_TOP);
text=new Text(context_);
text->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"),14);
text->SetColor(Color(.8,.85,.9));
text->SetAlignment(HA_LEFT,VA_TOP);
text->SetText(s); //s
window->AddChild(text);
////__________________
//// RENDER
Renderer* renderer=GetSubsystem<Renderer>();
SharedPtr<Viewport> viewport(new Viewport(context_,my_scene,camNode->GetComponent<Camera>()));
renderer->SetViewport(0,viewport);
////__________________
//// EVENTS
//SubscribeToEvent(E_BEGINFRAME,URHO3D_HANDLER(projet,HandleBeginFrame));
//SubscribeToEvent(E_KEYDOWN,URHO3D_HANDLER(projet,HandleKeyDown));
//SubscribeToEvent(E_UIMOUSECLICK,URHO3D_HANDLER(projet,HandleControlClicked));
SubscribeToEvent(E_UPDATE, URHO3D_HANDLER(projet, HandleUpdate));
//SubscribeToEvent(E_POSTUPDATE,URHO3D_HANDLER(projet,HandlePostUpdate));
//SubscribeToEvent(E_RENDERUPDATE,URHO3D_HANDLER(projet,HandleRenderUpdate));
SubscribeToEvent(E_POSTRENDERUPDATE,URHO3D_HANDLER(projet,HandlePostRenderUpdate));
//SubscribeToEvent(E_ENDFRAME,URHO3D_HANDLER(projet,HandleEndFrame));
SubscribeToEvent(E_KEYDOWN, URHO3D_HANDLER(projet, HandleKeyDown));
}
virtual void Stop()
{
}
////________
void HandleUpdate(StringHash eventType,VariantMap& eventData)
{
float timeStep=eventData[Update::P_TIMESTEP].GetFloat();
float MOVE_SPEED=50.0f;
Input* input=GetSubsystem<Input>();
if(input->GetQualifierDown(1)) // 1 is shift, 2 is ctrl, 4 is alt
MOVE_SPEED*=4;
if(input->GetKeyDown('D')) //rotate sens inverse horizontal
camNode->Translate(Vector3(1,0, 0)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('Q')) //sens montre horizontal
camNode->Translate(Vector3(-1,0,0)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('Z')) //zoom avant
camNode->Translate(Vector3(0,0,1)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('S')) //zoom arriere
camNode->Translate(Vector3(0,0,-1)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('E')) //rotate sens inverse vertical
camNode->Translate(Vector3(0,1,0)*MOVE_SPEED*timeStep);
if(input->GetKeyDown('A')) //sens montre vertical
camNode->Translate(Vector3(0,-1,0)*MOVE_SPEED*timeStep);
if (input->GetKeyPress(KEY_SPACE)) // Toggle physics debug geometry with space
drawDebug_ = !drawDebug_;
if(!GetSubsystem<Input>()->IsMouseGrabbed())
{
IntVector2 mouseMove=input->GetMouseMove();
if(mouseMove.x_>-2000000000&&mouseMove.y_>-2000000000)
{
camNode->LookAt(Vector3::ZERO); //look at 0,0,0
}
}
}
////_______
////________
void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
{
// If draw debug mode is enabled, draw physics debug geometry. Use depth test to make the result easier to interpret
if (drawDebug_)
my_scene->GetComponent<PhysicsWorld>()->DrawDebugGeometry(true);
}
////________
void HandleKeyDown(StringHash eventType, VariantMap& eventData)
{
using namespace KeyDown;
Graphics* graphics=GetSubsystem<Graphics>();
int key = eventData[P_KEY].GetInt();
if (key == KEY_ESC) //ESC to quit
{
engine_->Exit();
}
else if(key == KEY_TAB) //TAB to toggle mouse cursor
{
GetSubsystem<Input>()->SetMouseVisible(!GetSubsystem<Input>()->IsMouseVisible());
GetSubsystem<Input>()->SetMouseGrabbed(!GetSubsystem<Input>()->IsMouseGrabbed());
}
else if(key == 'W') //W for fullscreen
{
graphics->ToggleFullscreen();
}
else if(key == 'I')
{
//GetSubsystem<UI>()->menu->ShowPopup ();
}
}
////________
};
URHO3D_DEFINE_APPLICATION_MAIN(projet)
[/code][/spoiler]
comp.h
[spoiler][code]//
// Copyright © 2008-2015 the Urho3D project.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#pragma once
#include <Urho3D/Physics/CollisionShape.h>
#include “ModuleInfos.h”
using namespace Urho3D;
/// Custom component (that creates a ragdoll upon collision.)
class Module : public Component
{
URHO3D_OBJECT(Module, Component);
public:
/// Construct.
Module(Context* context);
void createRoom(Scene* scene, ResourceCache* cache);
void createCor(Scene* scene, ResourceCache* cache);
void createJunc(Scene* scene, ResourceCache* cache);
int type;
int exits;
protected:
/// Handle node being assigned.
virtual void OnNodeSet(Node* node);
private:
/// Handle scene node’s physics collision.
void OnCollisionEvent(StringHash eventType, VariantMap& eventData);
/*
/// Make a bone physical by adding RigidBody and CollisionShape components.
void CreateRagdollBone(const String& boneName, ShapeType type, const Vector3& size, const Vector3& position, const Quaternion& rotation);
/// Join two bones with a Constraint component.
void CreateRagdollConstraint(const String& boneName, const String& parentName, ConstraintType type, const Vector3& axis, const Vector3& parentAxis, const Vector2& highLimit, const Vector2& lowLimit, bool disableCollision = true);
*/
//to load different modules type infos
r_Rooms* room_p;
r_Cors* cor_p;
r_Juncs* junc_p;
};[/code][/spoiler]
comp.cpp
[spoiler][code]//
// Copyright © 2008-2015 the Urho3D project.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the “Software”), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Engine/Engine.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Input/InputEvents.h>
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Math/Vector3.h>
#include <Urho3D/Math/Quaternion.h>
#include <Urho3D/Graphics/Model.h>
#include <Urho3D/Graphics/AnimatedModel.h>
#include <Urho3D/Graphics/Material.h>
#include
#include
#include “fonctions.h”
#include “conversions.h”
#include “Counts.h”
#include “Exit.h”
#include “tinyxml2.h”
#include <Urho3D/IO/Log.h>
#include <Urho3D/DebugNew.h>
//physic
#include <Urho3D/Physics/CollisionShape.h>
//#include <Urho3D/Physics/PhysicsWorld.h>
#include <Urho3D/Physics/RigidBody.h>
#include <Urho3D/Physics/PhysicsEvents.h>
#include “CreateModule.h”
#include “ModuleInfos.h”
//#include “CreateExit.h”
using namespace Urho3D;
Module::Module(Context* context) :
Component(context),
type(0),
exits(0)
{
//context->RegisterFactory();
}
void Module::createRoom(Scene* scene, ResourceCache* cache)
{
room_p = new r_Rooms();
type = 0;
exits = room_p->exits;
std::string std_sceneName = IntString(id_, room_p->std_name);
String sceneName = string2urhoString(std_sceneName);
node_ = scene->CreateChild(sceneName);
node_->SetWorldPosition(Vector3::ZERO); //room.position
node_->SetWorldRotation(Quaternion::IDENTITY); //room.rotation (1,0,0,0)
//m_Object = new AnimatedModel();
AnimatedModel* m_Object = node_->CreateComponent<AnimatedModel>();
m_Object->SetModel(cache->GetResource<Model>(room_p->path));
m_Object->SetMaterial(cache->GetResource<Material>(room_p->texturepath));
//add physic
RigidBody* m_Body = node_->CreateComponent();
m_Body->SetMass(1); //0 for static object
m_Body->SetUseGravity(false);
m_Body->SetTrigger(true);
m_Body->SetFriction(0.6); // friction with other objects (like the ground)
m_Body->SetCollisionLayer(1);
//add collision shape
CollisionShape* m_BBox = node_->CreateComponent();
m_BBox->SetTriangleMesh(cache->GetResource(room_p->path));
//add light
Node* light=node_->CreateChild(“m_light”);
light->SetPosition(Vector3(0, 5, 0));
{
Light* Mlight=light->CreateComponent();
Mlight->SetLightType(LIGHT_POINT);
Mlight->SetRange(20);
Mlight->SetBrightness(1.0);
Mlight->SetColor(Color(.8,.8,.8,1.0));
}
/*
for(int x=0; x<exits; x++)
{
std::string std_exitName = stringInt("exit",x);
String name = string2urhoString(std_exitName);
Node* exitNode = node_->GetChild(name, true);
exitNode->CreateComponent<Exit>();
//make a vector there ?
Exit* tempExit = exitNode->GetComponent<Exit>();
tempExit->type = 0;
exit.type=room_p->type;
exit.position = exit.e_Node->GetWorldPosition();
exit.module_pos = Vector3::ZERO;
exitList.push_back(exit);
}
*/
}
void Module::createCor(Scene* scene, ResourceCache* cache)
{
cor_p = new r_Cors();
type = 1;
exits = cor_p->exits;
std::string std_sceneName = IntString(id_, cor_p->std_name);
String sceneName = string2urhoString(std_sceneName);
node_ = scene->CreateChild(sceneName);
node_->SetWorldPosition(Vector3::ZERO); //room.position
node_->SetWorldRotation(Quaternion::IDENTITY); //room.rotation (1,0,0,0)
//m_Object = new AnimatedModel();
AnimatedModel* m_Object = node_->CreateComponent<AnimatedModel>();
m_Object->SetModel(cache->GetResource<Model>(cor_p->path));
m_Object->SetMaterial(cache->GetResource<Material>(cor_p->texturepath));
//add physic
RigidBody* m_Body = node_->CreateComponent();
m_Body->SetMass(1); //0 for static object
m_Body->SetUseGravity(false);
m_Body->SetTrigger(true);
m_Body->SetFriction(0.6); // friction with other objects (like the ground)
m_Body->SetCollisionLayer(1);
//add collision shape
CollisionShape* m_BBox = node_->CreateComponent();
m_BBox->SetTriangleMesh(cache->GetResource(cor_p->path));
//add light
Node* light=node_->CreateChild(“m_light”);
light->SetPosition(Vector3(0, 5, 0));
{
Light* Mlight=light->CreateComponent();
Mlight->SetLightType(LIGHT_POINT);
Mlight->SetRange(20);
Mlight->SetBrightness(1.0);
Mlight->SetColor(Color(.8,.8,.8,1.0));
}
/*
for(int x=0; x<cor_p->exits; x++)
{
Exit tempExit;
std::string std_exitName = stringInt("exit",x);
exit.name = string2urhoString(std_exitName);
exit.type=cor_p->type;
exit.e_Node = node_->GetChild(exit.name, true);
exit.position = exit.e_Node->GetWorldPosition();
exit.module_pos = Vector3::ZERO;
exitList.push_back(exit);
}*/
}
void Module::createJunc(Scene* scene, ResourceCache* cache)
{
junc_p = new r_Juncs();
type = 2;
exits = junc_p->exits;
std::string std_sceneName = IntString(id_, junc_p->std_name);
String sceneName = string2urhoString(std_sceneName);
node_ = scene->CreateChild(sceneName);
node_->SetWorldPosition(Vector3::ZERO); //room.position
node_->SetWorldRotation(Quaternion::IDENTITY); //room.rotation (1,0,0,0)
//m_Object = new AnimatedModel();
AnimatedModel* m_Object = node_->CreateComponent<AnimatedModel>();
m_Object->SetModel(cache->GetResource<Model>(junc_p->path));
m_Object->SetMaterial(cache->GetResource<Material>(junc_p->texturepath));
//add physic
RigidBody* m_Body = node_->CreateComponent();
m_Body->SetMass(1); //0 for static object
m_Body->SetUseGravity(false);
m_Body->SetTrigger(true);
m_Body->SetFriction(0.6); // friction with other objects (like the ground)
m_Body->SetCollisionLayer(1);
//add collision shape
CollisionShape* m_BBox = node_->CreateComponent();
m_BBox->SetTriangleMesh(cache->GetResource(junc_p->path));
//add light
Node* light=node_->CreateChild(“m_light”);
light->SetPosition(Vector3(0, 5, 0));
{
Light* Mlight=light->CreateComponent();
Mlight->SetLightType(LIGHT_POINT);
Mlight->SetRange(20);
Mlight->SetBrightness(1.0);
Mlight->SetColor(Color(.8,.8,.8,1.0));
}
/*
for(int x=0; x<junc_p->exits; x++)
{
Exit tempExit;
std::string std_exitName = stringInt("exit",x);
exit.name = string2urhoString(std_exitName);
exit.type=junc_p->type;
exit.e_Node = node_->GetChild(exit.name, true);
exit.position = exit.e_Node->GetWorldPosition();
exit.module_pos = Vector3::ZERO;
exitList.push_back(exit);
}*/
}
//protected
void Module::OnNodeSet(Node* node)
{
// If the node pointer is non-null, this component has been created into a scene node. Subscribe to physics collisions that concern this scene node
if (node)
{
SubscribeToEvent(node, E_NODECOLLISIONSTART, URHO3D_HANDLER(Module, OnCollisionEvent));
URHO3D_LOGINFO(“node set”);
}
}
//private
void Module::OnCollisionEvent(StringHash eventType, VariantMap& eventData)
{
using namespace NodeCollision;
// Get the other colliding body
RigidBody* otherBody = static_cast<RigidBody*>(eventData[P_OTHERBODY].GetPtr());
//Node* otherNode = static_cast<Node*>(eventData[P_OTHERNODE].GetPtr());
if (otherBody->GetMass() > 0.0f)
{
URHO3D_LOGINFO("collide");
Light* light;
light = node_->GetComponent<Light>();
light->SetColor(Color(.8,.4,.4,1.0));
//m_Body->SetMass(1); //0 for static object
//m_Body->SetUseGravity(false);
//m_Body->SetTrigger(true);
// Finally remove self from the scene node. Note that this must be the last operation performed in the function
//Remove();
}
}[/code][/spoiler]