0027756: Visualization - add Draw() method taking Graphic3d_Group to tools Prs3d_Arro...
[occt.git] / src / Prs3d / Prs3d_Arrow.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
4ad142d9 15#include <Prs3d_Arrow.hxx>
42cf5bc1 16
17#include <gp_Dir.hxx>
18#include <gp_Pnt.hxx>
b8ddfc2f 19#include <Graphic3d_ArrayOfPolylines.hxx>
42cf5bc1 20#include <Graphic3d_ArrayOfSegments.hxx>
21#include <Graphic3d_Group.hxx>
42cf5bc1 22#include <Prs3d_Presentation.hxx>
7fd59977 23
24//=======================================================================
25//function : Draw
26//purpose :
27//=======================================================================
4ad142d9 28void Prs3d_Arrow::Draw(const Handle(Graphic3d_Group)& theGroup,
7fd59977 29 const gp_Pnt& aLocation,
b8ddfc2f 30 const gp_Dir& aDirection,
7fd59977 31 const Quantity_PlaneAngle anAngle,
b8ddfc2f 32 const Quantity_Length aLength)
33{
7fd59977 34 Quantity_Length dx,dy,dz; aDirection.Coord(dx,dy,dz);
35//
81bba717 36// Point of the arrow:
7fd59977 37 Quantity_Length xo,yo,zo; aLocation.Coord(xo,yo,zo);
38
81bba717 39// Center of the base circle of the arrow:
7fd59977 40 Quantity_Length xc = xo - dx * aLength;
41 Quantity_Length yc = yo - dy * aLength;
42 Quantity_Length zc = zo - dz * aLength;
43
81bba717 44// Construction of i,j mark for the circle:
7fd59977 45 Quantity_Length xn=0., yn=0., zn=0.;
46
47 if ( Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) xn=1.;
48 else if ( Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) yn=1.;
49 else zn=1.;
50 Quantity_Length xi = dy * zn - dz * yn;
51 Quantity_Length yi = dz * xn - dx * zn;
52 Quantity_Length zi = dx * yn - dy * xn;
53
54 Quantity_Length Norme = sqrt ( xi*xi + yi*yi + zi*zi );
55 xi = xi / Norme; yi = yi / Norme; zi = zi/Norme;
56
b8ddfc2f 57 const Quantity_Length xj = dy * zi - dz * yi;
58 const Quantity_Length yj = dz * xi - dx * zi;
59 const Quantity_Length zj = dx * yi - dy * xi;
7fd59977 60
b8ddfc2f 61 const Standard_Integer NbPoints = 15;
7fd59977 62
b8ddfc2f 63 Handle(Graphic3d_ArrayOfSegments) aPrims1 = new Graphic3d_ArrayOfSegments(2*NbPoints);
64 Handle(Graphic3d_ArrayOfPolylines) aPrims2 = new Graphic3d_ArrayOfPolylines(NbPoints+1);
7fd59977 65
b8ddfc2f 66 gp_Pnt p1;
67 const Standard_Real Tg=tan(anAngle);
7fd59977 68
b8ddfc2f 69 for (Standard_Integer i = 1; i <= NbPoints ; i++)
70 {
71 const Standard_Real cosinus = cos ( 2 * M_PI / NbPoints * (i-1) );
72 const Standard_Real sinus = sin ( 2 * M_PI / NbPoints * (i-1) );
7fd59977 73
b8ddfc2f 74 const gp_Pnt pp(xc + (cosinus * xi + sinus * xj) * aLength * Tg,
75 yc + (cosinus * yi + sinus * yj) * aLength * Tg,
76 zc + (cosinus * zi + sinus * zj) * aLength * Tg);
7fd59977 77
b8ddfc2f 78 aPrims1->AddVertex(aLocation);
79 aPrims1->AddVertex(pp);
80 if(i==1) p1 = pp;
81 aPrims2->AddVertex(pp);
7fd59977 82 }
b8ddfc2f 83 aPrims2->AddVertex(p1);
84
4ad142d9 85 theGroup->AddPrimitiveArray (aPrims1);
86 theGroup->AddPrimitiveArray (aPrims2);
7fd59977 87}