Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
einsteinathome
pulsatingscience
Commits
07513a3b
Commit
07513a3b
authored
Nov 29, 2008
by
Oliver Bock
Browse files
Sent pulsar on a cricular orbit around a central companion
* Again, not to scale! * Also: fixed quadrics pointer initialization
parent
a9a05d7b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/pulsaranimationwidget.cpp
View file @
07513a3b
...
...
@@ -23,18 +23,25 @@
PulsarAnimationWidget
::
PulsarAnimationWidget
(
QWidget
*
parent
)
:
QGLWidget
(
parent
),
m_frameTimer
(),
m_pulsarSpinTimer
()
m_pulsarSpinTimer
(),
m_orbitTimer
()
{
connect
(
&
m_frameTimer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
updateFrame
()));
connect
(
&
m_pulsarSpinTimer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
updatePulsarSpin
()));
connect
(
&
m_orbitTimer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
updateOrbit
()));
GLUquadricObj
*
m_quadricPulsar
;
GLUquadricObj
*
m_quadricPulsarCone1
;
GLUquadricObj
*
m_quadricPulsarCone2
;
m_quadricPulsar
=
NULL
;
m_quadricPulsarCone1
=
NULL
;
m_quadricPulsarCone2
=
NULL
;
m_framesPerSecond
=
25
;
setPulsarSpinFrequency
(
0.5
f
);
m_pulsarRotationAngle
=
0.0
;
m_pulsarRotationAngle
=
0.0
f
;
setOrbitFrequency
(
0.25
f
);
setOrbitRadius
(
4.0
f
);
m_orbitRotationAngle
=
0.0
f
;
}
PulsarAnimationWidget
::~
PulsarAnimationWidget
()
...
...
@@ -117,6 +124,13 @@ void PulsarAnimationWidget::paintGL()
glMaterialfv
(
GL_FRONT
,
GL_SHININESS
,
low_shininess
);
glMaterialfv
(
GL_FRONT
,
GL_EMISSION
,
no_mat
);
glPushMatrix
();
gluSphere
(
m_quadricPulsar
,
1.0
f
,
32
,
32
);
glPopMatrix
();
glRotatef
(
m_orbitRotationAngle
,
0.0
f
,
1.0
f
,
0.0
f
);
glTranslatef
(
0.0
f
,
0.0
f
,
m_orbitRadius
);
glPushMatrix
();
glRotatef
(
m_pulsarRotationAngle
,
0.0
f
,
1.0
f
,
0.0
f
);
gluSphere
(
m_quadricPulsar
,
1.0
f
,
32
,
32
);
...
...
@@ -139,20 +153,24 @@ void PulsarAnimationWidget::runAnimation()
{
m_frameTimer
.
start
(
1000.0
/
m_framesPerSecond
);
m_pulsarSpinTimer
.
start
(
m_pulsarSpinFrequency
);
m_orbitTimer
.
start
(
m_orbitFrequency
);
}
void
PulsarAnimationWidget
::
pauseAnimation
()
{
m_frameTimer
.
stop
();
m_pulsarSpinTimer
.
stop
();
m_orbitTimer
.
stop
();
}
void
PulsarAnimationWidget
::
stopAnimation
()
{
m_frameTimer
.
stop
();
m_pulsarSpinTimer
.
stop
();
m_orbitTimer
.
stop
();
m_pulsarRotationAngle
=
0.0
;
m_orbitRotationAngle
=
0.0
;
updateGL
();
}
...
...
@@ -171,6 +189,16 @@ void PulsarAnimationWidget::updatePulsarSpin()
}
}
void
PulsarAnimationWidget
::
updateOrbit
()
{
if
(
m_orbitRotationAngle
<=
360.0
)
{
m_orbitRotationAngle
++
;
}
else
{
m_orbitRotationAngle
=
0.0
;
}
}
void
PulsarAnimationWidget
::
setFramePerSecond
(
const
unsigned
int
fps
)
{
m_framesPerSecond
=
fps
;
...
...
@@ -181,3 +209,14 @@ void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
m_pulsarSpinFrequency
=
(
unsigned
int
)
(
1000
/
(
frequency
*
360.0
f
));
m_pulsarSpinTimer
.
setInterval
(
m_pulsarSpinFrequency
);
}
void
PulsarAnimationWidget
::
setOrbitRadius
(
const
float
radius
)
{
m_orbitRadius
=
-
1.0
*
radius
;
}
void
PulsarAnimationWidget
::
setOrbitFrequency
(
const
float
frequency
)
{
m_orbitFrequency
=
(
unsigned
int
)
(
1000
/
(
frequency
*
360.0
f
));
m_orbitTimer
.
setInterval
(
m_orbitFrequency
);
}
src/pulsaranimationwidget.h
View file @
07513a3b
...
...
@@ -34,6 +34,8 @@ public:
void
setFramePerSecond
(
const
unsigned
int
fps
);
void
setPulsarSpinFrequency
(
const
float
frequency
);
void
setOrbitRadius
(
const
float
radius
);
void
setOrbitFrequency
(
const
float
frequency
);
public
slots
:
void
runAnimation
();
...
...
@@ -42,6 +44,7 @@ public slots:
void
updateFrame
();
void
updatePulsarSpin
();
void
updateOrbit
();
protected:
...
...
@@ -54,14 +57,20 @@ protected:
private:
QTimer
m_frameTimer
;
QTimer
m_pulsarSpinTimer
;
QTimer
m_orbitTimer
;
GLUquadricObj
*
m_quadricPulsar
;
GLUquadricObj
*
m_quadricPulsarCone1
;
GLUquadricObj
*
m_quadricPulsarCone2
;
int
m_framesPerSecond
;
float
m_pulsarSpinFrequency
;
float
m_pulsarRotationAngle
;
float
m_orbitRadius
;
float
m_orbitFrequency
;
float
m_orbitRotationAngle
;
};
#endif
/* PULSARANIMATIONWIDGET_H_ */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment