RigsofRods
Soft-body Physics Simulation
FlexObj.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #pragma once
23 
24 #include "Application.h"
25 #include "SimData.h"
26 
27 #include <Ogre.h>
28 
29 namespace RoR {
30 
33 
36 
39 {
40  int node_id;
41  float texcoord_u;
42  float texcoord_v;
43 };
44 
46 struct CabSubmesh
47 {
49 
51 
53  size_t texcoords_pos;
54  size_t cabs_pos;
55 };
56 
59 class FlexObj
60 {
61 public:
62 
63  FlexObj(
64  RoR::GfxActor* gfx_actor,
65  node_t* all_nodes, // For initial setup only, pointer is not stored
66  std::vector<CabTexcoord>& texcoords,
67  int numtriangles,
68  int* triangles,
69  std::vector<CabSubmesh>& submeshes,
70  char* texname,
71  const char* name,
72  char* backtexname,
73  char* transtexname);
74 
75  ~FlexObj();
76 
77  Ogre::Vector3 UpdateFlexObj();
78  void ScaleFlexObj(float factor);
79 
80 private:
81 
83  {
84  Ogre::Vector3 position;
85  Ogre::Vector3 normal;
86  Ogre::Vector2 texcoord;
87  };
88 
90  int ComputeVertexPos(int tidx, int v, std::vector<CabSubmesh>& submeshes);
91  Ogre::Vector3 UpdateMesh();
92 
93  Ogre::MeshPtr m_mesh;
94  std::vector<Ogre::SubMesh*> m_submeshes;
96  float* m_s_ref;
97 
100  Ogre::VertexDeclaration* m_vertex_format;
101  Ogre::HardwareVertexBufferSharedPtr m_hw_vbuf;
102  union
103  {
106  };
107 
109  unsigned short* m_indices;
111 };
112 
115 
116 } // namespace RoRs
RoR::FlexObj::~FlexObj
~FlexObj()
Definition: FlexObj.cpp:237
RoR::FlexObj::UpdateMesh
Ogre::Vector3 UpdateMesh()
Definition: FlexObj.cpp:186
RoR::FlexObj::m_vertex_nodes
int * m_vertex_nodes
Definition: FlexObj.h:99
RoR::FlexObj::FlexObjVertex::texcoord
Ogre::Vector2 texcoord
Definition: FlexObj.h:86
RoR::CabSubmesh::backmesh_type
BackmeshType backmesh_type
Definition: FlexObj.h:52
RoR::FlexObj::m_indices
unsigned short * m_indices
Definition: FlexObj.h:109
RoR::FlexObj::FlexObjVertex::normal
Ogre::Vector3 normal
Definition: FlexObj.h:85
RoR::FlexObj::m_hw_vbuf
Ogre::HardwareVertexBufferSharedPtr m_hw_vbuf
Definition: FlexObj.h:101
RoR::FlexObj
A visual mesh, forming a chassis for softbody actor At most one instance is created per actor.
Definition: FlexObj.h:59
RoR::CabSubmesh::BACKMESH_NONE
@ BACKMESH_NONE
Definition: FlexObj.h:48
RoR::FlexObj::m_vertices_raw
float * m_vertices_raw
Definition: FlexObj.h:104
RoR::CabSubmesh::CabSubmesh
CabSubmesh()
Definition: FlexObj.h:50
RoR::FlexObj::m_vertex_count
size_t m_vertex_count
Definition: FlexObj.h:98
RoR::FlexObj::m_vertices
FlexObjVertex * m_vertices
Definition: FlexObj.h:105
RoR::CabTexcoord::texcoord_u
float texcoord_u
Definition: FlexObj.h:41
RoR::FlexObj::m_mesh
Ogre::MeshPtr m_mesh
Definition: FlexObj.h:93
RoR::FlexObj::FlexObjVertex
Definition: FlexObj.h:82
RoR::FlexObj::m_submeshes
std::vector< Ogre::SubMesh * > m_submeshes
Definition: FlexObj.h:94
RoR::FlexObj::m_s_ref
float * m_s_ref
Definition: FlexObj.h:96
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
RoR::CabSubmesh::BACKMESH_OPAQUE
@ BACKMESH_OPAQUE
Definition: FlexObj.h:48
RoR::FlexObj::m_index_count
size_t m_index_count
Definition: FlexObj.h:108
Application.h
Central state/object manager and communications hub.
RoR::node_t
Physics: A vertex in the softbody structure.
Definition: SimData.h:286
RoR::FlexObj::ComputeVertexPos
int ComputeVertexPos(int tidx, int v, std::vector< CabSubmesh > &submeshes)
Compute vertex position in the vertexbuffer (0-based offset) for node v of triangle tidx
Definition: FlexObj.cpp:158
RoR::CabTexcoord::node_id
int node_id
Definition: FlexObj.h:40
RoR::CabTexcoord::texcoord_v
float texcoord_v
Definition: FlexObj.h:42
RoR::FlexObj::FlexObj
FlexObj(RoR::GfxActor *gfx_actor, node_t *all_nodes, std::vector< CabTexcoord > &texcoords, int numtriangles, int *triangles, std::vector< CabSubmesh > &submeshes, char *texname, const char *name, char *backtexname, char *transtexname)
Definition: FlexObj.cpp:32
RoR::CabSubmesh::BACKMESH_TRANSPARENT
@ BACKMESH_TRANSPARENT
Definition: FlexObj.h:48
RoR::CabSubmesh::cabs_pos
size_t cabs_pos
Definition: FlexObj.h:54
RoR::CabSubmesh
Submesh for old-style actor body (the "cab")
Definition: FlexObj.h:46
RoR::FlexObj::ScaleFlexObj
void ScaleFlexObj(float factor)
Definition: FlexObj.cpp:149
RoR::CabTexcoord
Texture coordinates for old-style actor body (the "cab")
Definition: FlexObj.h:38
RoR::FlexObj::FlexObjVertex::position
Ogre::Vector3 position
Definition: FlexObj.h:84
RoR::GfxActor
Definition: GfxActor.h:52
RoR::FlexObj::m_gfx_actor
RoR::GfxActor * m_gfx_actor
Definition: FlexObj.h:95
RoR::CabSubmesh::texcoords_pos
size_t texcoords_pos
Definition: FlexObj.h:53
RoR::FlexObj::m_triangle_count
int m_triangle_count
Definition: FlexObj.h:110
RoR
Definition: AppContext.h:36
RoR::FlexObj::UpdateFlexObj
Ogre::Vector3 UpdateFlexObj()
Definition: FlexObj.cpp:230
RoR::FlexObj::m_vertex_format
Ogre::VertexDeclaration * m_vertex_format
Definition: FlexObj.h:100
RoR::CabSubmesh::BackmeshType
BackmeshType
Definition: FlexObj.h:48