Jump to content
  • Advertisement

fluke

Member
  • Content Count

    95
  • Joined

  • Last visited

Community Reputation

136 Neutral

About fluke

  • Rank
    Member
  1. is there such a thing as a c/c++ based api that can retrieve the actual date/time/epoch rather than whatever is set by the windows system clock (which can easily be changed/wrong)? i'm trying to implement a free 30-day trial of my software, but obviously, turning back the clock makes any use of time_t useless. and preferably this wouldn't be a third party library.
  2. it's called differential hysteresis processing. it uses the radial lines to perform pixel comparisons. the lines themselves are calculated as y=tan((line/numlines)*pi),x=1.0f for first quarter, then x=1.0f/tan((line/numlines)*pi),y=1.0f for second, then inverting both for other half of the circle. incrementing these with x/y during convolution produces desired radial lines. [Edited by - fluke on November 2, 2009 12:43:32 PM]
  3. well, they aren't typical kernels. i just said that to keep the focus on my bigger problem. they are actually radial lines that extend from the source pixel. so it's more like O(w*h*n*l) where n is the number of radial lines (which can range from 10 to 64+) and l is the length of each line which at it's respective angle, goes through the source pixel from one side of the image to the other. so as you can imagine, this is pretty slow processing a set of those lines per pixel. the order is an external radial lines loop, then width/height inside. this allows me to thread each radial line loop and the results are stored in a floating point image buffer which later is averaged with the sum of all processes to acheive the final result. i'm using a while loop which checks two x/y indexes for exceeding width/height limits. it has to be this way as each radial line is stored as a rise/run value which can't be predicted, so preemptive measures are difficult.
  4. Quote:Original post by Antheus Ugh, C++ and threads.... Quote:what's a best practice in this situation? Best practice would be not to use threads, and just write directly. well, this is to speed up an image processing routine that uses some heavy convolution kernels. without any kind of threading, this takes up to a minute on even a small 1-megapixel image, so that's not an option.
  5. ok, that makes sense now that i think about it, but how do i pass this data in then? just passing a copy instead of a pointer like this won't compile: _beginthread((void(*)(void*))process_abc,0,(void*)_abc); what's a best practice in this situation? thanks
  6. i've never used threads much before, and i'm having some weird issues where after a few iterations of calling beginthread, the member data of the struct argument i'm passing in is corrupted. have a look at the example code and the output below: typedef struct { int a,b,c; }abc; void process_abc(abc* _abc){ FILE* f=fopen("C:\\output.txt", "at"); fprintf(f,"%i\n",_abc->a); fprintf(f,"%i\n",_abc->b); fprintf(f,"%i\n",_abc->c); fclose(f); _endthread(); } // in a function: for(int i=0;i<32;i++){ abc _abc; _abc.a=1; _abc.b=2; _abc.c=3; _beginthread((void(*)(void*))process_abc,0,(void*)&_abc); } the output: 1 2 3 1 2 ... 1 2 3 1 64 138 1 64 208 any idea what's causing this?
  7. after giving katie's post a thorough second read-through, and addressing the row vs. column ordering issue, i got it working. i used glGetFloatv(GL_MODELVIEW_MATRIX, m) to get my up, and filled the result matrix like explained. i found another external reference to clear up a few things and with a call to glMultMatrixf(rm) the projectile was aligned with it's path. now i just need to study this for a while longer to actually understand "why" it works. thanks katie!
  8. ooookay. :) so jyk, is my implementation close to what you recommended then? i'm mostly indifferent on the approach i use as long as it isn't too complicated to implement and then maintain. but of course, any opportunity to learn something new is one i won't pass up, so i'll definitely give katie's suggestion a shot as well. but in the meantime, i'd really like to just get what i've started working! ;)
  9. i'm a liiittle closer here having made some wild guesses. the projectile's (a simpe rectangular cube) rotation *seems* to coincide with it's current path/direction, but the orientation is WAY off.: axis = cross(vel,dir); axis.normalize(); sargeant_angle = acos(abs(dot(vel,dir))) * 360.0f; //later in render func: glPushMatrix(); glTranslatef(x,y,z); glRotatef(sargeant_angle,axis.x,axis.y,axis.z); glScalef(0.05f, 0.05f, 0.2f); //problem exists here probably???????? DrawCube(); //draws a simple cube, now rectangular thanks to prev scale call glPopMatrix(); is there an easy way to fix the orientation problem no matter which axis i scale the cube on?
  10. hmmm.. so minus div by zero checking, you mean like this?: axis = cross(vel,dir); axis.normalize(); sargeant_angle = abs(dot(vel,dir)); glRotatef(sargeant_angle,axis.x,axis.y,axis.z); i'm guessing this isn't correct as the behavior is... well, there's no behavior.. at least no rotation.
  11. the title says it all. i'm using vectors to calculate the position of the projectile each frame and i want to take the projectile and "face" it in the direction it's moving, perhaps via some yaw/pitch mechanism? i'm assuming i'd use angles to get this but my attempts have come up short. //ummm... no. yaw=RAD2DEG(atan2(y,x)); glRotatef(yaw,0,1,0);
  12. fluke

    math for a sidewinder-like missile

    ok, i re-wrote the whole thing and got it working-ish. i ditched the pid and just went with a simpler implementation like Nanoha suggested and using a direction and velocity vector to calculate the new pos. anyway, thanks for the help everyone!
  13. fluke

    math for a sidewinder-like missile

    ok, i've been working on this steadily for the last few days, but with no luck. i found an example of kind of what i'm after in a game programming book i have and it uses a PID controller like suggested... however, it's in 2D, so it uses angles for it's heading, which in the code below you see i've attempted to correct. then again below, it attempts a direction rotation based on an angle, which obviously is not going to work for 3d. i'd need to specify an axis for rotation, but i don't know how to determine the rotations for each axis based on the previous calculations. //PART OF PID: void Missile::Clear(){ m_CurrentIndex = -1; m_PreviousIndex = -1; m_NumErrorsRecorded = 0; m_CurrentIntegral = 0.0f; for (int i = 0; i < NUM_ERROR_SLOTS; i++) { m_Error = 0.0f; m_Timestep = 0.0f; } } void Missile::Record(float error, float timestep){ m_PreviousIndex = m_CurrentIndex; m_CurrentIndex = (m_CurrentIndex + 1) % NUM_ERROR_SLOTS; if (m_NumErrorsRecorded == NUM_ERROR_SLOTS){ m_CurrentIntegral -= m_Error[m_CurrentIndex] * m_Timestep[m_CurrentIndex]; } m_Error[m_CurrentIndex] = error; m_Timestep[m_CurrentIndex] = timestep; m_CurrentIntegral += error * timestep; m_NumErrorsRecorded = min(m_NumErrorsRecorded + 1, NUM_ERROR_SLOTS); } float Missile::GetError(){ if (m_NumErrorsRecorded >= 1){ return m_Error[m_CurrentIndex]; }else{ return 0.0f; } } float Missile::GetErrorIntegral(){ return m_CurrentIntegral; } float Missile::GetErrorDerivative(){ if (m_NumErrorsRecorded >= 2){ float difference = m_Error[m_CurrentIndex] - m_Error[m_PreviousIndex]; float time_interval = m_Timestep[m_CurrentIndex]; if (time_interval > 0.001f){ return (difference / time_interval); }else{ return 999999.0f; } }else{ return 0.0f; } } float Missile::GetOutput(){ m_P_Coefficient = 2.0f; // Our current P coefficient m_I_Coefficient = .5f; // Our current I coefficient m_D_Coefficient = 2.9f; // Our current D coefficient return m_P_Coefficient * GetError() + m_I_Coefficient * GetErrorIntegral() + m_D_Coefficient * GetErrorDerivative(); } float Missile::CalculateIntegralDirectly(){ float integral = 0.0f; for (int i = 0; i < m_NumErrorsRecorded; i++){ integral += (m_Error * m_Timestep); } return integral; } //MISSILE MOVEMENT: void Missile::Move(float timestep){ //Vector3 vector_to_target = vTargetPos - vMissilePos;//Vector3 vector_to_target = *(m_pTarget->GetPosition()) - vMissilePos; //float heading_error = vDirection.GetAngle() - vector_to_target.GetAngle(); Vector3 vector_to_target = vTargetPos - vMissilePos; Vector3 v1 = vDirection; Vector3 v2 = vector_to_target; v1.normalize(); v2.normalize(); float heading_error = RAD2DEG(asin(Vector3::dot(&v1,&v2))); if (heading_error > 180.0f){ heading_error -= 360.0f; }else if (heading_error < -180.0f){ heading_error += 360.0f; } Record(heading_error, timestep); float desired_acceleration = GetMaxAcceleration(); float desired_angular_acceleration = GetOutput(); desired_acceleration = Clamp(desired_acceleration, 0.0f, 1000.0f); desired_angular_acceleration = Clamp(desired_angular_acceleration, -180.0f, 180.0f); SetAcceleration(desired_acceleration); SetAngularAcceleration(desired_angular_acceleration); //move m_Speed += m_Acceleration * timestep; Vector3 velocity = vDirection; velocity.normalize_especial(m_Speed); m_AngularVelocity += m_AngularAcceleration * timestep; float drag = -m_Speed * (float)fabs(m_Speed); drag *= (MissileDragFactor * timestep); m_Speed += drag; float rotational_drag = -m_AngularVelocity * (float)fabs(m_AngularVelocity); rotational_drag *= (MissileRotationalDragFactor * timestep); m_AngularVelocity += rotational_drag; float delta_angle = m_AngularVelocity * timestep; vDirection.Rotate(delta_angle); //not correct for 3d vDirection.normalize(); vMissilePos += velocity * timestep; Vector3 p = vMissilePos; p.normalize(); x = p.x; y = p.y; z = p.z; }
  14. fluke

    math for a sidewinder-like missile

    Emergent, you're using a few expressions i don't understand. what is "x" in "v x g" and "a x g"? Nanoha, how can i get the missile to curve using your approach? and to answer your question, yes, i guess it is effectively a homing missile. sidewinders (which i assume get their name from their behavior which is similar to the snake of the same name) overcompensate their turns to "predict" the position of their target. their curves are wide and windy when initially fired and the path is less windy as it closes in on the enemy. i'll try to get both of these implementations working and any others that anyone provides.
  15. i'll start with the source. be careful not to fall out of your chair when you start laughing.. class Missile { public: float x,x2,y,y2,z,z2; float curAngle, destAngle; Missile(){ x=0; y=0; z=0; curAngle = 0.0f; } void Init(float x1, float y1, float z1, float angle){ x=x1; y=y1; z=z1; curAngle = angle; } void Update(float x2, float y2, float z2, float speed){ float destAngle = atan2((z2-z),(x2-x)); if(curAngle>destAngle+PI) curAngle -= 1.0f * PI; if(curAngle<destAngle-PI) curAngle += 1.0f * PI; curAngle += (destAngle - curAngle) * .1f; x += cosf(curAngle) * speed; y = 0; //??? z += sinf(curAngle) * speed; } }; ooookay. quite plainly, i suck at math and found this 2d implementation that has some problems. first of all, in its simplicity, it doesn't even do what i want, which is to behave like a sidewinder missile eradically painting the sky with plumes of smoke using its proportional navigation before finally plowing into its target. instead, it "attempts" to curve around and eventually hit the target, as opposed to going in a straight, boring line. however, it even fails at this in some ways. when it reaches the target, the x and z values go up and down causing a "ghosting" type effect where there are seemingly two instances of the missile co-existing a short distance from one another. finally, the last problems is that i don't know how to solve for y. anyone care to help or better yet provide some sample code on how to create a more accurate sidewinder effect? :)
  • 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!