comments and new random

This commit is contained in:
Nikola Petrov 2025-08-27 17:56:25 +02:00
parent 53c333d46d
commit d41f11a333
2 changed files with 74 additions and 6 deletions

View File

@ -0,0 +1,68 @@
#include <raymath.h>
#include <cstdio>
int main(int argc, char const *argv[])
{
std::printf("\n\n\n");
Vector2 mousePosition = {.x = 15, .y = 10};
Vector2 mouseStart;
Vector2 orgPosition = {.x = 0, .y = 10};
float screenWidth = 30;
mouseStart = mousePosition;
std::printf("MouseStart x:%f, y:%f\n", mouseStart.x, mouseStart.y);
std::printf("orgPosition x:%f, y:%f\n", orgPosition.x, orgPosition.y);
// distance betwen corner of image and mouse startPoint
float len = Vector2Distance(mouseStart, orgPosition);
std::printf("len %f\n", len);
// angle in rad betwen mouse and image corner
float atan2x = orgPosition.x - mouseStart.x;
float atan2y = orgPosition.y - mouseStart.y;
std::printf("atan2 x:%f, y:%f\n", atan2x, atan2y);
float angleOfset = std::atan2( orgPosition.y - mouseStart.y, orgPosition.x - mouseStart.x);
std::printf("angleOffset %f\n", angleOfset);
mousePosition = {.x = 20, .y = 10};
// get distance that mouse has moved from original press location
// can be positive or negative if mouse start on right side and
// end on left it will be 0 - 100 so -100 dist
float dist = mousePosition.x - mouseStart.x;
printf("dist: %f\n", dist);
// this value can get from -1 to 1 based on if we swipe left or right
float l = dist / screenWidth;
printf("l: %f\n", l);
// first convert range of -1 to 1 to 0 to 1
// then change to degres from 45 to -45
float rotation = Lerp(45.0f, -45.0f, (l + 1) / 2);
printf("rotation: %f\n", rotation);
// convert to radians
float angle = ((rotation)*PI) / 180.0f;
printf("angle: %f\n", angle);
angle += angleOfset;
printf("angle + angleOfser: %f\n", angle);
// vector betwen image corrner and mouse
Vector2 newCornerVec = {.x = len * std::cos(angle), .y = len * std::sin(angle)};
printf("newCornerVec x: %f, y:%f \n", newCornerVec.x, newCornerVec.y);
// get global vector where to draw image
Vector2 newPosition;
newPosition.x = newCornerVec.x + mousePosition.x;
newPosition.y = newCornerVec.y + mousePosition.y;
printf("New position x: %f, y:%f \n", newPosition.x, newPosition.y);
printf("Draw image at this angle %f\n", rotation + 90);
return 0;
}

View File

@ -90,7 +90,7 @@ BlockedList blockedList;
void call(int sock, sockaddr_in newSocketInfo)
{
std::string add = TcpSocket::remoteAddress(newSocketInfo);
printf("new: %s\n", add.c_str());
//printf("new: %s\n", add.c_str());
int64_t conf, id;
Message message;
@ -99,7 +99,7 @@ void call(int sock, sockaddr_in newSocketInfo)
if (conf != StartHeader)
{
printf("StartHeader ERROR\n");
//printf("StartHeader ERROR\n");
TcpSocket::closet(sock);
//blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
return;
@ -107,7 +107,7 @@ void call(int sock, sockaddr_in newSocketInfo)
if (id == 0)
{
printf("ID ERROR\n");
//printf("ID ERROR\n");
TcpSocket::closet(sock);
//blockedList.addWarning(newSocketInfo.sin_addr.s_addr);
return;
@ -144,12 +144,12 @@ void call(int sock, sockaddr_in newSocketInfo)
sqlite3_stmt *insert_user_stmt;
sql::prepare_v2(db, insert_user_data, -1, &insert_user_stmt, NULL);
// limit how many gen they can send so some cant just come to here and start sendding random data.
while (ok)
{
message.mess = Mess::REQ_SEND_GEN;
message.data = gen;
printf("requesting gen %ld\n", gen);
//printf("requesting gen %ld\n", gen);
TcpSocket::sendt(sock, &message, sizeof(Message));
TcpSocket::recvt(sock, &message, sizeof(Message));
@ -187,7 +187,7 @@ void call(int sock, sockaddr_in newSocketInfo)
sql::finalize(insert_liked_stmt);
sql::close(db);
printf("del\n");
//printf("del\n");
TcpSocket::closet(sock);
}