MathUtils.cpp
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
//  MathUtils.cpp
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 10.05.2017.
//
//
#include <stdio.h>
#include "MathUtils.h"
#include <random>
// random generator
double MathUtils::getRandom(double min, double max){
    auto rng = _getRNG();
    std::uniform_real_distribution<> dist(min, max);
    return dist(rng);
}
int MathUtils::getRandomInt(int min, int max){
    auto rng = _getRNG();
    std::uniform_int_distribution<std::mt19937::result_type> dist6(min,max);
    return dist6(rng);
}
cocos2d::Color4F MathUtils::getRandomOpaqueColor(){
    auto r = MathUtils::getRandom(0, 1);
    auto g = MathUtils::getRandom(0, 1);
    auto b = MathUtils::getRandom(0, 1);
    return cocos2d::Color4F(r,g,b,1);
}
//void MathUtils::drawRoundedCorneredRect(cocos2d::DrawNode* drawNode, cocos2d::Rect rect, float cornerRadius, cocos2d::Color4F& color){
//
//    drawNode->drawLine(cocos2d::Vec2(rect.getMinX()+cornerRadius, rect.getMinY()), cocos2d::Vec2(rect.getMaxX()-cornerRadius, rect.getMinY()), color);
//    drawNode->drawLine(cocos2d::Vec2(rect.getMaxX(), rect.getMinY()+cornerRadius), cocos2d::Vec2(rect.getMaxX(), rect.getMaxY()-cornerRadius), color);
//    drawNode->drawLine(cocos2d::Vec2(rect.getMaxX()-cornerRadius, rect.getMaxY()), cocos2d::Vec2(rect.getMinX()+cornerRadius, rect.getMaxY()), color);
//    drawNode->drawLine(cocos2d::Vec2(rect.getMinX(), rect.getMaxY()-cornerRadius), cocos2d::Vec2(rect.getMinX(), rect.getMinY()+cornerRadius), color);
//
//    static float MagicConst = 0.552f;
//
//    drawNode->setLineWidth(1);
//
//    auto corner = cocos2d::Vec2(rect.getMinX(), rect.getMinY()); //bottom left
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x, corner.y + cornerRadius), cocos2d::Vec2(corner.x, corner.y + cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x + cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x + cornerRadius, corner.y), 100, color);
//    corner = cocos2d::Vec2(rect.getMinX(), rect.getMaxY());
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x, corner.y - cornerRadius), cocos2d::Vec2(corner.x, corner.y - cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x + cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x + cornerRadius, corner.y), 80, color);
//    corner = cocos2d::Vec2(rect.getMaxX(), rect.getMaxY());
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x - cornerRadius, corner.y), cocos2d::Vec2(corner.x - cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x, corner.y - cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x, corner.y - cornerRadius), 50, color);
//    corner = cocos2d::Vec2(rect.getMaxX(), rect.getMinY());
//    drawNode->drawCubicBezier(cocos2d::Vec2(corner.x, corner.y + cornerRadius), cocos2d::Vec2(corner.x, corner.y + cornerRadius*(1-MagicConst)), cocos2d::Vec2(corner.x - cornerRadius*(1-MagicConst), corner.y), cocos2d::Vec2(corner.x - cornerRadius, corner.y), 30, color);
//
//}
///////////////////////////////////////
// private
std::mt19937 MathUtils::_getRNG(){
    std::mt19937 rng;
    rng.seed(std::random_device()());
    return rng;
}