2017-05-02 5 views
1

Momentan arbeite ich an einem ADAS-Projekt zur Visualisierung von Straßenmodellen (Fahrbahnmitte, Fahrbahnbegrenzungen etc.) mit ROS und OGRE (Object-Oriented Graphics Rendering Engine). Eingaben sind Geometriepunkte (x, y, z).Texturkoordinaten in Ogre

Ich kann die Linien mit Ogre :: RenderOperation :: OT_TRIANGLE_STRIP zeichnen. Ich habe Materialien erstellt, um durchgezogene Linien, gepunktete Lügen, doppelte durchgezogene Linien usw. eindeutig zu visualisieren. Wie finde ich Texturkoordinaten für diese Geometriepunkte?

Aktuelle Code sieht wie folgt aus:

geometry_msgs::Point p0 = _msg.shape_points.front(); 

    for(int i = 1; i < _msg.shape_points.size(); ++i) 
    { 
     const geometry_msgs::Point& p1(_msg.shape_points[i]); 
     const float dx = p1.x - p0.x; 
     const float dy = p1.y - p0.y; 
     const float phi = atan2(dy, dx); 
     const float wx = sin(phi) * lane_mark_width_; 
     const float wy = -cos(phi) * lane_mark_width_; 

     if (i == 1) 
     { 
      lane_boundary_->position(p0.x - wx, p0.y - wy, p0.z); 
      lane_boundary_->textureCoord(p0.x , p0.y); 

      lane_boundary_->position(p0.x + wx, p0.y + wy, p0.z); 
      lane_boundary_->textureCoord(p0.x, p0.y); 
     } 

     lane_boundary_->position(p1.x - wx, p1.y - wy, p1.z); 
     lane_boundary_->textureCoord(p1.x, p1.y); 

     lane_boundary_->position(p1.x + wx, p1.y + wy, p1.z); 
     lane_boundary_->textureCoord(p1.x, p1.y); 

     p0 = p1; 
    } 

Danke

+0

Was ist der Typ von 'lane_boundary_'? – pergy

+0

Es ist ein manuelles Objekt: Ogre :: ManualObject * lane_boundary_ – StrongSoul

+0

dann, ich weiß nicht, wie das funktionieren kann, weil Sie Ihre Zeichenaufrufe zwischen 'beginnen' und 'end' aufrufen müssen, wie in [Docs ] (http://www.ogre3d.org/docs/api/1.9/class_ogre_1_1_manual_object.html#details). Für die spätere Aktualisierung verwenden Sie 'beginUpdate'. – pergy

Antwort

0

Texturkoordinaten müssen im Bereich [0, 1] sein. Dabei steht [0, 0] an der oberen linken Ecke einer Textur und [1,1] ist unten rechts.

Ich nehme an, Sie möchten, dass die Textur einem Streifen entlang der y-Achse zugeordnet wird (vertikale Achse in der Textur, Y-Koordinatenbereich). Ich gehe auch davon aus, dass Ihre Koordinatengenerierung entlang der Linie angeordnet ist.

geometry_msgs::Point p0 = _msg.shape_points.front(); 

//Offset in between two points is fixed 
const float uv_step = 1.0f/_msg.shape_points.size(); 

    for(int i = 1; i < _msg.shape_points.size(); ++i) 
    { 
     const geometry_msgs::Point& p1(_msg.shape_points[i]); 
     const float dx = p1.x - p0.x; 
     const float dy = p1.y - p0.y; 
     const float phi = atan2(dy, dx); 
     const float wx = sin(phi) * lane_mark_width_; 
     const float wy = -cos(phi) * lane_mark_width_; 

     //Compute the vertical texture coordinate 
     const float v = i * uv_step; 

     if (i == 1) 
     { 
      lane_boundary_->position(p0.x - wx, p0.y - wy, p0.z); 
      //First point is at the top left corner 
      lane_boundary_->textureCoord(0.0f, 0.0f); 

      lane_boundary_->position(p0.x + wx, p0.y + wy, p0.z); 
      //Second point is a the the top right corner 
      lane_boundary_->textureCoord(1.0f, 0.0f); 
     } 

     lane_boundary_->position(p1.x - wx, p1.y - wy, p1.z); 
     //Along the y axis on the left 
     lane_boundary_->textureCoord(0.0f, v); 

     lane_boundary_->position(p1.x + wx, p1.y + wy, p1.z); 
     //Along the Y axis on the right 
     lane_boundary_->textureCoord(1.0f, v); 

     p0 = p1; 
    } 

Stellen Sie sicher, dass Sie die gleiche Art von Texturzuordnung haben möchten. Wenn sich die Textur oder die Koordinaten nicht auf der rechten Achse befinden, passen Sie den Code so an, dass er auf der gewünschten Achse interpoliert.

+0

Vielen Dank für die Antwort. In meinem Fall ist die Achse dynamisch. Die Eingänge sind vom Echtzeitsystem und ändern sich entsprechend der Richtung des Fahrzeugs. Können wir diese Implementierung dynamisch machen? – StrongSoul

Verwandte Themen