home *** CD-ROM | disk | FTP | other *** search
- // VCDemoDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "VCDemo.h"
- #include "VCDemoDlg.h"
- #include "math.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CVCDemoDlg dialog
-
- CVCDemoDlg::CVCDemoDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CVCDemoDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CVCDemoDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
-
- init = FALSE;
- mousedown = FALSE;
-
- }
-
- void CVCDemoDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CVCDemoDlg)
- DDX_Control(pDX, IDC_ADF, ADF);
- DDX_Control(pDX, IDC_ALT, ALT);
- DDX_Control(pDX, IDC_CLIMB, CLIMB);
- DDX_Control(pDX, IDC_HEADING, HEADING);
- DDX_Control(pDX, IDC_HORIZON, HORIZON);
- DDX_Control(pDX, IDC_HSI, HSI);
- DDX_Control(pDX, IDC_OBI, OBI);
- DDX_Control(pDX, IDC_RMI, RMI);
- DDX_Control(pDX, IDC_SPEED, SPEED);
- DDX_Control(pDX, IDC_TURN, TURN);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CVCDemoDlg, CDialog)
- //{{AFX_MSG_MAP(CVCDemoDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_TIMER()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_MOUSEMOVE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CVCDemoDlg message handlers
-
- BOOL CVCDemoDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CVCDemoDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
-
-
- if (!init) {
- init = TRUE;
-
- //SetTimer(1000,50,NULL);
- SetTimer(1001,200,NULL);
- }
-
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CVCDemoDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- BOOL CVCDemoDlg::DestroyWindow()
- {
- //KillTimer(1000);
- if (IsWindow(m_hWnd)) {
- KillTimer(1001);
- //KillTimer(1000);
- }
-
- return CDialog::DestroyWindow();
- }
-
- void CVCDemoDlg::OnTimer(UINT nIDEvent)
- {
- switch (nIDEvent) {
- case 1001:
- CLIMB.SetClimbRate(50.0f * SPEED.GetAirspeed()
- * (float) sin((double) HORIZON.GetAHPitch()
- * (float) cos((double) HORIZON.GetAHRoll() * 3.14159f / 180.0f) * 3.14159f / 180.0f));
- ALT.SetAltitude(ALT.GetAltitude() + CLIMB.GetClimbRate() / 100.0f);
-
- SPEED.SetAirspeed(SPEED.GetAirspeed() - CLIMB.GetClimbRate() / 2000.0f);
- if (SPEED.GetAirspeed() > 120.0f) SPEED.SetAirspeed(120.0f);
- if (SPEED.GetAirspeed() < 60.0f) SPEED.SetAirspeed(60.0f);
-
- HEADING.SetHeadingIndicator(HEADING.GetHeadingIndicator() + SPEED.GetAirspeed() * (float) sin((double) HORIZON.GetAHRoll() * 3.14159f / 180.0f) / 20.0f);
- OBI.SetOBICourse(HEADING.GetHeadingIndicator());
- ADF.SetADFBearing(HEADING.GetHeadingIndicator() + 30.0f);
- RMI.SetRMIBearing1(HEADING.GetHeadingIndicator() + 45.0f);
- HORIZON.SetAHHeading(HEADING.GetHeadingIndicator());
- HSI.SetHSIHeading(HEADING.GetHeadingIndicator());
-
- TURN.SetTCTurn(SPEED.GetAirspeed() * (float) sin((double) HORIZON.GetAHRoll() * 3.14159f / 180.0f) * (float) sin((double) HORIZON.GetAHPitch() * 3.14159f / 180.0f));
-
- //In this cockpit demo, all instruments have the AutoRedraw property
- //set to false for improved refresh rates. This requires that
- //you force the instruments to redraw after all the instruments'
- //properties have been updated. Setting the Redraw property to
- //True forces the instruments to be refreshed immediately.
-
- HEADING.Redraw();
- SPEED.Redraw();
- CLIMB.Redraw();
- ALT.Redraw();
- HSI.Redraw();
- OBI.Redraw();
- RMI.Redraw();
- ADF.Redraw();
- TURN.Redraw();
- HORIZON.Redraw();
-
- break;
- }
-
- CDialog::OnTimer(nIDEvent);
- }
-
- BEGIN_EVENTSINK_MAP(CVCDemoDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CVCDemoDlg)
- ON_EVENT(CVCDemoDlg, IDC_HORIZON, -605 /* MouseDown */, OnMouseDownHorizon, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CVCDemoDlg, IDC_HORIZON, -606 /* MouseMove */, OnMouseMoveHorizon, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CVCDemoDlg, IDC_HORIZON, -607 /* MouseUp */, OnMouseUpHorizon, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CVCDemoDlg, IDC_ADF, -601 /* DblClick */, OnDblClickAdf, VTS_NONE)
- ON_EVENT(CVCDemoDlg, IDC_ALT, -601 /* DblClick */, OnDblClickAlt, VTS_NONE)
- ON_EVENT(CVCDemoDlg, IDC_CLIMB, -601 /* DblClick */, OnDblClickClimb, VTS_NONE)
- ON_EVENT(CVCDemoDlg, IDC_HEADING, -601 /* DblClick */, OnDblClickHeading, VTS_NONE)
- ON_EVENT(CVCDemoDlg, IDC_HORIZON, -601 /* DblClick */, OnDblClickHorizon, VTS_NONE)
- ON_EVENT(CVCDemoDlg, IDC_HSI, -601 /* DblClick */, OnDblClickHsi, VTS_NONE)
- ON_EVENT(CVCDemoDlg, IDC_OBI, -601 /* DblClick */, OnDblClickObi, VTS_NONE)
- ON_EVENT(CVCDemoDlg, IDC_RMI, -601 /* DblClick */, OnDblClickRmi, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CVCDemoDlg::OnMouseDownHorizon(short Button, short Shift, long x, long y)
- {
- mousedown = TRUE;
- mousex = x;
- mousey = y;
- pitch = HORIZON.GetAHPitch();
- roll = HORIZON.GetAHRoll();
- }
-
- void CVCDemoDlg::OnMouseMoveHorizon(short Button, short Shift, long x, long y)
- {
- if (mousedown) {
- if (mousex!=x || mousey!=y) {
- HORIZON.SetAHPitch(pitch + (y - mousey)/5.0f);
- HORIZON.SetAHRoll(roll + (x - mousex)/5.0f);
- HORIZON.Redraw();
- }
- }
- }
-
- void CVCDemoDlg::OnMouseUpHorizon(short Button, short Shift, long x, long y)
- {
- mousedown = FALSE;
- }
-
- void CVCDemoDlg::OnDblClickAdf()
- {
- ADF.ShowPropertyPage();
- }
-
- void CVCDemoDlg::OnDblClickAlt()
- {
- ALT.ShowPropertyPage();
- }
-
- void CVCDemoDlg::OnDblClickClimb()
- {
- CLIMB.ShowPropertyPage();
- }
-
- void CVCDemoDlg::OnDblClickHeading()
- {
- HEADING.ShowPropertyPage();
- }
-
- void CVCDemoDlg::OnDblClickHorizon()
- {
- HORIZON.ShowPropertyPage();
- }
-
- void CVCDemoDlg::OnDblClickHsi()
- {
- HSI.ShowPropertyPage();
- }
-
- void CVCDemoDlg::OnDblClickObi()
- {
- OBI.ShowPropertyPage();
- }
-
- void CVCDemoDlg::OnDblClickRmi()
- {
- RMI.ShowPropertyPage();
- }
-