Permalink
Browse files

Added the ability to scale the scene.

  • Loading branch information...
1 parent f9477da commit 1d2ac887b98577f749c538191257d922d2735f32 @mdfeist committed Jun 18, 2013
Showing with 103 additions and 11 deletions.
  1. +25 −11 BlinkAnalysis/AppViewer.cpp
  2. +2 −0 BlinkAnalysis/AppViewer.h
  3. +73 −0 BlinkAnalysis/MainForm.h
  4. +3 −0 BlinkAnalysis/MainForm.resX
@@ -30,6 +30,7 @@
osgViewer::Viewer* viewer;
osg::Group* rootNode;
+osg::AutoTransform* sceneNode;
osg::Vec3 lastRay;
@@ -38,11 +39,18 @@ bool visible = false;
bool localMarkers = false;
-float VIEWER_SCALE = 5.f;
+float VIEWER_SCALE = 1.f;
void AppViewer::stopAppViewer() { running = false; }
void AppViewer::setVisible(bool bVisible) { visible = bVisible; }
+void AppViewer::setScale(int scale) {
+ VIEWER_SCALE = scale;
+
+ if (sceneNode)
+ sceneNode->setScale(VIEWER_SCALE);
+}
+
void renderEyeVector(osg::Geode* node) {
// Get the current client
ClientHandler* client = AppData::getInstance()->getClient();
@@ -67,7 +75,7 @@ void renderEyeVector(osg::Geode* node) {
osg::Vec3 pos = head->getPosition();
// Add to the points array
- points->push_back( pos * VIEWER_SCALE );
+ points->push_back( pos );
colors->push_back(osg::Vec4(1, 0, 0, 1));
osg::Matrixf headMatrix;
@@ -98,7 +106,7 @@ void renderEyeVector(osg::Geode* node) {
lastRay = ray;
- points->push_back( (ray + pos) * VIEWER_SCALE );
+ points->push_back( (ray + pos) );
colors->push_back(osg::Vec4(1, 0, 0, 1));
}
}
@@ -171,7 +179,7 @@ void renderMarkers(osg::Geode* node) {
osg::Vec3 pos = marker.getPosition();
// Add marker to the points array
- points->push_back( pos * VIEWER_SCALE );
+ points->push_back( pos );
// Add colors
colors->push_back( marker.getColor() );
@@ -194,7 +202,7 @@ void renderMarkers(osg::Geode* node) {
osg::Vec3 pos = marker->getPosition();
// Add marker to the points array
- points->push_back( pos * VIEWER_SCALE );
+ points->push_back( pos );
// Add colors
if (marker->isSelected())
@@ -224,7 +232,7 @@ void renderMarkers(osg::Geode* node) {
nodeState->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
nodeState->setMode(GL_BLEND, osg::StateAttribute::ON);
nodeState->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON);
- nodeState->setAttribute( new osg::Point( 10.0f ) , osg::StateAttribute::ON );
+ nodeState->setAttribute( new osg::Point( 5.0f ) , osg::StateAttribute::ON );
nodeState->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
// End Create Points
}
@@ -254,13 +262,13 @@ void render(void *) {
renderEyeVector(node);
// Add Node containing all the points to the scene
- rootNode->addChild( node );
+ sceneNode->addChild( node );
// Render frame
viewer->frame();
// Remove points from the scene
- rootNode->removeChild( node );
+ sceneNode->removeChild( node );
} else {
// View not visible so Sleep for 1000 milliseconds
Sleep(1000);
@@ -284,12 +292,18 @@ void AppViewer::initAppViewer(HWND hwnd)
// Create new root node if one doesn't exist
if (!rootNode)
rootNode = new osg::Group();
+
+ if (!sceneNode)
+ sceneNode = new osg::AutoTransform();
+
+ sceneNode->setScale(VIEWER_SCALE);
+ rootNode->addChild(sceneNode);
// Add world, a Group node containing captured objects
std::map<int, CaptureWorld*> worlds = WorldManager::getInstance()->getWorlds();
for (worlds_iterator itr = worlds.begin(); itr != worlds.end(); itr++)
{
- rootNode->addChild(itr->second->getAsGroup());
+ sceneNode->addChild(itr->second->getAsGroup());
}
// Set the traits for the rendering view
@@ -363,9 +377,9 @@ void AppViewer::initAppViewer(HWND hwnd)
}
bool AppViewer::addNodeToViewer(osg::Node* node) {
- return rootNode->addChild(node);
+ return sceneNode->addChild(node);
}
bool AppViewer::removeNodeFromViewer(osg::Node* node) {
- return rootNode->removeChild(node);
+ return sceneNode->removeChild(node);
}
@@ -20,4 +20,6 @@ namespace AppViewer {
// Add/remove nodes from scene
bool addNodeToViewer(osg::Node* node);
bool removeNodeFromViewer(osg::Node* node);
+ // The Scale of the Viewers Scenes
+ void setScale(int scale);
};
View
@@ -267,6 +267,10 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ worldPropertyColumn
private: System::Windows::Forms::DataGridViewTextBoxColumn^ worldValueColumn;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectPropertyColumn;
private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectValueColumn;
+private: System::Windows::Forms::ToolStrip^ visualToolStrip;
+private: System::Windows::Forms::ToolStripLabel^ visualViewerScaleLabel;
+private: System::Windows::Forms::ToolStripTextBox^ visualViewerScaleTextBox;
+private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
@@ -376,6 +380,10 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectValueColumn;
this->visualTabPage = (gcnew System::Windows::Forms::TabPage());
this->visualMainSplitContainer = (gcnew System::Windows::Forms::SplitContainer());
this->visualSplitContainer = (gcnew System::Windows::Forms::SplitContainer());
+ this->visualToolStrip = (gcnew System::Windows::Forms::ToolStrip());
+ this->visualViewerScaleLabel = (gcnew System::Windows::Forms::ToolStripLabel());
+ this->visualViewerScaleTextBox = (gcnew System::Windows::Forms::ToolStripTextBox());
+ this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->visualOutputLogTextBox = (gcnew System::Windows::Forms::TextBox());
this->visualOutputLogLabel = (gcnew System::Windows::Forms::Label());
this->visualPropertiesTabControl = (gcnew System::Windows::Forms::TabControl());
@@ -436,8 +444,10 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectValueColumn;
this->visualMainSplitContainer->Panel2->SuspendLayout();
this->visualMainSplitContainer->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->visualSplitContainer))->BeginInit();
+ this->visualSplitContainer->Panel1->SuspendLayout();
this->visualSplitContainer->Panel2->SuspendLayout();
this->visualSplitContainer->SuspendLayout();
+ this->visualToolStrip->SuspendLayout();
this->visualPropertiesTabControl->SuspendLayout();
this->rigidBodyTabPage->SuspendLayout();
this->worldTabPage->SuspendLayout();
@@ -1373,6 +1383,7 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectValueColumn;
// visualSplitContainer.Panel1
//
this->visualSplitContainer->Panel1->BackColor = System::Drawing::Color::WhiteSmoke;
+ this->visualSplitContainer->Panel1->Controls->Add(this->visualToolStrip);
//
// visualSplitContainer.Panel2
//
@@ -1383,6 +1394,40 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectValueColumn;
this->visualSplitContainer->SplitterDistance = 376;
this->visualSplitContainer->TabIndex = 0;
//
+ // visualToolStrip
+ //
+ this->visualToolStrip->BackColor = System::Drawing::SystemColors::Window;
+ this->visualToolStrip->GripStyle = System::Windows::Forms::ToolStripGripStyle::Hidden;
+ this->visualToolStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->visualViewerScaleLabel,
+ this->visualViewerScaleTextBox, this->toolStripSeparator1});
+ this->visualToolStrip->Location = System::Drawing::Point(0, 0);
+ this->visualToolStrip->Name = L"visualToolStrip";
+ this->visualToolStrip->Size = System::Drawing::Size(493, 25);
+ this->visualToolStrip->TabIndex = 0;
+ this->visualToolStrip->Text = L"Tool Bar";
+ //
+ // visualViewerScaleLabel
+ //
+ this->visualViewerScaleLabel->ForeColor = System::Drawing::SystemColors::WindowText;
+ this->visualViewerScaleLabel->Name = L"visualViewerScaleLabel";
+ this->visualViewerScaleLabel->Size = System::Drawing::Size(68, 22);
+ this->visualViewerScaleLabel->Text = L"Scene Scale";
+ //
+ // visualViewerScaleTextBox
+ //
+ this->visualViewerScaleTextBox->BackColor = System::Drawing::SystemColors::Window;
+ this->visualViewerScaleTextBox->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
+ this->visualViewerScaleTextBox->ForeColor = System::Drawing::SystemColors::WindowText;
+ this->visualViewerScaleTextBox->Name = L"visualViewerScaleTextBox";
+ this->visualViewerScaleTextBox->Size = System::Drawing::Size(50, 25);
+ this->visualViewerScaleTextBox->Text = L"1.0";
+ this->visualViewerScaleTextBox->TextBoxTextAlign = System::Windows::Forms::HorizontalAlignment::Right;
+ //
+ // toolStripSeparator1
+ //
+ this->toolStripSeparator1->Name = L"toolStripSeparator1";
+ this->toolStripSeparator1->Size = System::Drawing::Size(6, 25);
+ //
// visualOutputLogTextBox
//
this->visualOutputLogTextBox->AcceptsReturn = true;
@@ -1792,10 +1837,14 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectValueColumn;
this->visualMainSplitContainer->Panel2->ResumeLayout(false);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->visualMainSplitContainer))->EndInit();
this->visualMainSplitContainer->ResumeLayout(false);
+ this->visualSplitContainer->Panel1->ResumeLayout(false);
+ this->visualSplitContainer->Panel1->PerformLayout();
this->visualSplitContainer->Panel2->ResumeLayout(false);
this->visualSplitContainer->Panel2->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->visualSplitContainer))->EndInit();
this->visualSplitContainer->ResumeLayout(false);
+ this->visualToolStrip->ResumeLayout(false);
+ this->visualToolStrip->PerformLayout();
this->visualPropertiesTabControl->ResumeLayout(false);
this->rigidBodyTabPage->ResumeLayout(false);
this->worldTabPage->ResumeLayout(false);
@@ -1981,6 +2030,10 @@ private: System::Windows::Forms::DataGridViewTextBoxColumn^ objectValueColumn;
this->optiTrackDataGridView->VirtualMode = true;
// Visual
+ this->visualViewerScaleTextBox->TextChanged +=
+ gcnew System::EventHandler(this, &MainForm::visualViewerScaleTextBox_TextChanged);
+ this->visualViewerScaleTextBox->KeyPress +=
+ gcnew KeyPressEventHandler(this, &MainForm::visualViewerScaleTextBox_KeyPress);
AppViewer::initAppViewer((HWND)this->visualSplitContainer->Panel1->Handle.ToPointer());
this->visualRigidBodyListView->View = View::Details;
@@ -2977,6 +3030,26 @@ private: System::Void removeObjectButton_Click(System::Object^ sender, System::
}
}
}
+private: System::Void visualViewerScaleTextBox_KeyPress(System::Object^ sender, KeyPressEventArgs^ e) {
+ if (!System::Char::IsControl(e->KeyChar)
+ && !System::Char::IsDigit(e->KeyChar)
+ && e->KeyChar != '.')
+ {
+ e->Handled = true;
+ }
+
+ // only allow one decimal point
+ if (e->KeyChar == '.'
+ && this->visualViewerScaleTextBox->Text->IndexOf('.') > -1)
+ {
+ e->Handled = true;
+ }
+ }
+
+private: System::Void visualViewerScaleTextBox_TextChanged(System::Object^ sender, System::EventArgs^ e) {
+ float scale = Convert::ToSingle(this->visualViewerScaleTextBox->Text);
+ AppViewer::setScale(scale);
+ }
};
}
@@ -144,6 +144,9 @@
<metadata name="optiTrackRigidBodyRotationWColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
+ <metadata name="visualToolStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>327, 13</value>
+ </metadata>
<metadata name="worldPropertyColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

0 comments on commit 1d2ac88

Please sign in to comment.