Ok Same project new problem.
My assignment has me using a bunch of pre-written code and I just need to fill in the blanks. Now after following the instructions thus far I'm running into an accessibility error.
Here's the instructions I am provided:
There is a green dot that translates across the screen. Study Point3D.cpp.
#include <math.h>
#include "Point3D.h"
#include "GraphicsLib.h"
Point3D::Point3D( void ) //defining the default constructor from the Point3D class in //Points3D.h. Note the scope resolution operator :: is used to refer to the class Point3D
{
x = y = z = 0.0f ;
}
Point3D::Point3D( float x, float y, float z ) //defining the constructor w/ 3 parameters
{
this->x = x ; //using the this pointer to access the member data x
this->y = y ;
this->z = z ;
}
Point3D::~Point3D(void) //destructor
{
}
double Point3D::Distance(const Point3D & other ) const //defining the Distance function
{
double result = 0.0 ;
double delta[3] ;
delta[0] = x - other.x ;
delta[1] = y - other.y ;
delta[2] = z - other.z ;
result = sqrt( delta[0]*delta[0] + delta[1]*delta[1] + delta[2]*delta[2] ) ;
return result ;
}
void Point3D::Render( const Appearance* appearance ) const //defining Render function
{
byte r, g, b ;
appearance->Get_RGB( r, g, b ) ;
DrawingSurface::Draw_Point( ROUND( x ), ROUND( y ), r, g, b ) ; // round
//coordinates to nearest integer
}
void Point3D::Translate(double Tx, double Ty, double Tz) //defining translate function
{
x += float( Tx ) ;
y += float( Ty ) ;
z += float( Tz ) ;
}
Then I'm given this code for a sphere:
Sphere::Sphere(void)
{
radius = 0.0f ;
}
Sphere::~Sphere(void)
{
}
Add this definition of the constructor with two parameters, consisting of center and radius:
Sphere:: Sphere( Point3D& center, float radius )
{
Fill-in the appropriate two lines of code that go here. For an idea, see the structure of the similar constructor in Point3D.cpp, the one having 3 parameters.
}
Then translate the center:
void Sphere:: Translate( double Tx, double Ty, double Tz )
{
Write the appropriate one line of code to translate the center (Tx,Ty,Tz) using the Translate method.
}
Finally, render the sphere:
void Sphere::Render( const Appearance* appearance ) const
{
See Point3D.cpp for the two lines of code that you will need here.
Then use the Draw_Circle method:
DrawingSurface::Draw_Circle( int( center.x+0.5f ),write the appropriate code here,
int( radius+0.5f ), appearance->solid, r, g, b ) ;
}
The sphere should now render and translate.
I've gotten down to adding code to the Draw_Circle method and when I try to enter the parameters VS is telling me that x and y are attributes of Point3D.center and are inaccessible as they are private data members. Is ther something I'm doing wrong or is this code bogus?
I know I need to move the center, but in Point3D.cpp the x,y, and z coordinates are applied to the x,y, and z position of the green dot by coding x+=Tx etc. How to I apply Sphere::Translate(double, double, double) to the center of the sphere?
There are 3 coordinates and only 1 center.
There is only ONE center and THREE coordinates. How do I apply those coordinates to the center? Point3D::Translate applies 3 changes to 3 attributes. There is only one center
I know how to call member functions I mistyped the code. Look, I don't learn very well when it comes to reading the information. I need to see it done first then I reverse engineer the solution until I understand it. Basically what I need is the solution ONE time and an explanation for each step. Then I can apply to similar problems from then on.
Ok I see now that center is actually a Point3D object. Did not make that connection since most of the code was provided for me and I am only adding the lines of code required by the assignment. I'm still confused on how I'm supposed to apply the Point3D::Translate to Sphere::Translate. I am a true novice taking 8 week cramfest courses and then just slowly relearning everything I crammed to pass my lasses to little programming projects of my own. I need a lot of help and detailed explanation as I am in way over my head. It doesn't make my student debt any less real or my need for this knowledge any less necessary. Glad I could make you laugh. Now how about some more help ;)
Ok Same project new problem.
My assignment has me using a bunch of pre-written code and I just need to fill in the blanks. Now after following the instructions thus far I'm running into an accessibility error.
Here's the instructions I am provided:
There is a green dot that translates across the screen. Study Point3D.cpp.
#include <math.h>
#include "Point3D.h"
#include "GraphicsLib.h"
Point3D::Point3D( void ) //defining the default constructor from the Point3D class in //Points3D.h. Note the scope resolution operator :: is used to refer to the class Point3D
{
x = y = z = 0.0f ;
}
Point3D::Point3D( float x, float y, float z ) //defining the constructor w/ 3 parameters
{
this->x = x ; //using the this pointer to access the member data x
this->y = y ;
this->z = z ;
}
Point3D::~Point3D(void) //destructor
{
}
double Point3D::Distance(const Point3D & other ) const //defining the Distance function
{
double result = 0.0 ;
double delta[3] ;
delta[0] = x - other.x ;
delta[1] = y - other.y ;
delta[2] = z - other.z ;
result = sqrt( delta[0]*delta[0] + delta[1]*delta[1] + delta[2]*delta[2] ) ;
return result ;
}
void Point3D::Render( const Appearance* appearance ) const //defining Render function
{
byte r, g, b ;
appearance->Get_RGB( r, g, b ) ;
DrawingSurface::Draw_Point( ROUND( x ), ROUND( y ), r, g, b ) ; // round
//coordinates to nearest integer
}
void Point3D::Translate(double Tx, double Ty, double Tz) //defining translate function
{
x += float( Tx ) ;
y += float( Ty ) ;
z += float( Tz ) ;
}
Then I'm given this code for a sphere:
Sphere::Sphere(void)
{
radius = 0.0f ;
}
Sphere::~Sphere(void)
{
}
Add this definition of the constructor with two parameters, consisting of center and radius:
Sphere:: Sphere( Point3D& center, float radius )
{
Fill-in the appropriate two lines of code that go here. For an idea, see the structure of the similar constructor in Point3D.cpp, the one having 3 parameters.
}
Then translate the center:
void Sphere:: Translate( double Tx, double Ty, double Tz )
{
Write the appropriate one line of code to translate the center (Tx,Ty,Tz) using the Translate method.
}
Finally, render the sphere:
void Sphere::Render( const Appearance* appearance ) const
{
See Point3D.cpp for the two lines of code that you will need here.
Then use the Draw_Circle method:
DrawingSurface::Draw_Circle( int( center.x+0.5f ),write the appropriate code here,
int( radius+0.5f ), appearance->solid, r, g, b ) ;
}
The sphere should now render and translate.
I've gotten down to adding code to the Draw_Circle method and when I try to enter the parameters VS is telling me that x and y are attributes of Point3D.center and are inaccessible as they are private data members. Is ther something I'm doing wrong or is this code bogus? I added the same post to the bottom here since I'm reviving an old post involving the same assignment, but with a new issue.
For future posts, please put your code in code tags as it makes it much easier to read and retains whitespace:
[code]
Put your code between these
[/code]
Anyway... as for your problem... is there a GetX() or any kind of similar function in Point3D? Maybe you're supposed to use that instead of accessing the x member directly.