Advertisement
Guest User

drone bug

a guest
Oct 6th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.70 KB | None | 0 0
  1. /// Code for rotation
  2.  
  3. /// Set target
  4.         Vector3 TargetPosition(2.0f,2.0f,2.0f);
  5.  
  6.  
  7.         /// Get Cross product to get a angle
  8.         Vector3 currentForwardUnit=Vector3(1.0f,1.0f,1.0f);
  9.         Vector3 newForwardUnit = Vector3(TargetPosition-ThisBody->GetPosition()).Normalized();
  10.  
  11.         /// Get Rotation and Axis
  12.         Vector3 rotAxis= currentForwardUnit.CrossProduct(newForwardUnit);
  13.         float rotAngle=acos(currentForwardUnit.DotProduct(newForwardUnit));
  14.  
  15.         /// Create a quaternion
  16.         Quaternion rot(rotAngle,rotAxis);
  17.  
  18.         /// Set Rotation
  19.         ThisBody->SetRotation(ThisBody->GetRotation()*rot);
  20.  
  21.  
  22. ///////// drone creation
  23.  
  24.     /// Create needed filenames
  25.         String temporarymodelfilename;
  26.         String temporarytexturefilename;
  27.         Node * ObjectStaticNode;
  28.         StaticModel * ObjectStaticModel;
  29.         /// first one
  30.         temporaryfilename.Clear();
  31.  
  32.         temporaryfilename.Append("Resources/Models/");
  33.  
  34.         /// Create a resource filename
  35.         temporaryfilename.Append("ExoComp2");
  36.  
  37.         /// wall or other component
  38.         temporarymodelfilename=temporaryfilename+String(".mdl");
  39.         temporarytexturefilename=temporaryfilename+String(".txt");
  40.  
  41.         ObjectStaticNode= Existence->scene_ -> CreateChild("ExoComp2");
  42.  
  43.         ObjectStaticModel = ObjectStaticNode->CreateComponent<StaticModel>();
  44.  
  45.         ObjectStaticModel ->SetModel(cache->GetResource<Model>(temporarymodelfilename));
  46.         ObjectStaticModel ->ApplyMaterialList(temporarytexturefilename);
  47.  
  48.         ObjectStaticModel ->SetCastShadows(true);
  49.  
  50.         ObjectStaticNode->SetPosition(Vector3(4,1.5f,1));
  51.  
  52.         /// Create rigidbody, and set non-zero mass so that the body becomes dynamic
  53.         RigidBody * ObjectRigidBody = ObjectStaticNode->CreateComponent<RigidBody>();
  54.         ObjectRigidBody->SetCollisionLayer(1);
  55.  
  56.         /// Turn off Gravity
  57.         ObjectRigidBody->SetMass(1.2f);
  58.         ObjectRigidBody->SetUseGravity(true);
  59.         ObjectRigidBody->SetAngularDamping(0.6f);
  60.         ObjectRigidBody->SetLinearDamping(0.6f);
  61.  
  62.         /// Set zero angular factor so that physics doesn't turn the character on its own.
  63.         /// Instead we will control the character yaw manually
  64.         ObjectRigidBody->SetAngularFactor(Vector3::ONE);
  65.  
  66.         /// Set the rigidbody to signal collision also when in rest, so that we get ground collisions properly
  67.         ObjectRigidBody->SetCollisionEventMode(COLLISION_ALWAYS);
  68.  
  69.         Model * ExoComp2Collision = cache->GetResource<Model>(String("Resources/Models/ExoComp2Collision.mdl"));
  70.  
  71.         /// Set a capsule shape for collision
  72.         CollisionShape* ObjectShape = ObjectStaticNode->CreateComponent<CollisionShape>();
  73.  
  74.         /// Set shape collision
  75.         ObjectShape->SetConvexHull(ExoComp2Collision);
  76.         ObjectShape->SetLodLevel(1);
  77.         ObjectShape->SetMargin(0.1f);
  78.  
  79.         /// Created Drone
  80.         Drone * CreatedDrone = ObjectStaticNode->CreateComponent<Drone>();
  81.  
  82.         /// Create Drone information
  83.         DroneInformation SetDrone;
  84.         SetDrone.AlienAllianceAligned=0;
  85.         SetDrone.AlienRace=0;
  86.         SetDrone.DroneType=Drone100Beta;
  87.         SetDrone.Name = String("test");
  88.  
  89.         CreatedDrone->SetNode(ObjectStaticNode);
  90.         CreatedDrone->SetParameters(SetDrone);
  91.         CreatedDrone->Initialize();
  92.  
  93.         ResourceNodeComponent * DroneResourceComponent2=ObjectStaticNode -> CreateComponent<ResourceNodeComponent>();
  94.         DroneResourceComponent2->SetResourceComponentNameType(String("ExoComp1"), RCType_Drone);
  95.         DroneResourceComponent2->MapResources(Existence->ResourcesManager);
  96.  
  97.         ObjectStaticNode->CreateComponent<InteractObject>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement