SHARE
TWEET

Torch.cpp

CUgopEntity Jan 23rd, 2019 16 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include "torch.h"
  3. #include "entity.h"
  4.  
  5. CTorch::CTorch(void) {
  6.     m_weight = .5f;
  7.     m_belt = true;
  8.     light_render            = ::Render->light_create();
  9.     light_render->set_type  (IRender_Light::SPOT);
  10.     light_render->set_shadow(true);
  11. }
  12.  
  13. CTorch::~CTorch(void) {
  14.     ::Render->light_destroy (light_render);
  15. }
  16.  
  17. void CTorch::Load(LPCSTR section) {
  18.     inherited::Load(section);
  19.     m_pos = pSettings->r_fvector3(section,"position");
  20. }
  21.  
  22. BOOL CTorch::net_Spawn(LPVOID DC) {
  23.     BOOL res = inherited::net_Spawn(DC);
  24.  
  25.     CKinematics* V = PKinematics(Visual());
  26.     if(V) V->PlayCycle("idle");
  27.  
  28.     light_render->set_range (300.f);
  29.     light_render->set_color (1.f,.8f,1.f);
  30.     light_render->set_cone  (PI_DIV_3);
  31.     light_render->set_texture(0);
  32.  
  33.     if (0==m_pPhysicsShell) {
  34.         // Physics (Box)
  35.         Fobb obb; Visual()->vis.box.get_CD(obb.m_translate,obb.m_halfsize); obb.m_rotate.identity();
  36.         // Physics (Elements)
  37.         CPhysicsElement* E = P_create_Element(); R_ASSERT(E); E->add_Box(obb);
  38.         // Physics (Shell)
  39.         m_pPhysicsShell = P_create_Shell(); R_ASSERT(m_pPhysicsShell);
  40.         m_pPhysicsShell->add_Element(E);
  41.         m_pPhysicsShell->setDensity(2000.f);
  42.         if(!H_Parent())m_pPhysicsShell->Activate(svXFORM(),0,svXFORM());
  43.         m_pPhysicsShell->mDesired.identity();
  44.         m_pPhysicsShell->fDesiredStrength = 0.f;
  45.     }
  46.  
  47.     setVisible(true);
  48.     setEnabled(true);
  49.  
  50.     return res;
  51. }
  52.  
  53. void CTorch::net_Destroy() {
  54.     if(m_pPhysicsShell) m_pPhysicsShell->Deactivate();
  55.     xr_delete(m_pPhysicsShell);
  56.     inherited::net_Destroy();
  57. }
  58.  
  59. void CTorch::OnH_A_Chield() {
  60.     inherited::OnH_A_Chield     ();
  61.     setVisible(false);
  62.     setEnabled(false);
  63.     svTransform.c.set(m_pos);
  64.     vPosition.set(svTransform.c);
  65.     light_render->set_active(true);
  66. }
  67.  
  68. void CTorch::OnH_B_Independent() {
  69.     inherited::OnH_B_Independent();
  70.     setVisible(true);
  71.     setEnabled(true);
  72.     CObject* E = dynamic_cast<CObject*>(H_Parent()); R_ASSERT(E);
  73.     svTransform.set(E->clXFORM());
  74.     vPosition.set(svTransform.c);
  75.     if(m_pPhysicsShell) {
  76.         Fmatrix trans;
  77.         Level().Cameras.unaffected_Matrix(trans);
  78.         Fvector l_fw; l_fw.set(trans.k);
  79.         Fvector l_up; l_up.set(svTransform.j); l_up.mul(2.f);
  80.         Fmatrix l_p1, l_p2;
  81.         l_p1.set(svTransform); l_p1.c.add(l_up); l_up.mul(1.2f);
  82.         l_p2.set(svTransform); l_p2.c.add(l_up); l_fw.mul(3.f); l_p2.c.add(l_fw);
  83.         m_pPhysicsShell->Activate(l_p1, 0, l_p2);
  84.         svTransform.set(l_p1);
  85.         vPosition.set(svTransform.c);
  86.     }
  87.     light_render->set_active(false);
  88. }
  89.  
  90. void CTorch::UpdateCL() {
  91.     inherited::UpdateCL();
  92.     if(getVisible() && m_pPhysicsShell) {
  93.         m_pPhysicsShell->Update ();
  94.         svTransform.set         (m_pPhysicsShell->mXFORM);
  95.         vPosition.set           (svTransform.c);
  96.     } else if(H_Parent()) {
  97.         Collide::ray_query RQ;
  98.         H_Parent()->setEnabled(false);
  99.         Fvector l_p, l_d; dynamic_cast<CEntity*>(H_Parent())->g_fireParams(l_p,l_d);
  100.         //Fmatrix l_cam; Level().Cameras.unaffected_Matrix(l_cam);
  101.         if(Level().ObjectSpace.RayPick(l_p, l_d, 500.f, RQ)) {
  102.             Fvector l_end, l_up; l_end.mad(l_p, l_d, RQ.range); l_up.set(0, 1.f, 0);
  103.             svTransform.k.sub(l_end, l_p); svTransform.k.normalize();
  104.             svTransform.i.crossproduct(l_up, svTransform.k); svTransform.i.normalize();
  105.             svTransform.j.crossproduct(svTransform.k, svTransform.i);
  106.         }
  107.         H_Parent()->setEnabled(true);
  108.     }
  109. }
  110.  
  111. void CTorch::OnVisible() {
  112.     if(getVisible() && !H_Parent()) {
  113.         ::Render->set_Transform     (&clTransform);
  114.         ::Render->add_Visual        (Visual());
  115.     } else {
  116.         light_render->set_direction (clTransform.k);
  117.         light_render->set_position  (clTransform.c);
  118.     }
  119. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top