mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 03:19:19 +02:00
pch migration to modules [wip]
This commit is contained in:
104
model/vertex.cppm
Normal file
104
model/vertex.cppm
Normal file
@@ -0,0 +1,104 @@
|
||||
module;
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
export module eu07.model.vertex;
|
||||
import eu07.glm;
|
||||
|
||||
export {
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
|
||||
// geometry vertex with double precision position
|
||||
struct world_vertex {
|
||||
|
||||
// members
|
||||
glm::dvec3 position;
|
||||
glm::vec3 normal;
|
||||
glm::vec2 texture;
|
||||
|
||||
static world_vertex lerp(world_vertex const &a, world_vertex const &b, double factor)
|
||||
{
|
||||
return static_cast<world_vertex>(a * (1.0f - factor) + b * factor);
|
||||
}
|
||||
|
||||
// overloads
|
||||
// operator+
|
||||
template <typename Scalar_>
|
||||
world_vertex &
|
||||
operator+=( Scalar_ const &Right ) {
|
||||
position += Right;
|
||||
normal += Right;
|
||||
texture += Right;
|
||||
return *this; }
|
||||
template <typename Scalar_>
|
||||
friend
|
||||
world_vertex
|
||||
operator+( world_vertex Left, Scalar_ const &Right ) {
|
||||
Left += Right;
|
||||
return Left; }
|
||||
// operator*
|
||||
template <typename Scalar_>
|
||||
world_vertex &
|
||||
operator*=( Scalar_ const &Right ) {
|
||||
position *= Right;
|
||||
normal *= Right;
|
||||
texture *= Right;
|
||||
return *this; }
|
||||
template <typename Type_>
|
||||
friend
|
||||
world_vertex
|
||||
operator*( world_vertex Left, Type_ const &Right ) {
|
||||
Left *= Right;
|
||||
return Left; }
|
||||
// methods
|
||||
void serialize( std::ostream& ) const;
|
||||
void deserialize( std::istream& );
|
||||
// wyliczenie współrzędnych i mapowania punktu na środku odcinka v1<->v2
|
||||
void
|
||||
set_half( world_vertex const &Vertex1, world_vertex const &Vertex2 ) {
|
||||
*this =
|
||||
world_vertex::lerp(
|
||||
Vertex1,
|
||||
Vertex2,
|
||||
0.5 ); }
|
||||
// wyliczenie współrzędnych i mapowania punktu na odcinku v1<->v2
|
||||
void
|
||||
set_from_x( world_vertex const &Vertex1, world_vertex const &Vertex2, double const X ) {
|
||||
*this =
|
||||
world_vertex::lerp(
|
||||
Vertex1,
|
||||
Vertex2,
|
||||
( X - Vertex1.position.x ) / ( Vertex2.position.x - Vertex1.position.x ) ); }
|
||||
// wyliczenie współrzędnych i mapowania punktu na odcinku v1<->v2
|
||||
void
|
||||
set_from_z( world_vertex const &Vertex1, world_vertex const &Vertex2, double const Z ) {
|
||||
*this =
|
||||
world_vertex::lerp(
|
||||
Vertex1,
|
||||
Vertex2,
|
||||
( Z - Vertex1.position.z ) / ( Vertex2.position.z - Vertex1.position.z ) ); }
|
||||
};
|
||||
|
||||
} // export -- out-of-line member definitions and explicit
|
||||
// specialisations are not namespace-scope declarations, so they cannot
|
||||
// carry `export`; the class itself is exported and that is what counts.
|
||||
template <>
|
||||
world_vertex &
|
||||
world_vertex::operator+=( world_vertex const &Right );
|
||||
|
||||
template <>
|
||||
world_vertex &
|
||||
world_vertex::operator*=( world_vertex const &Right );
|
||||
export {
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
} // export
|
||||
Reference in New Issue
Block a user