This is mainly to thebolt, and also anyone else that can help answer :)
Hi! I've attached a diff using 8 raycasts in a disc from the eye to target
to determine how far in the camera should be. With a single raycast you get
smooth movement, but with the 8 it will jump very suddenly- I believe
because there's no falloff between one beam and the next like with a raycast
that has radius or a swept sphere.
The code is doing this correct right? So it's not just an error I made.
Thanks!
-----------------------------
Index: plugins/propclass/cameras/tracking/tracking.cpp
===================================================================
--- plugins/propclass/cameras/tracking/tracking.cpp (revision 3575)
+++ plugins/propclass/cameras/tracking/tracking.cpp (working copy)
@@ -300,8 +300,60 @@
posoff.angle = PI / 2 - 0.1f;
}
+float celPcTrackingCamera::TraceRaycast (const csVector3 &off, csVector3
&in)
+{
+ // do collision test
+ const csTraceBeamResult beam = csColliderHelper::TraceBeam (cdsys,
parent->GetSectors ()->Get (0),
+ tar, pos + off, true);
+ if (beam.sqdistance > 0)
+ {
+ in = beam.closest_isect;
+ }
+ return beam.sqdistance;
+}
+
void celPcTrackingCamera::FindCorrectedTransform (float elapsedsecs)
{
+ corrpos = pos;
+ corrtar = tar;
+
+ const float radius = 1.0;
+ csVector3 off[8];
+ off[0].Set (0, radius, 0);
+ off[1].Set (0, -radius, 0);
+ const csVector3 lookat (tar - pos);
+ off[2].Set (lookat.z, 0, lookat.x);
+ off[2].Normalize();
+ off[2] *= radius;
+ off[3].Set (-off[2]);
+
+ off[4] = (off[0] + off[2]) / 2.0;
+ off[5] = (off[0] + off[3]) / 2.0;
+ off[6] = (off[1] + off[2]) / 2.0;
+ off[7] = (off[1] + off[3]) / 2.0;
+
+ float best_sqdist = -1.0;
+ size_t bestidx;
+ csVector3 best_inter;
+ for (size_t i = 0; i < 8; i++)
+ {
+ csVector3 in;
+ float sqdist = TraceRaycast (off[i], in);
+ if (sqdist > 0 && (best_sqdist < 0 || sqdist < best_sqdist))
+ {
+ best_sqdist = sqdist;
+ bestidx = i;
+ best_inter = in;
+ }
+ }
+
+ if (best_sqdist > 0)
+ corrpos = best_inter - off[bestidx];
+ else
+ corrpos = pos;
+ corrtar = tar;
+
+ return;
// get this value before it's lost
float old_reallen = (corrtar - corrpos).Norm ();
// do collision test
@@ -329,7 +381,7 @@
// target unchanged
corrtar = tar;
- if (was_corrected)
+ if (false && was_corrected)
{
// reverse lookat vector
const csVector3 clookat (corrtar - corrpos);
Index: plugins/propclass/cameras/tracking/tracking.h
===================================================================
--- plugins/propclass/cameras/tracking/tracking.h (revision 3575)
+++ plugins/propclass/cameras/tracking/tracking.h (working copy)
@@ -110,6 +110,8 @@
float SpringForce (const float movement);
// pan camera around a target
void PanAroundPlayer (const csVector3 &playpos, float elapsedsecs);
+ // do the raycast to determine magical intersection point
+ float TraceRaycast (const csVector3 &off, csVector3 &in);
// do your collision detection maagick!
void FindCorrectedTransform (float elapsedsecs);
// target settings was changed, so need to do a transition
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]