Cambalinho
Power Member
estou a tentar usar Multitarefa no C++, mas estou a ter dificuldades. como se usa?
todo este código está dentro de 1 classe.
ao usar esta ultima linha, eu obtenho 1 erro:
"cannot convert 'void* (image::*)(void*)' to 'void* (*)(void*)'"
estou a tentar fazer esta alteração por este tutorial: https://www.tutorialspoint.com/cplusplus/cpp_multithreading.htm
todo este código está dentro de 1 classe.
Código:
#include <pthread.h>
struct Pixel
{
float X = 0;
float Y = 0;
float Z = 0;
BYTE R = 0;
BYTE G = 0;
BYTE B = 0;
};
void *DrawPixel(void *threadarg)
{
struct Pixel *Pix;
Pix = (struct Pixel *) threadarg;
//For every steps we calculate the perspective:
//Avoiding division by zero:
float EyeDistance = 500;// doing these i avoid the black\empty vertical lines
const float d = EyeDistance+Pix->Z; // Note that Z==0 is irrelevant here
const float Perspective = (d != 0) ? (EyeDistance/d) : 0;
//The 3D to 2D convertion(i use 300 of eye distance, but we can change it):
int PosX = Pix->X*Perspective;
int PosY = Pix->Y*Perspective;
//Draw the pixel on valid positions:
if(Pix->Z>=0 && PosX<Width && PosX>=0 && PosY<Height && PosY>=0)
{
size_t pixelOffset = PosY * scanlineSize + PosX * pixelSize;
int PosR = pixelOffset+2;
int PosG = pixelOffset+1;
int PosB = pixelOffset+0;
Pixels[PosR]=Pix->R;
Pixels[PosG]=Pix->G;
Pixels[PosB]=Pix->B;
}
pthread_exit(NULL);
}
//use it inside the class:
//Getting RGB from the color:
int R = GetRValue(LineColor);
int G = GetGValue(LineColor);
int B = GetBValue(LineColor);
pthread_t Draw;
Pixel PixeImage;
PixeImage.X = X;
PixeImage.Y = Y;
PixeImage.Z = Z;
PixeImage.R = R;
PixeImage.G = G;
PixeImage.B = B;
int i=0;
do
{
PixeImage.X = X;
PixeImage.Y = Y;
PixeImage.Z = Z;
pthread_create(&Draw, NULL, &DrawPixel,(void*) &PixeImage);
//................
"cannot convert 'void* (image::*)(void*)' to 'void* (*)(void*)'"
estou a tentar fazer esta alteração por este tutorial: https://www.tutorialspoint.com/cplusplus/cpp_multithreading.htm