I'm currently working on a project where I need to read the Oculus Rift DK2 sensors. I have searched the web for usable samples, sadly the only samples I can find cause me a lot of trouble with SDK vesions and such. I found a tutorial on how to implement some basic C++ code to read the pitch, roll & yaw. I used the SDK for Windows V1.8.0.
#include "stdafx.h"
#include <iostream>
#include "../../OculusSDK/LibOVR/Include/OVR_CAPI.h"
#include <thread>
#include <iomanip>
#define COLW setw(15)
using namespace std;
int main()
{
// Initialize our session with the Oculus HMD.
if (ovr_Initialize(nullptr) == ovrSuccess)
{
ovrSession session = nullptr;
ovrGraphicsLuid luid;
ovrResult result = ovr_Create(&session, &luid);
if (result == ovrSuccess)
{ // Then we're connected to an HMD!
// Let's take a look at some orientation data.
ovrTrackingState ts;
while (true)
{
ts = ovr_GetTrackingState(session, 0, true);
ovrPoseStatef tempHeadPose = ts.HeadPose;
ovrPosef tempPose = tempHeadPose.ThePose;
ovrQuatf tempOrient = tempPose.Orientation;
cout << "Orientation (x,y,z): " << COLW << tempOrient.x << ","
<< COLW << tempOrient.y << "," << COLW << tempOrient.z
<< endl;
// Wait a bit to let us actually read stuff.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
ovr_Destroy(session);
}
ovr_Shutdown();
// If we've fallen through to this point, the HMD is no longer
// connected.
}
return 0;
}
there are (as far as I know) no problems with this part.
when I included the OVR_CAPI.h the OVR_CAPI.cpp magically appears in the folder where OVR_CAPI.h is located. this cpp file contains the following:
#include "stdafx.h"
#include "OVR_CAPI.h"
OVR_PUBLIC_FUNCTION(ovrResult) ovr_Initialize(const ovrInitParams * params)
{
return OVR_PUBLIC_FUNCTION(ovrResult)();
}
when I try to build it errors:"expected an expression" and " C2062(type 'int' unexpected)" occur,both on Line 6.
is anyone familiar with this problem or can someone give me advice on how to get started with Oculus software?
You have included the source of the LibOVR. You have to compile LibOVR to a .lib file in visual studio and add that to your project instead.
Step 1
In the LibOVR folder, there should be a "Projects folder". Open the version for your visual studio version.
Step 2
Compile the LibOVR project (in release mode), this shouldn't give any errors. If it does, the library might be corrupted. Try downloading the source again from the oculus website or try a different version.
Step 3
When successful copy the LibOVR.lib file from the build folder and the "Include" folder to your own project (I suggest creating a new "libs" folder in your project directory).
Step 4
Close the LibOVR project and open your own. Open the property window for your project and in VC++ Directories add the "Include" folder to the "Include Directories". Also add the the folder where the .lib file is located to the "Library Directories".
Finally in the "Linker->Input" settings add LibOVR.lib to the "Additional Dependencies" if you didn't already.
Step 5
Add this to your main.cpp file
#include <OVR_CAPI.h>
Try compiling your project. Everything should work now.
Related
Hello I am currently following a book on c++ and currently learning on file i/o
I am trying to open a .txt file and the result is everytime "could not open file
#include <iostream>
#include <filesystem>
using namespace std;
int main(int argc, char* argv[])
{
ifstream file_reader("myfile.txt");
if (!file_reader.is_open()) {
cout << "could not open file" << "\n";
}
int number;
file_reader >> number;
return 0;
}
I'v tried to put the .txt file into debug folder and project folder but no success.
By default, Visual Studio C++ projects execute with the directory containing the .vcxproj file as the working directory (where all file operations are relative to).
You can see this if you right click your project in the "Solution Explorer" -> "Properties" menu item. The on the left of the new window select "Debugging". On the right the "Working Directory" item is most likely set to "$(ProjectDir)".
project folder but no success.
So assuming you didn't change that setting, this should definitely work. Make sure you did place the file there, and that it is properly named (if using Explorer, be sure to have "File name extensions" enabled under "View", so you don't end up making like a myfile.txt.txt by mistake).
It is also possible opening the file fails for some other reason (unfortunately C++ error reporting on this is extremely limited). For example if the file permissions do not allow your program to read it.
If still no luck, you could maybe try writing a file, and see where it puts it.
ofstream file_writer("lostfile.txt");
i m trying to use sfml in my project using visual studio 2019. Following sfml documentation to perform setup for visual studio i have performed all the action required
i have included include folder in c/c++/additional include directory and also provided path for lib folder in linker setting and also provided additional dependencies in linker/input
but
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
std::cout << "i cant tolerate" << std::endl;
return 0;
}
this code shows above mentioned error ,
cannot open include file 'Graphics.hpp' no such file or directory
it seems like include path is not working
how can i solve this issue
i tried many times but got same result
if anyone facing the same problem please check the platform in the project/properties win32 worked for my particular problem
I am starting to learn how to use Sqlite and build databases however I would like to be able to work with these databases in C++. Whenever I start I am unable to accomplish anything because Visual Studio gives me the error in the title. when I try:
#include <sqlite3.h>
I have tried moving all of the code from sqlite's amalgamation into my project file and it still did not work. I tried using:
"sqlite3.h"
instead of
<sqlite3.h>
I also added the 'amalgamation' folder as a directory which makes the first error away but I am given a linker error on the build.
I feel as though I missed something in the setup that is not allowing me to do continue, but I have searched everything I can imagine and found no answers. Any help would be greatly appreciated. Thank you.
UPDATE: I am in a CLR project because I will need to attach a GUI to this Database and I am unable to compile the .c files from the amalgamation. Those files seem to be the solution to my problem though, so is there any way to get around that issue of a C file not being able to be compiled in a CLR project?
The following method demonstrate how to link with sqlite3.dll.
Download and copy the following folder to your Visual C++ solution folder.
https://github.com/mcychan/DNAssist/tree/master/sqlite3
The sqlite3 folder contains both x86 and x64 version of sqlite dll and lib.
You may upgrade to latest version of sqlite.dll.
Download and copy the following files to your Visual C++ project folder, add reference for them.
https://github.com/mcychan/DNAssist/blob/master/DNAssist/CppSQLite3.cpp
https://github.com/mcychan/DNAssist/blob/master/DNAssist/CppSQLite3.h
The following is the sample code to query the database.
#include "CppSQLite3.h"
#include <iostream>
#include <string>
using namespace std;
CppSQLite3DB db;
bool GetDatabase(const string& dbPath)
{
try {
db.open(dbPath.c_str());
return true;
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot open database: ") << dbPath << _T("\n");
return false;
}
}
void IssueQuery(const string& querystring, const string& field1)
{
try {
CppSQLite3Query q = db.execQuery(querystring.c_str());
while (!q.eof()) {
CString temp2(q.fieldValue(field1.c_str()));
TRACE(temp2 + _T("\n"));
q.nextRow();
}
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot execute query: ") << querystring << _T("\n");
}
}
void main()
{
if(GetDatabase("C:\\test.sqlite"))
IssueQuery("SELECT * FROM DUAL", "X");
}
I'm running VS2015 on Windows 10 and I'm having issues with include directories. I have setup the Additional Include Directories in C/C++ -> General and Include Directories in VC++ Directories to point to the right path (F:\boost_1_61_0). I keep getting the "Cannot open source file" error. If I move the cursor to the include statement the full include path in the Definition bar points to the correct address. This also happens when working with Google Mock. All the core and STL includes work just fine.
I've stripped down the code to try and just get it to work on this basic Boost test code:
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
I've successfully built this code using Netbeans by adding the additional include directory to the project without any issues, so its not a file access issue. The compiler used from Netbeans was G++, but from VS I used MSVC and tried ICP with the same results.
Thanks,
As The Dark states above: make sure you check that the build properties match.
i am learning vc++ and i make my first application win32 console and just write simple code and i get 20 error from external files automatic included
i change compile as to c++ and not using precompiled headers but stil have errors
here is my code
#include <iostream>
int main()
{
//cout << "hello !" << endl;
return 0;
}
how can i fix it ?
Edit :
i have win7 and vs2015 perhaps helps
Edit 2:
last picture is for an empty project this one is for a win32 console app
I think you have created a project set to use precompiled header. Can you start with an empty project and add source file?
And don't forget to set "Not using precomplied header" in file option