Walters.Robert Posted August 1, 2019 Posted August 1, 2019 Is it possible to get some documentation or a tutorial on the IG Symbol classes?
cash-metall Posted August 2, 2019 Posted August 2, 2019 Hello! We support symbols in the experimental mode. As far as I know, our clients haven't tried theis feature yet. At the moment symbols have the following limitations: - there are no dotted lines. - fixed_scale does not work for SymbolsPlane - there are no ig-predefined templates otherwise, the symbols must comply with the CIGI ICD 3.3 documentation.
Walters.Robert Posted August 2, 2019 Author Posted August 2, 2019 Thanks, I'm trying to draw a heads up display from scratch. Due to the limitations on my HOST computer software I can't send symbol packets directly from the HOST. My plan is to take the attitude and position information received over CIGI and then code the rest directly in Unigine using the Symbols classes to draw the HUD. For some reason the following code ends up adding the profiler overlay: IG::ISymbolsController *myController; myController->createSymbol(IG::ISymbolsController::SYMBOL_TYPE::TEXT,0); The program runs fine. If I then add: myController->getSymbol(0)->setColor(vec4(0.0f, 1.0f, 0.0f, 1.0f)); the program compiles but crashes with no reason given in the log.
cash-metall Posted August 5, 2019 Posted August 5, 2019 (edited) On 8/2/2019 at 10:53 PM, Walters.Robert said: For some reason the following code ends up adding the profiler overlay It is very strange. We do not control the display of the profiler. On 8/2/2019 at 10:53 PM, Walters.Robert said: the program compiles but crashes with no reason given in the log. I checked your case, and I am not getting any errors. I need more information, where do you call this code? UPD: I found this bug: The ISymbol must be immediately added to the ISymbolPlane. Some ISymbol`s methods call sort on the plane. Without a plane, the program crashes. We will fix it. thanks! here is a simple example: IG::ISymbolsController *myController = ig_manager->getSymbolsController(); IG::ISymbolsPlane *plane = myController->createPlane(0, ig_manager->getView(0)); // create plane on view IG::ISymbolText *symbol_text = dynamic_cast<IG::ISymbolText *>(myController->createSymbol(IG::ISymbolsController::SYMBOL_TYPE::TEXT, 0)); plane->addSymbol(symbol_text); // add symbol to plane symbol_text->setText("Hello world!"); symbol_text->setOffset(400,400); symbol_text->setFontSize(12); myController->getSymbol(0)->setColor(vec4::RED); methods are not working at the moment: SymbolText::setFont SymbolText::setAligin SymbolText::setOrientation Edited August 5, 2019 by cash-metall bug found
Walters.Robert Posted August 6, 2019 Author Posted August 6, 2019 Thanks. Your example code has me up and running, however, I need just a bit more help. I'm trying to take a float and return it as text however the setText() function only accepts const char* and not string or float. I think I'm casting from float to string but I can't figure out how to go the final step from string to const char*. My googling in stack overflow hasn't helped. for (int i = 40; i < 40 + 2 * 18; i++) {//create the attitude bar labels IG::ISymbolText *hudHorizonLabel = dynamic_cast<IG::ISymbolText *>(myController->createSymbol(IG::ISymbolsController::SYMBOL_TYPE::TEXT, i)); plane->addSymbol(hudHorizonLabel); if (i % 2 == 0) {//long lines on the 10 degree increments float evens = (i - 40.0f)*10.0f; String *str = new String(); StringStack<> str = String::ftoa(evens, 0); ????? const char *str; ????? //this is where I'm lost hudHorizonLabel->setText(str); hudHorizonLabel->setFontSize(20); } else {//short lines on 5 degree increments float odds = (i - 40.0f)*5.0f; String *str = new String(); StringStack<> str = String::ftoa(odds, 0); ????? const char *str; ????? //this is where I'm lost hudHorizonLabel->setText(str); hudHorizonLabel->setFontSize(20); } }
Walters.Robert Posted August 7, 2019 Author Posted August 7, 2019 Never mind I figured it out. Here is my solution for those that may be working on a similar project. char buffer[32]; int ret = snprintf(buffer, sizeof buffer, "%i", evens); hudHorizonLabel->setText(buffer);
Walters.Robert Posted August 7, 2019 Author Posted August 7, 2019 My HUD overlaying is coming along nicely. https://youtu.be/OOzTnJW2NYw I'd like to display the altitude numerically on the right hand side of the HUD. I can add text but I'm having trouble getting it to update. I've been initializing the HUD under AppWorldLogic::init_HUD() and then calling init_HUD() in AppWorldLogic::init(), init_HUD() is public. I can access the getSymbol(id) method through ig_manager in AppWorldLogic::update() but there is no way to access the methods for the derived class ISymbolText, only the ISymbol (base class) methods. If I try to add symbols to AppWorldLogic::update() like I do when I initialized them in init_HUD() in order to have access to the derived method setText() then the program complies but crashes. I have also tried adding the following as public in the AppWorldLogic.h IG::ISymbolText *symbol_text; but if I then try symbol_text->setText("some new text"); in AppWorldLogic::update() the program compiles but crashes. The end goal would be something like the following: //AppWorldLogic.cpp AppWorldLogic::update(){ dvec3 myPosition = ig_manager->getEntity(0)->getGeoPosition(); //get the position information double myAltDouble = myPosition.z; //get just the altitude portion of the position int myAltInt = int(myAltDouble); //convert the double to an int char buffer[32]; //create a char buffer to store the int int ret = snprintf(buffer, sizeof buffer, "%i", myAltInt); //solves the problem changing the int to a char symbol_text->setText(buffer); //the crash occurs here }
cash-metall Posted August 8, 2019 Posted August 8, 2019 14 hours ago, Walters.Robert said: char buffer[32]; int ret = snprintf(buffer, sizeof buffer, "%i", evens); hudHorizonLabel->setText(buffer); Unigine::String has method get() usually we use so String a = "text"; label.setText(String::format("my string %d %f %s \n", 1, 2.5, a.get()).get()) 9 hours ago, Walters.Robert said: I can access the getSymbol(id) method through ig_manager in AppWorldLogic::update() but there is no way to access the methods for the derived class ISymbolText, only the ISymbol (base class) methods. to access SymbolText methods, you need to cast Symbol to type SymbolText IG::ISymbolText * text = dynamic_cast<IG::ISymbolText *>(ig_manager->getSymbolsController()->getSymbol(0)); if (text) { text->setText(" hello world"); } 9 hours ago, Walters.Robert said: If I try to add symbols to AppWorldLogic::update() like I do when I initialized them in init_HUD() in order to have access to the derived method setText() then the program complies but crashes. I do not quite understand what the problem is. Сan you send a crash callstack? I tried to do the same, everything works fine for me: int AppWorldLogic::init() { IG::ISymbolsController *myController = ig_manager->getSymbolsController(); IG::ISymbolsPlane *plane = myController->createPlane(0, ig_manager->getView(0)); // create plane on view //IG::ISymbolText *symbol_text - is a member of the AppWorldLogic class symbol_text = dynamic_cast<IG::ISymbolText *>(myController->createSymbol(IG::ISymbolsController::SYMBOL_TYPE::TEXT, 0)); plane->addSymbol(symbol_text); // add symbol to plane symbol_text->setText("Hello world!"); symbol_text->setOffset(600,400); symbol_text->setFontSize(25); myController->getSymbol(0)->setColor(vec4::RED); return 1; } int AppWorldLogic::update() { int z = ig_manager->getEntity(0)->getGeoPosition().z; symbol_text->setText(String::itoa(z).get()); // or you can use this // IG::ISymbolText * text = dynamic_cast<IG::ISymbolText *>(ig_manager->getSymbolsController()->getSymbol(0)); // text->setText(String::itoa(z).get()); return 1; } symbols.mp4
Walters.Robert Posted August 8, 2019 Author Posted August 8, 2019 (edited) Thanks cash-metal! Changing the line from: IG::ISymbolText *symbol_text = dynamic_cast<IG::ISymbolText *>(myController->createSymbol(IG::ISymbolsController::SYMBOL_TYPE::TEXT, 0)); To symbol_text = dynamic_cast<IG::ISymbolText *>(myController->createSymbol(IG::ISymbolsController::SYMBOL_TYPE::TEXT, 0)); Fixed the crash problem. video with working numeric altitude and heading: https://www.youtube.com/watch?v=UWtaHmgsMdM&feature=youtu.be Edited August 8, 2019 by Walters.Robert added video 2
Recommended Posts