Witam
Narysowałem w visual c++ sześcian i teraz chciałbym pokolorować jego ściany, te które są widoczne.
Tylko nie wiem jak to zrobić. Jak malować w wyznaczonym obszarze, na danej ścianie sześcianu.
Rysuje sześcian w pictureBox, jest jakaś funkcja setpixel ale nie wiem kompletnie jak ją narysować.
Jeśli mam wrzucić cały plik projektu proszę pisać.
Poniżej kod
#pragma once
#include <math.h>
#include <cmath>
namespace kwadrat {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private: System::Windows::Forms::PictureBox^ pictureBox1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(13, 13);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"Rysuj";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::Color::White;
this->pictureBox1->Location = System::Drawing::Point(94, 13);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(676, 537);
this->pictureBox1->TabIndex = 1;
this->pictureBox1->TabStop = false;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(782, 553);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Pen^ pioro = gcnew Pen(System::Drawing::Color::Red);
Graphics^ grafika=pictureBox1->CreateGraphics();
pictureBox1->Refresh();
int a1, a2, b1, b2, c1, c2;
a1=128;
a2=468;
b1=96;
b2=288;
c1=384;
c2=192;
float X [9];
float Y [9];
float f;
f=1;
float teta;
//teta=M_PI/6;
teta=3.14/6;
X[1]=a1+c1*f*cos(teta);
Y[1]=b1+c1*f*sin(teta);
X[2]=a2+c1*f*cos(teta);
Y[2]=b1+c1*f*sin(teta);
X[3]=a2+c1*f*cos(teta);
Y[3]=b2+c1*f*sin(teta);
X[4]=a1+c1*f*cos(teta);
Y[4]=b2+c1*f*sin(teta);
X[5]=a1+c2*f*cos(teta);
Y[5]=b1+c2*f*sin(teta);
X[6]=a2+c2*f*cos(teta);
Y[6]=b1+c2*f*sin(teta);
X[7]=a2+c2*f*cos(teta);
Y[7]=b2+c2*f*sin(teta);
X[8]=a1+c2*f*cos(teta);
Y[8]=b2+c2*f*sin(teta);
int i;
for ( i=1; i<=8; i++)
{
X[i]=X[i]-2*a1;
Y[i]=Y[i]-2*b1;
}
grafika->DrawLine(pioro,X[1],Y[1],X[2],Y[2]);
grafika->DrawLine(pioro,X[2],Y[2],X[3],Y[3]);
grafika->DrawLine(pioro,X[3],Y[3],X[4],Y[4]);
grafika->DrawLine(pioro,X[4],Y[4],X[1],Y[1]);
grafika->DrawLine(pioro,X[6],Y[6],X[7],Y[7]);
grafika->DrawLine(pioro,X[7],Y[7],X[8],Y[8]);
grafika->DrawLine(pioro,X[8],Y[8],X[5],Y[5]);
grafika->DrawLine(pioro,X[5],Y[5],X[6],Y[6]);
grafika->DrawLine(pioro,X[1],Y[1],X[5],Y[5]);
grafika->DrawLine(pioro,X[2],Y[2],X[6],Y[6]);
grafika->DrawLine(pioro,X[4],Y[4],X[8],Y[8]);
grafika->DrawLine(pioro,X[3],Y[3],X[7],Y[7]);
}
};
}