//---------------------------------------------------------------------------
#include <vcl.h>
#include <cmath>
#pragma hdrstop
#include "rgr.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
using namespace std;
int x1=270, x2 = 270, x3=220, x4=220;
int y1=250, y2 = 200, y3=200, y4=250;
double alfa=0.5;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Canvas->Pen->Width=1;
Canvas->Pen->Color=clBlack;
Canvas->Brush->Color=clBlack;
TPoint p[4];
p[0] = Point(x1,y1);
p[1] = Point(x2,y2);
p[2] = Point(x3,y3);
p[3] = Point(x4,y4);
Canvas->Polygon(p,3);
Timer1->Interval = 100;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
x1=x1*Cos(alfa)-y1*Sin(alfa); x2=x2*Cos(alfa)-y2*Sin(alfa); x3=x3*Cos(alfa)-y3*Sin(alfa); x4=x4*Cos(alfa)-y4*Sin(alfa);
y1=y1*Cos(alfa)+x1*Sin(alfa); y2=y2*Cos(alfa)+x2*Sin(alfa); y3=y3*Cos(alfa)+x3*Sin(alfa); y4=y4*Cos(alfa)+x4*Sin(alfa);
TPoint p[4];
p[0] = Point(x1,y1);
p[1] = Point(x2,y2);
p[2] = Point(x3,y3);
p[3] = Point(x4,y4);
Canvas->Polygon(p,3);
}
//---------------------------------------------------------------------------
Не подключается cmath
Код:
Ошибки:
Call to undefined function 'Cos'
Call to undefined function 'Sin'
Вроде бы и cmath подключал, и math.h - бесполезно. Помогите найти решение проблемы
math.h
Функции с мальнькой буквы
Функции с мальнькой буквы
Спасибо, функции действительно длжны были быть с маленькой
Код:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <cmath>
#pragma hdrstop
#include "rgr.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
using namespace std;
int x1=270, x2=220;
int y1=250, y2=200;
int a=2,b=2;
double t=10;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Canvas->Pen->Width=1;
Canvas->Pen->Color=clBlack;
Canvas->Brush->Color=clBlack;
Canvas->Rectangle(x1,y1,x1,y1);
Timer1->Interval = t;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Canvas->Pen->Color = Form1->Color;
Canvas->Brush->Color = Form1->Color;
Canvas->Rectangle(x1,y1,x2,y2);
Canvas->Pen->Color=clBlack;
Canvas->Brush->Color=clBlack;
x1+=a; x2+=a; y1+=b; y2+=b;
Canvas->Rectangle(x1,y1,x2,y2);
if (((x1 == ClientWidth) || (x2 == ClientWidth)) && ((y1>ClientHeight/2) || (y2>ClientHeight/2))) {a=-2; b=1.5;};
if (((x1 == ClientWidth) || (x2 == ClientWidth)) && ((y1>ClientHeight/2) || (y2>ClientHeight/2))) {a=-2; b=-1;};
if (((y1 == ClientHeight) || (y2 == ClientHeight)) && ((x1>ClientWidth/2) || (x2>ClientWidth/2))) {a=2; b=-1.8;};
if (((y1 == ClientHeight) || (y2 == ClientHeight)) && ((x1<ClientWidth/2) || (x2<ClientWidth/2))) {a=-1.6; b=-2.1;};
if (((x1 == 0) || (x2 == 0)) && ((y1>ClientHeight/2) || (y2>ClientHeight/2))) {a=2; b=2;};
if (((x1 == 0) || (x2 == 0)) && ((y1<ClientHeight/2) || (y2<ClientHeight/2))) {a=2; b=-2;};
if (((y1 == 0) || (y2 == 0)) && ((x1<ClientWidth/2) || (x2<ClientWidth/2))) {a=-1.7; b=2;};
if (((y1 == 0) || (y2 == 0)) && ((x1>ClientWidth/2) || (x2>ClientWidth/2))) {a=1.7; b=2;};
}
//---------------------------------------------------------------------------
#include <vcl.h>
#include <cmath>
#pragma hdrstop
#include "rgr.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
using namespace std;
int x1=270, x2=220;
int y1=250, y2=200;
int a=2,b=2;
double t=10;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Canvas->Pen->Width=1;
Canvas->Pen->Color=clBlack;
Canvas->Brush->Color=clBlack;
Canvas->Rectangle(x1,y1,x1,y1);
Timer1->Interval = t;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Canvas->Pen->Color = Form1->Color;
Canvas->Brush->Color = Form1->Color;
Canvas->Rectangle(x1,y1,x2,y2);
Canvas->Pen->Color=clBlack;
Canvas->Brush->Color=clBlack;
x1+=a; x2+=a; y1+=b; y2+=b;
Canvas->Rectangle(x1,y1,x2,y2);
if (((x1 == ClientWidth) || (x2 == ClientWidth)) && ((y1>ClientHeight/2) || (y2>ClientHeight/2))) {a=-2; b=1.5;};
if (((x1 == ClientWidth) || (x2 == ClientWidth)) && ((y1>ClientHeight/2) || (y2>ClientHeight/2))) {a=-2; b=-1;};
if (((y1 == ClientHeight) || (y2 == ClientHeight)) && ((x1>ClientWidth/2) || (x2>ClientWidth/2))) {a=2; b=-1.8;};
if (((y1 == ClientHeight) || (y2 == ClientHeight)) && ((x1<ClientWidth/2) || (x2<ClientWidth/2))) {a=-1.6; b=-2.1;};
if (((x1 == 0) || (x2 == 0)) && ((y1>ClientHeight/2) || (y2>ClientHeight/2))) {a=2; b=2;};
if (((x1 == 0) || (x2 == 0)) && ((y1<ClientHeight/2) || (y2<ClientHeight/2))) {a=2; b=-2;};
if (((y1 == 0) || (y2 == 0)) && ((x1<ClientWidth/2) || (x2<ClientWidth/2))) {a=-1.7; b=2;};
if (((y1 == 0) || (y2 == 0)) && ((x1>ClientWidth/2) || (x2>ClientWidth/2))) {a=1.7; b=2;};
}
//---------------------------------------------------------------------------
Вообщем надо чтобы квадратик отталкивался от стен, но удара о верхнюю не происходит, и он тупо вылетает
других ошибок с лету не видно.
Выяснил, что проблема в этой строке:
Код:
if (((y1 == ClientHeight) || (y2 == ClientHeight)) && ((x1>ClientWidth/2) || (x2>ClientWidth/2))) {a=2; b=-1.8;};
Говорюж == ClientHeight такого быть не должно, делай >= ClientHeight и где == 0 делай <=0
b=-1.8 WTF? oO у тебяж все int'ами объявлено
int x1=270, x2=220;
int y1=250, y2=200;
int a=2,b=2;
делай их double или float хотяб