sally1980
asked on
what wrong with my program...
I got a question is I not confirm my code. I use object – oriental and OpenGL concept to draw a triangle. I got a Position class which store 3 float variable (x, y, z). Then I use the Triangle class which contain of array of 3 Position which contain the coordinate of the 3 vertices of Triangle. I use Driver.cpp to test my program (main class to control everything). Following is my code to test the program:
//Driver.cpp
#include <windows.h>
#include "Globals.h"
#include "OpenGLScene.h"
#include "MyOpenGLScene.h"
int WINAPI WinMain(HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
// Position accept 3 variable(x, y, z)
Position* p1 = new Position(0.0f, 1.0f, -6.0f);
// Position accept 3 variable(x, y, z)
Position* p2 = new Position(-1.0f, -1.0f, -6.0f);
// Position accept 3 variable(x, y, z)
Position* p3 = new Position(1.0f, -1.0f, -6.0f);
// because 3 Position for draw a Triangle
Position* p[] = {p1, p2, p3};
// Trianlge to store array of Position
Triangle* myTriangle = new Triangle(*p);
// add Triangle
myStage->addTriangle(myTri angle);
//run the code
OpenGLScene* myStage = new MyOpenGLScene("Stage 1",800,600,16,0);
myStage->start();
return 0;
}
when I test addTriangle function then got this kind of error:
error C2440: '=' : cannot convert from 'class Position *(__thiscall Triangle::*)(void)' to 'class Position *' There is no context in which this conversion is possible
error C2440: '=' : cannot convert from 'float (__thiscall Position::*)(void)' to 'float'
There is no context in which this conversion is possible
error C2440: '=' : cannot convert from 'float (__thiscall Position::*)(void)' to 'float'
There is no context in which this conversion is possible
error C2440: '=' : cannot convert from 'float (__thiscall Position::*)(void)' to 'float'
There is no context in which this conversion is possible
I think my code are stupid and then I don’t know how to make it simple and fix the error. Can someone check for me. Thanks!
Following is my other code:
// Triangle.cpp file
#include "MyOpenGLScene.h"
int i=0;
Triangle *triangle[50];
MyOpenGLScene::MyOpenGLSce ne(char* title, int width, int height, int bits, bool fullscreenflag):OpenGLScen e(title, width, height, bits, fullscreenflag) { }
void MyOpenGLScene::addTriangle (Triangle *T) {
triangle[i] = aTriangle[1];
i++;
}
void MyOpenGLScene::DrawTriangl e(Triangle *T) {
Position *vertex;
float vx, vy, vz;
glBegin(GL_TRIANGLES);
for(int i=0; i<3; i++) {
vertex = T->getVertices;
vx = vertex->getX;
vy = vertex->getY;
vz = vertex->getZ;
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(vx, vy, vz);
}
glEnd();
}
int MyOpenGLScene::DrawGLScene () {
this->DrawTriangle(T);
return 0;
}
// Triangle.cpp file
#include "Triangle.h"
Triangle::Triangle(Positio n position[3]):red(1.0), green(1.0), blue(1.0) {
this->position[0] = position[0];
this->position[1] = position[1];
this->position[2] = position[2];
}
void Triangle::setColor(float red, float green, float blue) {
this->red = red;
this->green = green;
this->blue = blue;
}
float Triangle::getRed() {
return red;
}
float Triangle::getGreen() {
return green;
}
float Triangle::getBlue() {
return blue;
}
Position* Triangle::getVertices() {
return position;
}
// Position.cpp file
Position::Position() { }
Position::Position(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}
float Position::getX() {
return x;
}
float Position::getY() {
return y;
}
float Position::getZ() {
return z;
}
From: Sally
//Driver.cpp
#include <windows.h>
#include "Globals.h"
#include "OpenGLScene.h"
#include "MyOpenGLScene.h"
int WINAPI WinMain(HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
// Position accept 3 variable(x, y, z)
Position* p1 = new Position(0.0f, 1.0f, -6.0f);
// Position accept 3 variable(x, y, z)
Position* p2 = new Position(-1.0f, -1.0f, -6.0f);
// Position accept 3 variable(x, y, z)
Position* p3 = new Position(1.0f, -1.0f, -6.0f);
// because 3 Position for draw a Triangle
Position* p[] = {p1, p2, p3};
// Trianlge to store array of Position
Triangle* myTriangle = new Triangle(*p);
// add Triangle
myStage->addTriangle(myTri
//run the code
OpenGLScene* myStage = new MyOpenGLScene("Stage 1",800,600,16,0);
myStage->start();
return 0;
}
when I test addTriangle function then got this kind of error:
error C2440: '=' : cannot convert from 'class Position *(__thiscall Triangle::*)(void)' to 'class Position *' There is no context in which this conversion is possible
error C2440: '=' : cannot convert from 'float (__thiscall Position::*)(void)' to 'float'
There is no context in which this conversion is possible
error C2440: '=' : cannot convert from 'float (__thiscall Position::*)(void)' to 'float'
There is no context in which this conversion is possible
error C2440: '=' : cannot convert from 'float (__thiscall Position::*)(void)' to 'float'
There is no context in which this conversion is possible
I think my code are stupid and then I don’t know how to make it simple and fix the error. Can someone check for me. Thanks!
Following is my other code:
// Triangle.cpp file
#include "MyOpenGLScene.h"
int i=0;
Triangle *triangle[50];
MyOpenGLScene::MyOpenGLSce
void MyOpenGLScene::addTriangle
triangle[i] = aTriangle[1];
i++;
}
void MyOpenGLScene::DrawTriangl
Position *vertex;
float vx, vy, vz;
glBegin(GL_TRIANGLES);
for(int i=0; i<3; i++) {
vertex = T->getVertices;
vx = vertex->getX;
vy = vertex->getY;
vz = vertex->getZ;
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(vx, vy, vz);
}
glEnd();
}
int MyOpenGLScene::DrawGLScene
this->DrawTriangle(T);
return 0;
}
// Triangle.cpp file
#include "Triangle.h"
Triangle::Triangle(Positio
this->position[0] = position[0];
this->position[1] = position[1];
this->position[2] = position[2];
}
void Triangle::setColor(float red, float green, float blue) {
this->red = red;
this->green = green;
this->blue = blue;
}
float Triangle::getRed() {
return red;
}
float Triangle::getGreen() {
return green;
}
float Triangle::getBlue() {
return blue;
}
Position* Triangle::getVertices() {
return position;
}
// Position.cpp file
Position::Position() { }
Position::Position(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}
float Position::getX() {
return x;
}
float Position::getY() {
return y;
}
float Position::getZ() {
return z;
}
From: Sally
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: _ys_ {http:#9679161}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: _ys_ {http:#9679161}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
To get an instance of Position use
Position p1(1,1,-6);
Now p needs to be declared as
Position p[3] and then you can continue with the tip of _ys_.