0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / Prs3d / Prs3d_Arrow.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <Prs3d_Arrow.ixx>
20#include <Graphic3d_Group.hxx>
b8ddfc2f 21#include <Graphic3d_ArrayOfSegments.hxx>
22#include <Graphic3d_ArrayOfPolylines.hxx>
7fd59977 23
24//=======================================================================
25//function : Draw
26//purpose :
27//=======================================================================
28
29void Prs3d_Arrow::Draw(const Handle(Prs3d_Presentation)& aPresentation,
30 const gp_Pnt& aLocation,
b8ddfc2f 31 const gp_Dir& aDirection,
7fd59977 32 const Quantity_PlaneAngle anAngle,
b8ddfc2f 33 const Quantity_Length aLength)
34{
7fd59977 35 Quantity_Length dx,dy,dz; aDirection.Coord(dx,dy,dz);
36//
81bba717 37// Point of the arrow:
7fd59977 38 Quantity_Length xo,yo,zo; aLocation.Coord(xo,yo,zo);
39
81bba717 40// Center of the base circle of the arrow:
7fd59977 41 Quantity_Length xc = xo - dx * aLength;
42 Quantity_Length yc = yo - dy * aLength;
43 Quantity_Length zc = zo - dz * aLength;
44
81bba717 45// Construction of i,j mark for the circle:
7fd59977 46 Quantity_Length xn=0., yn=0., zn=0.;
47
48 if ( Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) xn=1.;
49 else if ( Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) yn=1.;
50 else zn=1.;
51 Quantity_Length xi = dy * zn - dz * yn;
52 Quantity_Length yi = dz * xn - dx * zn;
53 Quantity_Length zi = dx * yn - dy * xn;
54
55 Quantity_Length Norme = sqrt ( xi*xi + yi*yi + zi*zi );
56 xi = xi / Norme; yi = yi / Norme; zi = zi/Norme;
57
b8ddfc2f 58 const Quantity_Length xj = dy * zi - dz * yi;
59 const Quantity_Length yj = dz * xi - dx * zi;
60 const Quantity_Length zj = dx * yi - dy * xi;
7fd59977 61
b8ddfc2f 62 const Standard_Integer NbPoints = 15;
7fd59977 63
b8ddfc2f 64 Handle(Graphic3d_ArrayOfSegments) aPrims1 = new Graphic3d_ArrayOfSegments(2*NbPoints);
65 Handle(Graphic3d_ArrayOfPolylines) aPrims2 = new Graphic3d_ArrayOfPolylines(NbPoints+1);
7fd59977 66
b8ddfc2f 67 gp_Pnt p1;
68 const Standard_Real Tg=tan(anAngle);
7fd59977 69
b8ddfc2f 70 for (Standard_Integer i = 1; i <= NbPoints ; i++)
71 {
72 const Standard_Real cosinus = cos ( 2 * M_PI / NbPoints * (i-1) );
73 const Standard_Real sinus = sin ( 2 * M_PI / NbPoints * (i-1) );
7fd59977 74
b8ddfc2f 75 const gp_Pnt pp(xc + (cosinus * xi + sinus * xj) * aLength * Tg,
76 yc + (cosinus * yi + sinus * yj) * aLength * Tg,
77 zc + (cosinus * zi + sinus * zj) * aLength * Tg);
7fd59977 78
b8ddfc2f 79 aPrims1->AddVertex(aLocation);
80 aPrims1->AddVertex(pp);
81 if(i==1) p1 = pp;
82 aPrims2->AddVertex(pp);
7fd59977 83 }
b8ddfc2f 84 aPrims2->AddVertex(p1);
85
86 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims1);
87 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims2);
7fd59977 88}
89
90//=======================================================================
91//function : Fill
92//purpose :
93//=======================================================================
94
95void Prs3d_Arrow::Fill(const Handle(Prs3d_Presentation)& /*aPresentation*/,
96 const gp_Pnt& /*aLocation*/,
97 const gp_Dir& /*aDirection*/,
98 const Quantity_PlaneAngle /*anAngle*/,
b8ddfc2f 99 const Quantity_Length /*aLength*/)
7fd59977 100{
101}