Skip to content

Commit

Permalink
FlagWarpSceneNode: do not recompute sin/cos every time
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed May 29, 2024
1 parent 04fc025 commit 04a1e3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/FlagWarpSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class FlagWarpSceneNode : public SceneNode
const GLfloat* getPosition() const override;
private:
const FlagWarpSceneNode* sceneNode;
static float ring[12][2];
};
friend class FlagWarpRenderNode;

Expand Down
17 changes: 14 additions & 3 deletions src/geometry/FlagWarpSceneNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,22 @@ void FlagWarpSceneNode::addRenderNodes(
// FlagWarpSceneNode::FlagWarpRenderNode
//

float FlagWarpSceneNode::FlagWarpRenderNode::ring[12][2];

FlagWarpSceneNode::FlagWarpRenderNode::FlagWarpRenderNode(
const FlagWarpSceneNode* _sceneNode) :
sceneNode(_sceneNode)
{
// do nothing
static bool init = true;
if (init)
{
init = false;
for (int i = 0; i < 12; i++)
{
ring[i][0] = cosf((float)(2.0 * M_PI * double(i) / 12.0));
ring[i][1] = sinf((float)(2.0 * M_PI * double(i) / 12.0));
}
}
}

FlagWarpSceneNode::FlagWarpRenderNode::~FlagWarpRenderNode()
Expand All @@ -124,8 +135,8 @@ void FlagWarpSceneNode::FlagWarpRenderNode::render()
for (int i = 0; i < 12; i++)
{
const GLfloat r = FlagWarpSize * (0.9f + 0.2f * (float)bzfrand());
geom[i][0] = r * cosf((float)(2.0 * M_PI * double(i) / 12.0));
geom[i][1] = r * sinf((float)(2.0 * M_PI * double(i) / 12.0));
geom[i][0] = r * ring[i][0];
geom[i][1] = r * ring[i][1];
}

const GLfloat* sphere = sceneNode->getSphere();
Expand Down

0 comments on commit 04a1e3f

Please sign in to comment.