mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-04-21 21:51:22 +02:00
Started implementing the classes.
This commit is contained in:
parent
d81a9f2470
commit
3fe760dca3
128
01_alapok/.clang-format
Normal file
128
01_alapok/.clang-format
Normal file
@ -0,0 +1,128 @@
|
||||
# Commented out parameters are those with the same value as base LLVM style
|
||||
# We can uncomment them if we want to change their value, or enforce the
|
||||
# chosen value in case the base style changes (last sync: Clang 6.0.1).
|
||||
---
|
||||
### General config, applies to all languages ###
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
# AlignConsecutiveAssignments: false
|
||||
# AlignConsecutiveDeclarations: false
|
||||
# AlignEscapedNewlines: Right
|
||||
# AlignOperands: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
# AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
# AllowShortLoopsOnASingleLine: false
|
||||
# AlwaysBreakAfterDefinitionReturnType: None
|
||||
# AlwaysBreakAfterReturnType: None
|
||||
# AlwaysBreakBeforeMultilineStrings: false
|
||||
# AlwaysBreakTemplateDeclarations: false
|
||||
# BinPackArguments: true
|
||||
# BinPackParameters: true
|
||||
# BraceWrapping:
|
||||
# AfterClass: false
|
||||
# AfterControlStatement: false
|
||||
# AfterEnum: false
|
||||
# AfterFunction: false
|
||||
# AfterNamespace: false
|
||||
# AfterObjCDeclaration: false
|
||||
# AfterStruct: false
|
||||
# AfterUnion: false
|
||||
# AfterExternBlock: false
|
||||
# BeforeCatch: false
|
||||
# BeforeElse: false
|
||||
# IndentBraces: false
|
||||
# SplitEmptyFunction: true
|
||||
# SplitEmptyRecord: true
|
||||
# SplitEmptyNamespace: true
|
||||
# BreakBeforeBinaryOperators: None
|
||||
# BreakBeforeBraces: Attach
|
||||
# BreakBeforeInheritanceComma: false
|
||||
BreakBeforeTernaryOperators: false
|
||||
# BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: AfterColon
|
||||
# BreakStringLiterals: true
|
||||
ColumnLimit: 0
|
||||
# CommentPragmas: '^ IWYU pragma:'
|
||||
# CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 8
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
# DerivePointerAlignment: false
|
||||
# DisableFormat: false
|
||||
# ExperimentalAutoDetectBinPacking: false
|
||||
# FixNamespaceComments: true
|
||||
# ForEachMacros:
|
||||
# - foreach
|
||||
# - Q_FOREACH
|
||||
# - BOOST_FOREACH
|
||||
# IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '".*"'
|
||||
Priority: 1
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*'
|
||||
Priority: 3
|
||||
# IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: true
|
||||
# IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
# IndentWrappedFunctionNames: false
|
||||
# JavaScriptQuotes: Leave
|
||||
# JavaScriptWrapImports: true
|
||||
# KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
# MacroBlockBegin: ''
|
||||
# MacroBlockEnd: ''
|
||||
# MaxEmptyLinesToKeep: 1
|
||||
# NamespaceIndentation: None
|
||||
# PenaltyBreakAssignment: 2
|
||||
# PenaltyBreakBeforeFirstCallParameter: 19
|
||||
# PenaltyBreakComment: 300
|
||||
# PenaltyBreakFirstLessLess: 120
|
||||
# PenaltyBreakString: 1000
|
||||
# PenaltyExcessCharacter: 1000000
|
||||
# PenaltyReturnTypeOnItsOwnLine: 60
|
||||
# PointerAlignment: Right
|
||||
# RawStringFormats:
|
||||
# - Delimiter: pb
|
||||
# Language: TextProto
|
||||
# BasedOnStyle: google
|
||||
# ReflowComments: true
|
||||
# SortIncludes: true
|
||||
# SortUsingDeclarations: true
|
||||
# SpaceAfterCStyleCast: false
|
||||
# SpaceAfterTemplateKeyword: true
|
||||
# SpaceBeforeAssignmentOperators: true
|
||||
# SpaceBeforeParens: ControlStatements
|
||||
# SpaceInEmptyParentheses: false
|
||||
# SpacesBeforeTrailingComments: 1
|
||||
# SpacesInAngles: false
|
||||
# SpacesInContainerLiterals: true
|
||||
# SpacesInCStyleCastParentheses: false
|
||||
# SpacesInParentheses: false
|
||||
# SpacesInSquareBrackets: false
|
||||
TabWidth: 4
|
||||
UseTab: Always
|
||||
---
|
||||
### C++ specific config ###
|
||||
Language: Cpp
|
||||
Standard: Cpp03
|
||||
---
|
||||
### ObjC specific config ###
|
||||
Language: ObjC
|
||||
Standard: Cpp03
|
||||
ObjCBlockIndentWidth: 4
|
||||
# ObjCSpaceAfterProperty: false
|
||||
# ObjCSpaceBeforeProtocolList: true
|
||||
---
|
||||
### Java specific config ###
|
||||
Language: Java
|
||||
# BreakAfterJavaFieldAnnotations: false
|
||||
JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax']
|
||||
...
|
13
01_alapok/compile.sh
Executable file
13
01_alapok/compile.sh
Executable file
@ -0,0 +1,13 @@
|
||||
|
||||
if [ ! -d "obj" ]; then
|
||||
mkdir obj
|
||||
fi
|
||||
|
||||
if [ ! -d "bin" ]; then
|
||||
mkdir bin
|
||||
fi
|
||||
|
||||
g++ -Wall -g -Iinclude -c main.cpp -o obj/main.o
|
||||
g++ -Wall -g -Iinclude -c vector2.cpp -o obj/vector2.o
|
||||
g++ -o bin/program obj/main.o obj/vector2.o
|
||||
|
7
01_alapok/main.cpp
Normal file
7
01_alapok/main.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#include<iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "asd" << std::endl;
|
||||
return 0;
|
||||
}
|
121
01_alapok/vector2.cpp
Normal file
121
01_alapok/vector2.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include "vector2.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
/*
|
||||
| + abs() : Vector2 | -> visszaadja egy új vektorba ennek a vektornak az abszolút értékét. (x, y abszolút értékét veszi)
|
||||
| + angle() float | -> atan2(x, y)
|
||||
| + angle_to(b : Vector2) : float | -> atan2(cross(b), dot(b));
|
||||
| + cross(b : Vector2) : float | -> Cross product -> x * b.y - y * b.x;
|
||||
| + clamped(len : float) : Vector2 | -> normalized() * len
|
||||
| + direction_to(b : Vector2) : Vector2 | -> Visszaad egy normalizált vektort ami ebből b be mutat. (A képlet: (b - a).normalized()) (operator-)
|
||||
| + distance_to_squared(b : Vector2) : float | -> (x - b.x) * (x - b.x) + (y - b.y) * (y - b.y);
|
||||
| + distance_to(b : Vector2) : float | -> sqrt((x - b.x) * (x - b.x) + (y - b.y) * (y - b.y));
|
||||
| + dot(b : Vector2) : float | -> dot product -> Ha a 2 vektor 90 fokosz szöget zár be, akkor 0.
|
||||
| | Pozitív, ha a 2 vektor által bezárt szög kisebb mint 90 fok, negatív, ha nagyobb.
|
||||
| | képlet: x * b.x + y * b.
|
||||
| + is_equal_approx(b : Vector2) : bool | -> nagyjából egyenlőek-e a vektorok. A max különbség legyen 0.00001 (Epszilon).
|
||||
| + length() : float |
|
||||
| + lenght_squared() : float | -> A hossz a gyökvonás nélkül. (A gyökvonás relatíve lassú, és ha csak össze kell
|
||||
| | hasonlítani hosszakat, akkor elég így)
|
||||
| + lerp(b : Vector2, t : float) : Vector2 | -> Linear interpolate -> a jelenlegi vektor és b közötti átmenetvektort adja vissza t paraméter felhasználásával.
|
||||
| | A t 0 és 1 közötti. Képlet: newx = x + (t * (b.x - x)); és newy = y + (t * (b.y - y));
|
||||
| + normalized() : Vector2 | -> A vektor normalizálva. Normalizált vektor = a hossza 1.
|
||||
| | float l = lenght_squared(); ha nem 0, gyököt kell vonni belőle, és le kell osztani x, y-t is vele
|
||||
| + normalize() | -> Maga a vektor normalizálódik.
|
||||
| + add(b: Vector2) | -> x += b.x, y += b.y
|
||||
| + sub(b: Vector2) | -> x -= b.x, y -= b.y
|
||||
| + operator+=(b: Vector2) | etc
|
||||
| + operator-=(b: Vector2) |
|
||||
| + operator+(a: Vector2, b: Vector2) : Vector2 |
|
||||
| + operator-(a: Vector2, b: Vector2) : Vector2 |
|
||||
| + operator==(b: Vector2) : bool |
|
||||
| + operator!=(b: Vector2) : bool |
|
||||
| + Vector2() |
|
||||
| + Vector2(b : Vector2) |
|
||||
| + Vector2(x : float, y : float) |
|
||||
*/
|
||||
|
||||
Vector2 Vector2::abs() {
|
||||
Vector2 b;
|
||||
|
||||
b.x = abs(x);
|
||||
b.y = abs(y);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
float Vector2::angle() {
|
||||
}
|
||||
|
||||
float Vector2::angle_to(const Vector2 &b) {
|
||||
}
|
||||
|
||||
float Vector2::cross() {
|
||||
}
|
||||
|
||||
Vector2 Vector2::clamped(float len) {
|
||||
}
|
||||
|
||||
Vector2 Vector2::direction_to(const Vector2 &b) {
|
||||
}
|
||||
|
||||
float Vector2::distance_to_squared(const Vector2 &b) {
|
||||
}
|
||||
|
||||
float Vector2::distance_to(const Vector2 &b) {
|
||||
}
|
||||
|
||||
float Vector2::dot(const Vector2 &b) {
|
||||
}
|
||||
|
||||
bool Vector2::is_equal_approx(const Vector2 &b) {
|
||||
}
|
||||
|
||||
float Vector2::length() {
|
||||
}
|
||||
|
||||
float Vector2::lenght_squared() {
|
||||
}
|
||||
|
||||
float Vector2::lerp(const Vector2 &b, const float t) {
|
||||
}
|
||||
|
||||
Vector2 Vector2::normalized() {
|
||||
}
|
||||
|
||||
void Vector2::normalize() {
|
||||
}
|
||||
|
||||
void Vector2::add(const Vector2 &b) {
|
||||
}
|
||||
|
||||
void Vector2::sub(const Vector2 &b) {
|
||||
}
|
||||
|
||||
Vector2::Vector2() {
|
||||
}
|
||||
|
||||
Vector2::Vector2(const Vector2 &b) {
|
||||
}
|
||||
|
||||
Vector2::Vector2(const float x, const float y) {
|
||||
}
|
||||
|
||||
Vector2 &Vector2::operator+=(const Vector2 &b) {
|
||||
}
|
||||
|
||||
Vector2 &Vector2::operator-=(const Vector2 &b) {
|
||||
}
|
||||
|
||||
Vector2 operator+(Vector2 lhs, const Vector2 &rhs) {
|
||||
}
|
||||
|
||||
Vector2 operator-(Vector2 lhs, const Vector2 &rhs) {
|
||||
}
|
||||
|
||||
bool operator==(const Vector2 &a, const Vector2 &b) {
|
||||
}
|
||||
|
||||
bool operator!=(const Vector2 &a, const Vector2 &b) {
|
||||
}
|
45
01_alapok/vector2.h
Normal file
45
01_alapok/vector2.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef VECTOR2_H
|
||||
#define VECTOR2_H
|
||||
|
||||
class Vector2 {
|
||||
public:
|
||||
Vector2 abs();
|
||||
float angle();
|
||||
float angle_to(const Vector2 &b);
|
||||
float cross();
|
||||
Vector2 clamped(float len);
|
||||
Vector2 direction_to(const Vector2 &b);
|
||||
float distance_to_squared(const Vector2 &b);
|
||||
float distance_to(const Vector2 &b);
|
||||
float dot(const Vector2 &b);
|
||||
bool is_equal_approx(const Vector2 &b);
|
||||
|
||||
float length();
|
||||
float lenght_squared();
|
||||
|
||||
float lerp(const Vector2 &b, const float t);
|
||||
|
||||
Vector2 normalized();
|
||||
void normalize();
|
||||
|
||||
void add(const Vector2 &b);
|
||||
void sub(const Vector2 &b);
|
||||
|
||||
Vector2();
|
||||
Vector2(const Vector2 &b);
|
||||
Vector2(const float x, const float y);
|
||||
|
||||
Vector2& operator+=(const Vector2& b);
|
||||
Vector2& operator-=(const Vector2& b);
|
||||
|
||||
friend Vector2 operator+(Vector2 lhs, const Vector2 &rhs);
|
||||
friend Vector2 operator-(Vector2 lhs, const Vector2 &rhs);
|
||||
|
||||
friend bool operator==(const Vector2& a, const Vector2& b);
|
||||
friend bool operator!=(const Vector2& a, const Vector2& b);
|
||||
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user