Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[Irrlicht] Renderowanie Tekstury

Ostatnio zmodyfikowano 2024-02-19 16:47
Autor Wiadomość
tBane
Temat założony przez niniejszego użytkownika
[Irrlicht] Renderowanie Tekstury
» 2024-02-19 15:26:03
Witam.
Piszę prostą mapę do gry i potrzebuję nałożyć teksturę na sześciokątną figurę (HexTile).
Nie wiem gdzie w moim kodzie jest błąd.


C/C++
float outerRadius = 10.0f;
float innerRadius = outerRadius * 0.866025404f;

class HexTile
    : public scene::ISceneNode
{
   
   
core::aabbox3d < f32 > Box;
   
video::S3DVertex Vertices[ 8 ];
   
video::SMaterial Material;
   
public:
   
   
HexTile( scene::ISceneNode * parent, scene::ISceneManager * mgr, s32 id )
        :
scene::ISceneNode( parent, mgr, id )
   
{
       
Material.Wireframe = false;
       
Material.Lighting = false;
       
Material.setTexture( 0, driver->getTexture( "Media/grass.png" ) );
       
       
// verticves of hexagons
       
Vertices[ 0 ] = video::S3DVertex( 0, 0, 0, 0, 0, 0, video::SColor( 255, 48, 48, 48 ), 0, 0 ); // CENTER OF HEXTILE
       
Vertices[ 1 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
       
Vertices[ 2 ] = video::S3DVertex( innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
       
Vertices[ 3 ] = video::S3DVertex( innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
       
Vertices[ 4 ] = video::S3DVertex( 0.0f, 0, - outerRadius, 0, 0, 0, video::SColor( 255, 128, 128, 48 ), 0, 0 );
       
Vertices[ 5 ] = video::S3DVertex( - innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
       
Vertices[ 6 ] = video::S3DVertex( - innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
       
Vertices[ 7 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, 0 );
       
       
       
       
Box.reset( Vertices[ 0 ].Pos );
       
for( s32 i = 1; i < 7; ++i )
           
 Box.addInternalPoint( Vertices[ i ].Pos );
       
   
}
   
   
virtual void OnRegisterSceneNode()
   
{
       
if( IsVisible )
           
 SceneManager->registerNodeForRendering( this );
       
       
ISceneNode::OnRegisterSceneNode();
   
}
   
   
virtual void render()
   
{
       
u16 indices[ ] = { 0, 1, 2, /**/ 0, 2, 3, /**/ 0, 3, 4, /**/ 0, 4, 5, /**/ 0, 5, 6, /**/ 0, 6, 7 };
       
IVideoDriver * driver = SceneManager->getVideoDriver();
       
driver->setMaterial( Material );
       
driver->setTransform( video::ETS_WORLD, AbsoluteTransformation );
       
driver->drawVertexPrimitiveList( & Vertices[ 0 ], 3, & indices[ 0 ], 6, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT );
       
   
}
   
   
virtual const core::aabbox3d < f32 > & getBoundingBox() const
   
{
       
return Box;
   
}
   
   
virtual u32 getMaterialCount() const
   
{
       
return 1;
   
}
   
   
virtual video::SMaterial & getMaterial( u32 i )
   
{
       
return Material;
   
}
}
;
P-180828
tBane
Temat założony przez niniejszego użytkownika
» 2024-02-19 16:18:00
Zmieniłem parametry centralnego punktu i faktycznie renderuje tylko jeden kolor. Jak to naprawić ?

C/C++
Vertices[ 0 ] = video::S3DVertex( 0, 0, 0, 0, 0, 0, video::SColor( 255, 255, 255, 255 ), 0, 0 ); // CENTER OF HEXTILE

P-180829
DejaVu
» 2024-02-19 16:20:01
Może nie załadowałeś tekstury w ogóle?
P-180830
tBane
Temat założony przez niniejszego użytkownika
» 2024-02-19 16:26:57
Załadowałem. W miejsca tu, tv (współrzędne tekstury) wstawiłem współrzędne wierzchołków oto jaki efekt otrzymałem.

C/C++
// verticves of hexagons
Vertices[ 0 ] = video::S3DVertex( 0, 0, 0, 0, 0, 0, video::SColor( 255, 255, 255, 255 ), 0, 0 ); // CENTER OF HEXTILE
Vertices[ 1 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, outerRadius );
Vertices[ 2 ] = video::S3DVertex( innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), innerRadius, outerRadius * 0.5f );
Vertices[ 3 ] = video::S3DVertex( innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), innerRadius, - outerRadius * 0.5f );
Vertices[ 4 ] = video::S3DVertex( 0.0f, 0, - outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, - outerRadius );
Vertices[ 5 ] = video::S3DVertex( - innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), - innerRadius, - outerRadius * 0.5f );
Vertices[ 6 ] = video::S3DVertex( - innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), - innerRadius, outerRadius * 0.5f );
Vertices[ 7 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, video::SColor( 255, 128, 48, 48 ), 0, outerRadius );

P-180831
tBane
Temat założony przez niniejszego użytkownika
» 2024-02-19 16:26:57
W miejsca tu, tv (współrzędne tekstury) wstawiłem dane z zakresu [0.0f, 1.0f].
Problem rozwiązany!

C/C++
video::SColor color = video::SColor( 255, 255, 255, 255 );

// verticves of hexagons
Vertices[ 0 ] = video::S3DVertex( 0, 0, 0, 0, 0, 0, color, 0, 0 ); // CENTER OF HEXTILE
Vertices[ 1 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, color, 0, 1 );
Vertices[ 2 ] = video::S3DVertex( innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, color, 1, 0.5f );
Vertices[ 3 ] = video::S3DVertex( innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, color, 1, - 0.5f );
Vertices[ 4 ] = video::S3DVertex( 0.0f, 0, - outerRadius, 0, 0, 0, color, 0, - 1 );
Vertices[ 5 ] = video::S3DVertex( - innerRadius, 0, - outerRadius * 0.5f, 0, 0, 0, color, - 1, - 0.5f );
Vertices[ 6 ] = video::S3DVertex( - innerRadius, 0, outerRadius * 0.5f, 0, 0, 0, color, - 1, 0.5f );
Vertices[ 7 ] = video::S3DVertex( 0.0f, 0, outerRadius, 0, 0, 0, color, 0, 1 );

P-180832
« 1 »
  Strona 1 z 1