0026348: Visualization, TKOpenGl - eliminate invalid NULL checks for transformation...
[occt.git] / src / OpenGl / OpenGl_Cylinder.cxx
CommitLineData
c827ea3a 1// Created on: 2014-10-15
2// Created by: Denis Bogolepov
3// Copyright (c) 2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <OpenGl_Cylinder.hxx>
17
18// =======================================================================
19// function : OpenGl_Cylinder
20// purpose :
21// =======================================================================
22OpenGl_Cylinder::OpenGl_Cylinder()
23: myBotRad (1.0f),
24 myTopRad (1.0f),
25 myHeight (1.0f)
26{
27 //
28}
29
30// =======================================================================
31// function : Init
32// purpose :
33// =======================================================================
34Standard_Boolean OpenGl_Cylinder::Init (const Standard_ShortReal theBotRad,
35 const Standard_ShortReal theTopRad,
36 const Standard_ShortReal theHeight,
37 const Standard_Integer theNbSlices,
38 const Standard_Integer theNbStacks)
39{
40 myBotRad = theBotRad;
41 myTopRad = theTopRad;
42 myHeight = theHeight;
43 return OpenGl_Quadric::init (theNbSlices, theNbStacks);
44}
45
46// =======================================================================
47// function : evalVertex
48// purpose :
49// =======================================================================
50OpenGl_Vec3 OpenGl_Cylinder::evalVertex (const Standard_ShortReal theU,
51 const Standard_ShortReal theV) const
52{
53 const Standard_ShortReal aU = static_cast<Standard_ShortReal> (theU * M_PI * 2.0);
54 const Standard_ShortReal aRadius = myBotRad + (myTopRad - myBotRad) * theV;
55 return OpenGl_Vec3 (cosf (aU) * aRadius,
56 sinf (aU) * aRadius,
57 theV * myHeight);
58}
59
60// =======================================================================
61// function : evalNormal
62// purpose :
63// =======================================================================
64OpenGl_Vec3 OpenGl_Cylinder::evalNormal (const Standard_ShortReal theU,
65 const Standard_ShortReal /*theV*/) const
66{
67 const Standard_ShortReal aU = static_cast<Standard_ShortReal> (theU * M_PI * 2.0);
68 return OpenGl_Vec3 (cosf (aU) * myHeight,
69 sinf (aU) * myHeight,
70 myBotRad - myTopRad).Normalized();
71}