Jump to content

  • Log In with Google      Sign In   
  • Create Account


Dissipate

Member Since 31 Oct 2012
Offline Last Active Sep 15 2014 06:41 PM

#5175708 Setting a path for objects

Posted by Dissipate on 23 August 2014 - 05:59 PM

Oops maybe the SetPath call needs to be just above the IF statement so that it sets all object's properties.




#5175706 Setting a path for objects

Posted by Dissipate on 23 August 2014 - 05:54 PM

Sorry for the confusion. Ok so instead of:

float Scalar = (float)timeGetTime();
Scalar = (Scalar -StartTime) * 0.0003f;
 
if(CurrentPath == 1)
{
stVector diff;
diff.x = Path[1].x - Path[0].x;
diff.y = Path[1].y - Path[0].y;
diff.z = Path[1].z - Path[0].z;
 
float len = (float)sqrt((diff.x * diff.x +
                   diff.y * diff.y +
diff.z * diff.z));
Scalar = Scalar / len;
objPos.x = (Path[1].x - Path[0].x) * Scalar + Path[0].x;
objPos.y = (Path[1].y - Path[0].y) * Scalar + Path[0].y;
objPos.z = (Path[1].z - Path[0].z) * Scalar + Path[0].z;
}
else
{
stVector diff;
diff.x = Path[3].x - Path[2].x;
diff.x = Path[3].y - Path[2].y;
diff.x = Path[3].z - Path[2].z;
 
float len = (float)sqrt((diff.x * diff.x +
                    diff.y * diff.y +
diff.z * diff.z));
 
Scalar = Scalar / len;
objPos.x = (Path[3].x - Path[2].x) * Scalar + Path[2].x;
objPos.y = (Path[3].y - Path[2].y) * Scalar + Path[2].y;
objPos.z = (Path[3].z - Path[2].z) * Scalar + Path[2].z;
}
 
if(Scalar >= 1.0f)
{
StartTime = (float)timeGetTime();
 
CurrentPath++;
 
if(CurrentPath > 2) CurrentPath = 1;
 
}

May be try:

float Scalar = (float)timeGetTime();
Scalar = (Scalar -StartTime) * 0.0003f;

 
if(Scalar >= 1.0f)
{
    SetPath(CurrentPath, CurrentPath + 1, Scalar);
    StartTime = (float)timeGetTime(); 
    if((CurrentPath + 1) > MaxPathCount) 
        CurrentPath = 0; 
    else
        CurrentPath++;
}

What is happening is you can call SetPath(...) Every second then if within bounds increment CurrentPath else set to zero.




#5175700 Setting a path for objects

Posted by Dissipate on 23 August 2014 - 05:04 PM

also maybe replace:

if(CurrentPath > 2) CurrentPath = 1;

with:

if(CurrentPath > MaxPathCount) CurrentPath = 0;

And oh dear sorry about the for loop I gave you... You need to be able to call that SetPath(...) every frame.  Make CurrentPath global. So that it will remember the last frame's number. Then in your render loop:

SetPath(CurrentPath, CurrentPath + 1);
CurrentPath++;

Also as I said I would be best if you set up your Path[n].x to equal minus then plus alternatingly. Then you could add as many as you like but remember to change you MaxPathCount also. I hope this works for you.

 

 

 

 




#5175684 Setting a path for objects

Posted by Dissipate on 23 August 2014 - 02:12 PM

I'm not sure but i think it goes from Path[0] to Path[1] then Path[2] to Path[3]. It would be easier if it went from Path[0] to Path[1] to Path[2] to Path[3]. Then it would be a simple case of iterating over them. Try maybe this instead of your if-else:

// Needs to know about diff, Scalar and obPos. I assume they are global
void SetPath(UINT uiStart, UINT uiEnd)
{
	diff.x = Path[uiEnd].x - Path[uiStart].x;
	diff.y = Path[uiEnd].y - Path[uiStart].y;
	diff.z = Path[uiEnd].z - Path[uiStart].z;
 
	float len = (float)sqrt((diff.x * diff.x +
					   diff.y * diff.y +
	diff.z * diff.z));
	Scalar = Scalar / len;
	objPos.x = (Path[uiEnd].x - Path[uiStart].x) * Scalar + Path[uiStart].x;
	objPos.y = (Path[uiEnd].y - Path[uiStart].y) * Scalar + Path[uiStart].y;
	objPos.z = (Path[uiEnd].z - Path[uiStart].z) * Scalar + Path[uiStart].z;
}

Then call via:

for (UINT i = 0; i < MaxPathCount; i++)
    SetPath(i, i+1);

Make sure you #define MaxPathCount to be the maximum number of paths. Don't go out of subscript btw.

The following might not work unless you put them in order properly as I said above.

#define MaxPath 6

Path[0].x = -2.5f; Path[0].y = 1.0f; Path[0].z = 0.0f;
Path[1].x =  2.5f; Path[1].y = 1.0f; Path[1].z = 0.0f;
Path[2].x =  2.5f; Path[2].y = 1.0f; Path[2].z = 0.0f;
Path[3].x = -2.5f; Path[3].y = 1.0f; Path[3].z = 0.0f;
Path[4].x = -2.5f; Path[4].y = -1.0f; Path[4].z = 0.0f;
Path[5].x = -2.5f; Path[5].y = 1.0f; Path[5].z = 0.0f;



#5172538 Pls suggest debugging t'kniques for why I can't display a cube

Posted by Dissipate on 09 August 2014 - 08:14 PM

Ok I've got it!

 

Simple mistake: the tutorial had a call to OnResize and I misinterpreted the program flow. It was a virtual function call that the derived overrided and in turn called the parent before setting up the projection with XMMatrixPerspectiveFovLH. I simply had to trigger an OnResize from within an init-function somwhere.

 

Happy days are here again...!




#5140909 Can't delete static singleton pointer (a deinitialization fiasco)

Posted by Dissipate on 21 March 2014 - 04:06 AM

Good morning...

Ok I've solved it fully and finally...!!!

 

I was sleeping and in my dream I dreamed that the shared pointer depended on the fstream(s). The static ofstream and ifstream were created after the shared pointers! I simply moved them to the top,  et voila, no more access violation.

 

Thank you Jesus!




PARTNERS