34 |
#include <GL/gl.h> |
#include <GL/gl.h> |
35 |
|
|
36 |
#include <vob/trans/Primitives.hxx> |
#include <vob/trans/Primitives.hxx> |
37 |
|
#include <vob/geom/Quadrics.hxx> |
38 |
|
|
39 |
namespace Vob { |
namespace Vob { |
40 |
namespace Primitives { |
namespace Primitives { |
117 |
VOB_PRIMITIVETRANS_DEFINED(TranslateXYZ_Explicit, "translate"); |
VOB_PRIMITIVETRANS_DEFINED(TranslateXYZ_Explicit, "translate"); |
118 |
VOB_PRIMITIVETRANS_DEFINED(ScaleXYZ_Explicit, "scale"); |
VOB_PRIMITIVETRANS_DEFINED(ScaleXYZ_Explicit, "scale"); |
119 |
|
|
|
|
|
120 |
/** Rotation clockwise. |
/** Rotation clockwise. |
121 |
*/ |
*/ |
122 |
class RotateXY : |
class RotateXY : |
417 |
}; |
}; |
418 |
VOB_PRIMITIVETRANS_DEFINED(Ortho_Explicit, "ortho"); |
VOB_PRIMITIVETRANS_DEFINED(Ortho_Explicit, "ortho"); |
419 |
|
|
420 |
|
/** A buoy coordinate system. |
421 |
|
*/ |
422 |
|
class BuoyOnCircle1 : |
423 |
|
public Ortho |
424 |
|
{ |
425 |
|
public: |
426 |
|
/** Set this coordinate system to be the buoy with given params. |
427 |
|
* @param anchorPt The location of the anchor. |
428 |
|
* @param ctrPoint The center of the buoy circle. |
429 |
|
* @param radius The radius of the circle. |
430 |
|
* @param projPoint the point to project the buoy from, if it would be |
431 |
|
* inside the circle just shifted. |
432 |
|
* @param shiftAmount The amount to shift the buoy. |
433 |
|
*/ |
434 |
|
void setBuoy(Pt anchorPt, Pt ctrPoint, float radius, Pt projPoint, float shiftAmount) { |
435 |
|
|
436 |
|
// shifted point: default buoy location |
437 |
|
Pt shifted = anchorPt + (ctrPoint - projPoint) * shiftAmount; |
438 |
|
|
439 |
|
float shiftrad = (shifted - ctrPoint).length(); |
440 |
|
float anchorrad = (anchorPt - ctrPoint).length(); |
441 |
|
|
442 |
|
Pt buoy; |
443 |
|
if(shiftrad >= radius) { |
444 |
|
// if shifted point is outside circle, our work is done |
445 |
|
buoy = shifted; |
446 |
|
} else { |
447 |
|
if(anchorrad >= radius) |
448 |
|
// otherwise, kludge it by placing it on the anchor. |
449 |
|
// There's a small jump here; we should do it differently. |
450 |
|
buoy = anchorPt; // XXX ??? |
451 |
|
else |
452 |
|
// If both anchor and shifted point are inside circle, |
453 |
|
// project. |
454 |
|
buoy = Geom::project2circle(anchorPt, projPoint, ctrPoint, radius); |
455 |
|
} |
456 |
|
|
457 |
|
float scale = 1-anchorrad / radius ; |
458 |
|
|
459 |
|
if(scale <shiftAmount) { |
460 |
|
scale = shiftAmount; |
461 |
|
} |
462 |
|
// DBG(dbg_buoy) << "final: "<<buoy << " "<<" "<<scale<<" "<<"\n"; |
463 |
|
|
464 |
|
this->x = buoy.x; |
465 |
|
this->y = buoy.y; |
466 |
|
this->z = - scale; |
467 |
|
this->sx = scale; |
468 |
|
this->sy = scale; |
469 |
|
|
470 |
|
} |
471 |
|
}; |
472 |
|
|
473 |
|
/* |
474 |
|
* <p> |
475 |
|
* The depth is between -1 (center) and 0 (edge) |
476 |
|
* <p> |
477 |
|
* Parameter layout: |
478 |
|
* x_circle, y_circle, radius, x_projpoint, y_projpoint, shiftamount |
479 |
|
* <p> |
480 |
|
* Linear interp between 0..1, 0..-1 |
481 |
|
*/ |
482 |
|
class BuoyOnCircle1_Explicit : |
483 |
|
public BuoyOnCircle1, |
484 |
|
public DependentPrimitiveTransform, |
485 |
|
public ParametrizedPrimitiveTransform |
486 |
|
{ |
487 |
|
public: |
488 |
|
enum { NDepends = 2, NParams = 6 }; // usual super and plus the anchor |
489 |
|
template<class SPtr, class P> void setParams(SPtr depends, P params) { |
490 |
|
ZPt anchor = depends[1]->transform(ZPt(0,0,0)); |
491 |
|
|
492 |
|
Pt ctr(params[0], params[1]); |
493 |
|
float radius = params[2]; |
494 |
|
Pt proj(params[3], params[4]); |
495 |
|
float shiftamount = params[5]; |
496 |
|
|
497 |
|
this->setBuoy(anchor, ctr, radius, proj, shiftamount); |
498 |
|
} |
499 |
|
}; |
500 |
|
VOB_PRIMITIVETRANS_DEFINED(BuoyOnCircle1_Explicit, "buoyOnCircle1"); |
501 |
|
|
502 |
|
|
503 |
/** Orthonormal transformation along with setting the box |
/** Orthonormal transformation along with setting the box |
504 |
* size of the coordinate system. |
* size of the coordinate system. |
505 |
*/ |
*/ |