Jump to content
  • Advertisement

PyemanKOP

Member
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

143 Neutral

About PyemanKOP

  • Rank
    Member
  1. Hi, I want to implement some sort of rotation gizmo,everything works find until i came to this problem that i want my object to rotate around its local axis. what i mean is when you rotate and object around x axis 90 degrees its local Y and Z axis axis also rotates, so i want to rotate based on these new axis. here is what i done so far: axisX = DirectX::XMVector3Transform(axisX, AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetActorFactory()-> GetActors()[0] ->GetComponent<AngelCore::AngelWorldSystem::Transform>()->GetWorldMatrix()); axisX = DirectX::XMVector3Normalize(axisX);   DirectX::XMVECTOR axisY = DirectX::XMVectorSet(0, 1, 0, 1); axisY = DirectX::XMVector3Transform(axisY, AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetActorFactory()-> GetActors()[0] ->GetComponent<AngelCore::AngelWorldSystem::Transform>()->GetWorldMatrix()); axisY = DirectX::XMVector3Normalize(axisY);   DirectX::XMVECTOR axisZ = DirectX::XMVectorSet(0, 0, 1, 1); axisZ = DirectX::XMVector3Transform(axisZ, AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetActorFactory()-> GetActors()[0] ->GetComponent<AngelCore::AngelWorldSystem::Transform>()->GetWorldMatrix()); axisZ = DirectX::XMVector3Normalize(axisZ); What above code do is rotate each axis based on object rotation. when i draw  a line for each axis they are in correct direction but when i try to rotate around them everything goes wrong! here is what i do to rotate: AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetActorFactory()-> GetActors()[0] ->GetComponent<AngelCore::AngelWorldSystem::Transform>()->GetRotation()->m_x += (axisInObject.m128_f32[0] * angle * axisX.m128_f32[0]); AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetActorFactory()-> GetActors()[0] ->GetComponent<AngelCore::AngelWorldSystem::Transform>()->GetRotation()->m_y += (axisInObject.m128_f32[0] * angle * axisX.m128_f32[1]); AngelCore::AngelSubSystem::SubSystemManager::GetInstance()->GetActorFactory()-> GetActors()[0] ->GetComponent<AngelCore::AngelWorldSystem::Transform>()->GetRotation()->m_z += (axisInObject.m128_f32[0] * angle * axisX.m128_f32[2]); Above code is just for axis X. but its not working! what is wrong with that? note that "axisInObject" is direction where user dragged mouse after click on axis X of rotation gizmo and angle is how many degrees he or she rotates that. thanks.
  2. Hi, I have a project where my task now is draw some arbitrary patterns on map. my idea was to draw this patterns using direct2d drawing function for point and other primitives and then pass this full patterned texture to pixel shader and show that texture on map. at first this idea seems correct and fit to this problem well. the pseudo code that maps 3d points to 2d space is this:   void AddPatternPoint(D3DXVECTOR3 p)// Gets Point On Map,so "p" is picked position on map. {    //suppose my texture is 800x800 that will send to shader i convert to 2d below:     D3DXVECTOR2 point2d;     point2d.x=p.x/limit.x;//limit is max value on map in x direction     point2d.y=p.z/limitz;//like limitx this is max value in z direction     point2d.x*=800;//scale to new coordinates     point2d.y*=800;     point2d.y=800-point2d.y;//revert coordinates as my coordinates is inverse in compare to direct2d coordinates.     //reset of the code is to save that point and draw it      }   after is pass this point to direct2d for drawing it will not map correctly to where i selected,also i have to mention that picking and finding point on map is well tested and is working well and correctly. any idea about what is wrong with this approach and this code? anyone have better idea to implement such feature? any DPI problem or something?   many thanks!
  3. PyemanKOP

    Auto Generate MipMap Not Working

      Assuming that you are actually using a supported format, then you should review the documentation for the helper function you're using; this one I assume (although you really should have said so).  Note the discussion around the maxsize parameter, how it interacts with miplevels, and ensure that the behaviour you're requesting is the behaviour you actually want.  Also note that you must be calling the overload that takes your context as a param if you wish it to generate mips for you.   Finally, since you're loading a DDS file, why are you generating mips at runtime anyway?  DDS is capable of storing pregenerated mips, so you could consider that instead. ok. now i use this function: HR(DirectX::CreateDDSTextureFromFileEx( AngelCore::AngelSubSystemResources::GraphicDeviceResources::Device.Get(), AngelCore::AngelSubSystemResources::GraphicDeviceResources::DeviceContext.Get() , path.c_str(),D3D10_FLOAT32_MAX,D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,0, D3D11_RESOURCE_MISC_GENERATE_MIPS,false, m_textureResource.GetAddressOf(), m_textureView.GetAddressOf())); but nothings changed! how i'm suppose to generate static mipmaps?
  4. PyemanKOP

    Auto Generate MipMap Not Working

    this function doesn't require anything,it will return shaderResourceView. i also use that d3dx11 function but nothing changed.
  5. PyemanKOP

    Auto Generate MipMap Not Working

    i use this function but it didn't fix my problem!
  6. i want to use SampleLevel to use different mipmap levels manually but its not working as below image shows: as the picture shows it always use level 0 texture!   here is my code for loading a texture i use Directx Textue tool for loading also i use dx11: HR(DirectX::CreateDDSTextureFromFileEx( AngelCore::AngelSubSystemResources::GraphicDeviceResources::Device.Get(), path.c_str(),MAXSIZE_T,D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,0, D3D11_RESOURCE_MISC_GENERATE_MIPS,false, m_textureResource.GetAddressOf(), m_textureView.GetAddressOf())); also i create my sampler state with below options: D3D11_FILTER_ANISOTROPIC,D3D11_TEXTURE_ADDRESS_WRAP, D3D11_TEXTURE_ADDRESS_WRAP , D3D11_TEXTURE_ADDRESS_WRAP,  D3D11_COMPARISON_ALWAYS what is the problem?
  7. PyemanKOP

    Vertex Skinning

    I'm working on vertex skinning by loading animation data from compiled model objects(.CMO) that visual studio generates from .FBX models. here is what i have: This is totaly wrong but i dont know why! here is my code for rendering animations: for (auto it = model->meshes.cbegin(); it != model->meshes.cend(); ++it) { auto mesh = it->get(); if (mesh->enableSkinning) { for (int i = 0;i < mesh->bones.size();i++) { mesh->armatureBuffer.Const.Bones[i]= mesh->bones[i]->LocalTransform; } //Animate Keyframe * lastKeyForBones =  new Keyframe[mesh->bones.size()]; bool *lerpedBones = new bool[mesh->bones.size()]; for (int i = 0;i < mesh->bones.size();i++) { //lerpedBones[i] = false; } for (int i = 0;i < mesh->animationClips[1]->Keys;i++) { Keyframe * frame = mesh->animationClips[1]->keyFrames[i]; if (elapsedTime >= frame->Time) { lastKeyForBones [frame->BoneIndex] = *frame; mesh->armatureBuffer.Const.Bones [frame->BoneIndex] = frame->Transform; } else { if (!lerpedBones [frame->BoneIndex]) { Keyframe * prevFrame; if (&lastKeyForBones [frame->BoneIndex] != nullptr) { prevFrame = &lastKeyForBones[frame->BoneIndex]; } else continue; lerpedBones[frame->BoneIndex] = true; float lenght = frame->Time - prevFrame->Time; float timeDiff = elapsedTime - prevFrame->Time; float amount = timeDiff / lenght; DirectX::XMVECTOR t1, t2, s1, s2, r1, r2; DirectX::XMMatrixDecompose( &s1, &r1, &t1, DirectX::XMLoadFloat4x4 (&prevFrame->Transform)); DirectX::XMMatrixDecompose( &s2, &r2, &t2, DirectX::XMLoadFloat4x4 (&frame->Transform)); DirectX::XMVECTOR lerpedScale = DirectX::XMVectorLerp(s1, s2, amount); DirectX::XMVECTOR lerpedtranslation = DirectX::XMVectorLerp(t1, t2, amount); DirectX::XMVECTOR lerpedrotation = DirectX::XMQuaternionSlerp(r1, r2, amount); DirectX::XMStoreFloat4x4 (&mesh->armatureBuffer.Const.Bones [frame->BoneIndex], DirectX::XMMatrixScaling( lerpedScale.m128_f32[0], lerpedScale.m128_f32[1], lerpedScale.m128_f32[2]) * DirectX::XMMatrixRotationQuaternion( lerpedrotation) * DirectX::XMMatrixTranslation( lerpedtranslation.m128_f32[0] , lerpedtranslation.m128_f32[1], lerpedtranslation.m128_f32[2])); } } } OutputDebugStringA("\n"); OutputDebugStringA(std::to_string(elapsedTime).c_str()); for (int i = 0;i < mesh->bones.size();i++) { if (mesh->bones[i]->ParentIndex>-1) { DirectX::XMFLOAT4X4 parentTransform = mesh->bones[mesh->bones[i]->ParentIndex]->LocalTransform; DirectX::XMStoreFloat4x4( &mesh->armatureBuffer.Const.Bones[i], DirectX::XMMatrixMultiply( DirectX::XMLoadFloat4x4(&mesh->armatureBuffer.Const.Bones[i]) , DirectX::XMLoadFloat4x4(&parentTransform))); } } for (int i = 0;i < mesh->bones.size();i++) { DirectX::XMStoreFloat4x4(&mesh->armatureBuffer.Const.Bones[i],  DirectX::XMMatrixTranspose( DirectX::XMMatrixMultiply( DirectX::XMLoadFloat4x4(&mesh->bones[i]->InvBindPos) , DirectX::XMLoadFloat4x4(&mesh->armatureBuffer.Const.Bones[i])))); } if (elapsedTime > mesh->animationClips[1]->end) { elapsedTime = 0.0f; } } } elapsedTime += timer.GetElapsedSeconds(); the animation plays but the model seems messing up! i think there is something wrong with matrix constructions. also i adapt this code from Direct3D rendering cook book that its written in C#! Also model render correctly when i render it without skinning. also here is vertex shade code: PS_IN_MESH OUT = (PS_IN_MESH)0; float4x3 skinning = 0; [unroll] for (int i = 0; i <2 ; i++) { skinning += Bones[IN.Indices[i]] * IN.Weights[i]; } float3 skinnedPos = mul(IN.PosL, skinning); OUT.position = mul(float4(skinnedPos,1.0f), WVP); OUT.positionVS = mul((IN.PosL), World).xyz; OUT.texCoord = IN.UV; //OUT.tangentVS = mul(IN.Tangent, World).xyz; OUT.normalVS = mul(IN.Normal, World).xyz; float4 posCurrent = OUT.position; float4 posLast= mul((IN.PosL), WVPLast); //posCurrent /= posCurrent.w; //posLast /= posLast.w; float2 velocity = posCurrent - posLast; velocity /= 2.0f; OUT.velocity = velocity; OUT.binormalVS = cross(OUT.tangentVS, OUT.normalVS); OUT.shadowPosH = mul((IN.PosL), World); OUT.shadowPosH = mul(OUT.shadowPosH, lightViewMatrix); OUT.shadowPosH = mul(OUT.shadowPosH, lightProjectionMatrix); //Skinning //if (IN.Weights.x != 0) return OUT; Any one have idea what is wrong with it? if you want more information tell me :)
  8. I want to implement an on board GUI where i first select a area and then i can write something in it but i'm stuck in first part where i have to select Billboard Text, here is my Code for Picking:     POINT ptCursor;     GetCursorPos(&ptCursor);     ScreenToClient(AngelCore::AngelSubSystemResources::WindowProperties::GetHWND(), &ptCursor);          UINT numOfVP = 1;     D3D11_VIEWPORT vp;     AngelCore::AngelSubSystemResources::GraphicDeviceResources::GetDeviceContext3D()->RSGetViewports(&numOfVP, &vp);               DirectX::XMFLOAT3 v;     v.x = (((2.0f * ptCursor.x) / vp.Width) - 1) / proj4X4._11;     v.y = -(((2.0f * ptCursor.y) / vp.Height) - 1) / proj4X4._22;     v.z = -1.0f;          DirectX::XMMATRIX translation = DirectX::XMMatrixTranslation(          DirectX::XMVectorGetX(     AngelCore::AngelSubSystemResources::BaseCameraProperties::BCamera.GetCameraPosition())     , DirectX::XMVectorGetY(     AngelCore::AngelSubSystemResources::BaseCameraProperties::BCamera.GetCameraPosition())     , DirectX::XMVectorGetZ(     AngelCore::AngelSubSystemResources::BaseCameraProperties::BCamera.GetCameraPosition()));          DirectX::XMMATRIX worldView = View;     DirectX::XMMATRIX inv = DirectX::XMMatrixInverse(nullptr, worldView);     DirectX::XMFLOAT4X4 invWorldView4X4;     DirectX::XMStoreFloat4x4(&invWorldView4X4, inv);          DirectX::XMFLOAT3 vPickRayDir;     DirectX::XMFLOAT3 vPickRayOrig;          vPickRayDir.x = v.x * invWorldView4X4._11 + v.y * invWorldView4X4._21 + v.z * invWorldView4X4._31;     vPickRayDir.y = v.x * invWorldView4X4._12 + v.y * invWorldView4X4._22 + v.z * invWorldView4X4._32;     vPickRayDir.z = v.x * invWorldView4X4._13 + v.y * invWorldView4X4._23 + v.z * invWorldView4X4._33;     vPickRayOrig.x = invWorldView4X4._41;     vPickRayOrig.y = invWorldView4X4._42;     vPickRayOrig.z = invWorldView4X4._43;          DirectX::XMFLOAT3 rayObjOrigin, rayObjDirection;          DirectX::XMVECTOR rayOrig =  DirectX::XMVector3TransformCoord(DirectX::XMVectorSet(     vPickRayOrig.x, vPickRayOrig.y, vPickRayOrig.z, 1.0f), invWorld);          DirectX::XMVECTOR rayDir = DirectX::XMVector3TransformNormal(DirectX::XMVectorSet(     vPickRayDir.x, vPickRayDir.y, vPickRayDir.z, 1.0f), invWorld);          rayDir = DirectX::XMVector3Normalize(rayDir);     float dist = 0;     if (b.Intersects(rayOrig,     rayDir, dist))     {     return true;     } Here is the details: Matrix translation do nothing. "b" is the bounding box from the object that i want to check for ray intersection. I also pass inverse world matrix to this function.     My code won't work correctly,it's like bounding box is moving with camera,every time i move camera it shows intersection in different position!
  9. I want to pick objects from distance(whenever it's visible to the camera) but i have problem with it. here what i'v done so far:       DirectX::XMFLOAT4X4 projection;     DirectX::XMStoreFloat4x4(&projection,AngelSubSystemResources::BaseCameraProperties::BCamera.GetProjection());     float vx = (((2 * this->m_mouseX) / AngelSubSystemResources::WindowProperties::GetWidth()) - 1)/projection._11;     float vy = (((-2 * this->m_mouseY) / AngelSubSystemResources::WindowProperties::GetHeight()) + 1) / projection._22;     DirectX::XMVECTOR rayOrigin = XMVectorSet(0.0f,0.0f,0.0f,1.0f);         DirectX::XMVECTOR rayDir = DirectX::XMVectorSet(vx, vy, 1.0f, 0.0f);          DirectX::XMMATRIX view = AngelSubSystemResources::BaseCameraProperties::BCamera.GetView();          DirectX::XMMATRIX toWorld = DirectX::XMMatrixInverse(&DirectX::XMMatrixDeterminant(view), view);          rayOrigin = DirectX::XMVector3TransformCoord(rayOrigin, toWorld);     rayDir = DirectX::XMVector3TransformNormal(rayDir, toWorld);     rayDir = DirectX::XMVector3Normalize(rayDir);     XMVECTOR ray = rayOrigin + (rayDir * 100);     float x = DirectX::XMVectorGetX(rayDir);     float y = DirectX::XMVectorGetY(rayDir);     float z = DirectX::XMVectorGetZ(rayDir);                   /*OutputDebugStringA("\nX:");     OutputDebugStringA(std::to_string(x).c_str());     OutputDebugStringA("\nY:");     OutputDebugStringA(std::to_string(y).c_str());     OutputDebugStringA("\nZ:");     OutputDebugStringA(std::to_string(z).c_str());*/     float f = 0;     for (auto const & member : allAABB)     {     if (IntersectRayAxisAlignedBox(rayOrigin, rayDir, member->boundingBox, &f))     {     //if (member->name == "Plant")     {     OutputDebugStringA("\n++++Intersect with:");     OutputDebugStringA(std::to_string(f).c_str());     OutputDebugStringA("+++++++++\n\n");     }         }     OutputDebugStringA("\n++++NOT INTERSECTIGN+++++++");     }   in this function i check for intersection between mouse and mesh, and here is the function that checks it:       static inline BOOL XMVector3AnyTrue(FXMVECTOR V)     {     XMVECTOR C;          // Duplicate the fourth element from the first element.     C = XMVectorSwizzle(V, 0, 1, 2, 0);          return XMComparisonAnyTrue(XMVector4EqualIntR(C, XMVectorTrueInt()));     }               BOOL IntersectRayAxisAlignedBox(FXMVECTOR Origin, FXMVECTOR Direction, BoundingBox pVolume, FLOAT* pDist)     {     static const XMVECTOR Epsilon =     {     1e-20f, 1e-20f, 1e-20f, 1e-20f     };     static const XMVECTOR FltMin =     {     -FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX     };     static const XMVECTOR FltMax =     {     FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX     };          // Load the box.     XMVECTOR Center = XMLoadFloat3(&pVolume.Center);     XMVECTOR Extents = XMLoadFloat3(&pVolume.Extents);          // Adjust ray origin to be relative to center of the box.     XMVECTOR TOrigin = Center - Origin;          // Compute the dot product againt each axis of the box.     // Since the axii are (1,0,0), (0,1,0), (0,0,1) no computation is necessary.     XMVECTOR AxisDotOrigin = TOrigin;     XMVECTOR AxisDotDirection = Direction;          // if (fabs(AxisDotDirection) <= Epsilon) the ray is nearly parallel to the slab.     XMVECTOR IsParallel = XMVectorLessOrEqual(XMVectorAbs(AxisDotDirection), Epsilon);          // Test against all three axii simultaneously.     XMVECTOR InverseAxisDotDirection = XMVectorReciprocal(AxisDotDirection);     XMVECTOR t1 = (AxisDotOrigin - Extents) * InverseAxisDotDirection;     XMVECTOR t2 = (AxisDotOrigin + Extents) * InverseAxisDotDirection;          // Compute the max of min(t1,t2) and the min of max(t1,t2) ensuring we don't     // use the results from any directions parallel to the slab.     XMVECTOR t_min = XMVectorSelect(XMVectorMin(t1, t2), FltMin, IsParallel);     XMVECTOR t_max = XMVectorSelect(XMVectorMax(t1, t2), FltMax, IsParallel);          // t_min.x = maximum( t_min.x, t_min.y, t_min.z );     // t_max.x = minimum( t_max.x, t_max.y, t_max.z );     t_min = XMVectorMax(t_min, XMVectorSplatY(t_min));  // x = max(x,y)     t_min = XMVectorMax(t_min, XMVectorSplatZ(t_min));  // x = max(max(x,y),z)     t_max = XMVectorMin(t_max, XMVectorSplatY(t_max));  // x = min(x,y)     t_max = XMVectorMin(t_max, XMVectorSplatZ(t_max));  // x = min(min(x,y),z)          // if ( t_min > t_max ) return FALSE;     XMVECTOR NoIntersection = XMVectorGreater(XMVectorSplatX(t_min), XMVectorSplatX(t_max));          // if ( t_max < 0.0f ) return FALSE;     NoIntersection = XMVectorOrInt(NoIntersection, XMVectorLess(XMVectorSplatX(t_max), XMVectorZero()));          // if (IsParallel && (-Extents > AxisDotOrigin || Extents < AxisDotOrigin)) return FALSE;     XMVECTOR ParallelOverlap = XMVectorInBounds(AxisDotOrigin, Extents);     NoIntersection = XMVectorOrInt(NoIntersection, XMVectorAndCInt(IsParallel, ParallelOverlap));               if (!XMVector3AnyTrue(NoIntersection))     {     // Store the x-component to *pDist     XMStoreFloat(pDist, t_min);     return TRUE;     }          return FALSE;     }   But the result is when i come very close to the mesh it shows that i'v got an intersection but as i mention i want to pick this mesh whenever player can see the mesh no matter how far it is! anyone can help me please?
  10. PyemanKOP

    AngelScript class property with indirection

    Hey! :) That fixed my problem thanks :)
  11. PyemanKOP

    AngelScript class property with indirection

    I have an actor factory class that represent creating and destroying actors. here is code: class ActorsFactory { public: ActorsFactory(); void Update(); ~ActorsFactory(); void Start(); private: std::vector<Actor*> m_actors; Actor *SpawnObject(const std::string &type, char dispChar, int x, int y); }; extern ActorsFactory *factory; Actorfactory.cpp: ActorsFactory::ActorsFactory() { } ActorsFactory::~ActorsFactory() { } void ActorsFactory::Update() { //for (int i = 0;i < 200;i++) for (unsigned int n = 0; n < m_actors.size(); n++) m_actors[n]->Update(); } Actor *ActorsFactory::SpawnObject(const std::string &type, char dispChar, int x, int y) { Actor *obj = new Actor(); m_actors.push_back(obj); // Set the controller based on type obj->controller = scriptMgr->CreateController(type, obj); return obj; } void ActorsFactory::Start() { // Create the player Actor *obj = SpawnObject("player", 'p', rand() % 10, rand() % 10); obj->Start(); //Actor *obj1 = SpawnObject("enemy", 'p', rand() % 10, rand() % 10); //obj1->Start(); // Check if there were any compilation errors during the script loading if (scriptMgr->hasCompileErrors) { std::cout << "SCRIPT COMPILT ERROR"; } //return -1; } And below is the result of script and code as you see position.x in script is different from actual code! Current is called in actor.cpp Update function to print position.x in c++.     And Here is the full solution you can test it on you own ;) http://s000.tinyupload.com/?file_id=04822932865189830393
  12. PyemanKOP

    AngelScript class property with indirection

    Thanks for response. I got no error at all! i just do that for test,position is pointer but rotation is not as i want to test that. Here is my transform.cpp Transform::Transform() { this->position = new AngelCore::AngelTools::AngelMathHelper::Vector<3>(); /*this->rotation= new AngelCore::AngelTools::AngelMathHelper::Vector<3>(); this->scalling = new AngelCore::AngelTools::AngelMathHelper::Vector<3>();;*/ } Transform::~Transform() { } Yeah i'm sure that i have correct refrence to transform and also position as you can see i print Position->x property in actor.cpp in update function. I want to register Position as refrence type is that correct to use @? i saw in documentation that i have to us e& but it gave me error!
  13. I have a class named "Actor" that has a pointer to class "Transform" that represent actors position; here is Actor.h:   using namespace DirectX; class Actor { public: Actor(); void Update(); void Render(); void Start(); int AddRef(); int Release(); asILockableSharedBool *GetWeakRefFlag(); void Send(CScriptHandle msg, Actor *other); const char * GetName() { return this->m_name; } int GetX() { return this->x3; } int GetY() { return this->y; } void SetX(int _x) { this->x3 = _x; } public: int                    refCount; asILockableSharedBool *weakRefFlag; const char *m_name; int x3;; int y; int z; bool active; AngelCore::AngelTools::AngelMathHelper::Vector<3> rotation; AngelCore::AngelTools::AngelMathHelper::Vector<3> *Position; asIScriptObject *controller; Transform  *t; ~Actor(); }; And Actor.cpp asILockableSharedBool *Actor::GetWeakRefFlag() {  if (!weakRefFlag)   weakRefFlag = asCreateLockableSharedBool();  return weakRefFlag; } void Actor::Start() {  //this->t = new Transform();  scriptMgr->Start(controller); } int Actor::AddRef() {  return ++refCount; } int Actor::Release() {  if (--refCount == 0)  {   delete this;   return 0;  }  return refCount; } void Actor::Send(CScriptHandle msg, Actor *other) {  if (other && other->controller)   scriptMgr->OnSendMessage(other->controller, msg, this); } Actor::Actor() {  refCount = 1;  this->t = new Transform();  //t->position->y = 150;  this->x3= 21000;  this->y = 510;  controller = 0;  //this->active = true;  weakRefFlag = 0; } void Actor::Update() {  scriptMgr->Update(controller); //HERE I WANT THIS VALUE BE SAME AS IN SCRIPT******************************************************  std::cout << "\n\n\nCurrent : " << this->t->position->x; } and Transform.h: class Transform { public: Transform(); ~Transform(); public: AngelCore::AngelTools::AngelMathHelper::Vector<3> *position; AngelCore::AngelTools::AngelMathHelper::Vector<3> rotation; AngelCore::AngelTools::AngelMathHelper::Vector<3> scalling; }; in my script manager i register "t" as one of actors properties:(t is actor pointer to class transform) engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); // Set the message callback to print the human readable messages that the engine gives in case of errors r = engine->SetMessageCallback(asMETHOD(ScriptManager, MessageCallback), this, asCALL_THISCALL); assert( r >= 0 ); // Register the string type RegisterStdString(engine); // Register the generic handle type, called 'ref' in the script RegisterScriptHandle(engine); // Register the weak ref template type RegisterScriptWeakRef(engine); // Register the game object. The scripts cannot create these directly, so there is no factory function. r = engine->RegisterObjectType("Actor", sizeof(Actor)*10, asOBJ_REF); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_ADDREF, "void f()", asMETHOD(Actor, AddRef), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_RELEASE, "void f()", asMETHOD(Actor, Release), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_GET_WEAKREF_FLAG, "int &f()", asMETHOD(Actor, GetWeakRefFlag), asCALL_THISCALL); assert( r >= 0 ); // The object's position is read-only to the script. The position is updated with the Move method r = engine->RegisterObjectMethod("Actor", "int get_x() const", asMETHOD(Actor, GetX), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod("Actor", "int get_y() const", asMETHOD(Actor, GetY), asCALL_THISCALL); assert( r >= 0 ); RegisterType<Transform>("Transform"); RegisterType<Vector3>("Vector3"); RegisterType<Vector2>("Vector2"); RegisterType<Vector4>("Vector4"); r = engine->RegisterObjectProperty("Vector3", "float x", asOFFSET(Vector3, x)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector3", "float y", asOFFSET(Vector3, y)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector3", "float z", asOFFSET(Vector3, z)); r = engine->RegisterObjectProperty("Vector2", "float x", asOFFSET(Vector2, x)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector2", "float y", asOFFSET(Vector2, y)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector4", "float x", asOFFSET(Vector4, x)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector4", "float y", asOFFSET(Vector4, y)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector4", "float z", asOFFSET(Vector4, z)); r = engine->RegisterObjectProperty("Vector4", "float w", asOFFSET(Vector4, w)); struct MyStruct { Vector3 * a = new Vector3(); MyStruct() { a->x = 12; } }; MyStruct * m = new MyStruct(); //REGISTER TRANSFORM POSITION /*/*/*/*/************************************************************** r = engine->RegisterObjectProperty("Transform", "Vector3 @position", asOFFSET(Transform, position)); //r = engine->RegisterGlobalProperty("Vector3 &data", data); if (r < 0) return r; r = engine->RegisterObjectProperty("Transform", "Vector3 rotation", asOFFSET(Transform, rotation)); if (r < 0) return r; r = engine->RegisterObjectProperty("Transform", "Vector3 scalling", asOFFSET(Transform, scalling)); if (r < 0) return r; //assert(r >= 0); engine->RegisterObjectProperty("Actor", "Vector3 Position", asOFFSET(Actor, Position)); //HERE I REGISTER t /*//*/*/*/*/*/*/*/*/********************************************************************* r = engine->RegisterObjectProperty("Actor", "Transform @transform", asOFFSET(Actor, t)); r = engine->RegisterObjectProperty("Actor", "bool active", asOFFSET(Actor, active)); r = engine->RegisterObjectMethod("Actor", "void Send(ref msg, const Actor @+ to)", asMETHOD(Actor, Send), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterGlobalFunction("void DebugString(string &in)", asFUNCTION(Print), asCALL_CDECL); above is registeration of all properties so far. my problem is when i change actors transform from script file like below the actual actor transform in .cpp file is not changed! I mean i want that a change from user in transform position in script take effect in c++ file but it dose not! And here is my AngelScript code: class Player : Component { // The constructor must take a CGameObj handle as input, // this is the object that the script will control Player(Actor @obj) { // Keep the owner for later reference @self = obj; } float ChangeValue(int x) { return x+=150; } void Start() { self.transform.position.x=42242; self.transform.rotation.y=1; self.transform.scalling.z=2; DebugString("StartCalled \n \n ++++++++++++++++++++"); self.active=false; //self.Position.x=10000; } void Update() { bool data; DebugString("Active : " + self.active); DebugString("\n Transform PositionY:" + self.transform.position.x); DebugString("\n Transform RotationX:" + self.transform.rotation.y); DebugString("\n Transform ScallingZ:" + self.transform.scalling.z); //self.transform.position.y++; } Actor @self; } Thanks!      
  14. I have a class named "Actor" that has a pointer to class "Transform" that represent actors position; here is Actor.h: class Actor { public:  Actor();  void Update();  void Render();  void Start();  int AddRef();  int Release();  asILockableSharedBool *GetWeakRefFlag();  void Send(CScriptHandle msg, Actor *other);  const char * GetName() { return this->m_name; }  int GetX() { return this->x3; }  int GetY() { return this->y; }    void SetX(int _x) { this->x3 = _x; } public:  int                    refCount;  asILockableSharedBool *weakRefFlag;  const char *m_name;  int x3;;  int y;  int z;  bool active;  AngelCore::AngelTools::AngelMathHelper::Vector<3> rotation;  AngelCore::AngelTools::AngelMathHelper::Vector<3> Position;  asIScriptObject *controller;  Transform  *t;  ~Actor(); }; And Actor.cpp   asILockableSharedBool *Actor::GetWeakRefFlag() {  if (!weakRefFlag)   weakRefFlag = asCreateLockableSharedBool();  return weakRefFlag; } void Actor::Start() {  //this->t = new Transform();  scriptMgr->Start(controller); } int Actor::AddRef() {  return ++refCount; } int Actor::Release() {  if (--refCount == 0)  {   delete this;   return 0;  }  return refCount; } void Actor::Send(CScriptHandle msg, Actor *other) {  if (other && other->controller)   scriptMgr->OnSendMessage(other->controller, msg, this); } Actor::Actor() {  refCount = 1;  this->t = new Transform();  //t->position->y = 150;  this->x3= 21000;  this->y = 510;  controller = 0;  //this->active = true;  weakRefFlag = 0; } void Actor::Update() {  scriptMgr->Update(controller); //HERE I WANT THIS VALUE BE SAME AS IN SCRIPT******************************************************  std::cout << "\n\n\nCurrent : " << this->t->position->x;   } and Transform.h: class Transform { public:  Transform();  ~Transform(); public:  AngelCore::AngelTools::AngelMathHelper::Vector<3> *position;  AngelCore::AngelTools::AngelMathHelper::Vector<3> rotation;  AngelCore::AngelTools::AngelMathHelper::Vector<3> scalling; };   in my script manager i register "t" as one of actors properties: engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); // Set the message callback to print the human readable messages that the engine gives in case of errors r = engine->SetMessageCallback(asMETHOD(ScriptManager, MessageCallback), this, asCALL_THISCALL); assert( r >= 0 ); // Register the string type RegisterStdString(engine); // Register the generic handle type, called 'ref' in the script RegisterScriptHandle(engine); // Register the weak ref template type RegisterScriptWeakRef(engine); // Register the game object. The scripts cannot create these directly, so there is no factory function. r = engine->RegisterObjectType("Actor", sizeof(Actor), asOBJ_REF | asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_ADDREF, "void f()", asMETHOD(Actor, AddRef), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_RELEASE, "void f()", asMETHOD(Actor, Release), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("Actor", asBEHAVE_GET_WEAKREF_FLAG, "int &f()", asMETHOD(Actor, GetWeakRefFlag), asCALL_THISCALL); assert( r >= 0 ); // The object's position is read-only to the script. The position is updated with the Move method r = engine->RegisterObjectMethod("Actor", "int get_x() const", asMETHOD(Actor, GetX), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod("Actor", "int get_y() const", asMETHOD(Actor, GetY), asCALL_THISCALL); assert( r >= 0 ); RegisterType<Transform>("Transform"); RegisterType<Vector3>("Vector3"); RegisterType<Vector2>("Vector2"); RegisterType<Vector4>("Vector4"); r = engine->RegisterObjectProperty("Vector3", "float x", asOFFSET(Vector3, x)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector3", "float y", asOFFSET(Vector3, y)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector3", "float z", asOFFSET(Vector3, z)); ? r = engine->RegisterObjectProperty("Vector2", "float x", asOFFSET(Vector2, x)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector2", "float y", asOFFSET(Vector2, y)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector4", "float x", asOFFSET(Vector4, x)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector4", "float y", asOFFSET(Vector4, y)); if (r < 0) return r; r = engine->RegisterObjectProperty("Vector4", "float z", asOFFSET(Vector4, z)); r = engine->RegisterObjectProperty("Vector4", "float w", asOFFSET(Vector4, w)); //REGISTER TRANSFORM POSITION /*/*/*/*/************************************************************** r = engine->RegisterObjectProperty("Transform", "Vector3 @position", asOFFSET(Transform, position)); //r = engine->RegisterGlobalProperty("Vector3 &data", data); if (r < 0) return r; r = engine->RegisterObjectProperty("Transform", "Vector3 rotation", asOFFSET(Transform, rotation)); if (r < 0) return r; r = engine->RegisterObjectProperty("Transform", "Vector3 scalling", asOFFSET(Transform, scalling)); if (r < 0) return r; //assert(r >= 0); engine->RegisterObjectProperty("Actor", "Vector3 Position", asOFFSET(Actor, Position)); //HERE I REGISTER t /*//*/*/*/*/*/*/*/*/********************************************************************* engine->RegisterObjectProperty("Actor", "Transform @transform", asOFFSET(Actor, t));       above is registeration of all properties so far. my problem is when i change actors transform from script file like below the actual actor transform in .cpp file is not changed! void Start()  {   self.transform.position.x=42242;   self.transform.rotation.y=1;   self.transform.scalling.z=2;   DebugString("StartCalled \n \n ++++++++++++++++++++");   self.active=false;   self.Position.x=10000;  }  void Update()  {   bool data;   DebugString("Active : " + self.active);    DebugString("\n Transform PositionY:" + self.transform.position.x);// IT PRINTS 42242 BUT IN ACTOR.cpp IT PRINTS A DEFAULT UNKOWN VALUE //I WANT THESE TO VALUE BE SAME! ?   DebugString("\n Transform RotationX:" + self.transform.rotation.y);   DebugString("\n Transform ScallingZ:" + self.transform.scalling.z);   //self.transform.position.y++;  }   what is the problem? ?I have to mention that when I delete pointers and register properties normally it works well.  
  15.   ?I write two custom memory allocators because I thought that my problem was from memory pool,but when I test a new type of custom memory allocation I realize that my problem is from classes inheritance. I have a base class IComponent you can see code below: virtual ~IComponent() {}     #pragma region Setter            void SetActive(bool _active) { this->m_active = _active; }            void SetName(const char * _name) { this->m_name = _name; }         #pragma endregion           public:         #pragma region Getter            bool GetActive() const { return this->m_active; }            const char * GetName() const { return this->m_name; }         #pragma endregion           public:            virtual void Initialize(Actor * _owner) = 0;            virtual void Update(const AngelSubSystem::TimeManager &timer) = 0;            virtual void Render() = 0;           protected:            Actor* GetOwner()             { return this->m_owner; }                void SetOwner(Actor * _owner)          { this->m_owner = _owner; }           private:            bool      m_active;        const char *    m_name;        Actor *     m_owner; And I have a component name GUIText that inherit from this class: protected:   virtual void Initialize(ActorPtr _owner) override;   virtual void Update(const AngelSubSystem::TimeManager &timer) override;   virtual void Render() override;  private:   Vector3 *               m_position;   Vector3 *               m_scalling;   Vector3 *               m_rotation; some code omitted. when I use my custom allocator like blow I got this error:      Access violation reading location 0xCDCDCDD1 this->m_componentMemory = new AngelMemory::LinearAllocator();      this->m_componentMemory->Init(2000);     GUIText * t = reinterpret_cast<GUIText*>(this->m_componentMemory->Allocate(sizeof(GUIText)));      t->Initialize(this); I find my problem that it is from inheritance and polymorphism but my question is how I can fix this? Here is my custom allocator: void AngelCore::AngelMemory::LinearAllocator::Init(size_t size)         {          this->m_currentPos = malloc(size);          this->m_size = size;          this->m_numAllocation = 0;          this->m_usedMemory = 0;         }                 void *AngelCore::AngelMemory::LinearAllocator::Allocate(size_t size)         {          void *address = m_currentPos;                    this->m_usedMemory += size;                   return (void*)address;     }  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!