Advertisement

I guess this is about typcasting, but maybe not

Started by March 07, 2001 05:06 PM
4 comments, last by CHollman82 23 years, 10 months ago
Check out this code, Ill explain it below. ----------------------------------------------------------------- 13hgraphics.h ----------------------------------------------------------------- void putpixel(int x,int y,char color) { int offs; offs=320*y + x; asm { mov ax,0a000h mov es,ax mov di,offs mov al,color mov [es:di],al } } void put3dpixel(float cx, float cy, float cz, float pitch, float roll, float yaw, float radius, char color) { float newx,newy,newz; newx=cx+(cos(roll)*radius); newy=cy+(sin(roll)*radius); //cx=newx; //cy=newy; //newx=cx+(cos(yaw)*radius); //newz=cz+(sin(yaw)*radius); //cx=newx; //cz=newz; //newy=cy+(sin(roll)*radius); //newz=cz+(sin(yaw)*radius); cx=newx; cy=newy; cz=newz; newx=(320*cx)/(cz+160); newy=(320*cy)/(cz+100); putpixel((int)newx,(int)newy,color); } ----------------------------------------------------------------- 3d.h ----------------------------------------------------------------- class point3d { private: float cx,cy,cz; float radius; float pitch,roll,yaw; char color; public: point3d(float cx, float cy, float cz, float pitch, float roll, float yaw, float radius, char color){} void putpoint() { put3dpixel(cx,cy,cz,pitch,roll,yaw,radius,color); } }; ----------------------------------------------------------------- Main ----------------------------------------------------------------- #include <13hgraphics.h> #include <3d.h> int main() { setmode(0x0013); point3d point(1,1,1,0,0,0,4,1); point.putpoint(); } ----------------------------------------------------------------- Okay, basically my problem is passing newx and newy to putpixel from put3dpixel, In put3dpixel they are floats (which is necessary because pitch, roll, and yaw have to be) but putpixel takes ints. I tried typecasting, as you can see, but it didn''t work. It compiles fine, but when it runs I get a stack fault, which Im positive is being caused by the call to putpixel (I isolated it and checked it). So, either Im not typecasting correctly, or thats not the problem. Can somebody please help. P.S. If anybody has any suggestions about the above code, even if they don''t solve my problem, they would be appreciated. Thanks
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
this in C or C++?

It sounds like C. You can''t just cast a basic type from one to the other (well you can, but it doesn''t do what you want ), you have to convert it, with a round function or something (at least I think you do, it''s been many years since I programmed in C, and my memory''s starting to fade...)

oh, you may need to push/pop es & di before/after you use them in the putpixel routine (it''s fairly safe to blow away ah/al, but not es:di).

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Its in C++ (Borland). The putpixel works fine (Probably because I didn''t write it )
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
Okay, this is not typecasting. Check this out
-----------------------------------------------------------------
#include iostream.h

class test
{
private:
float cx;
public:
test(float cx){};
outstats(){cout << "cx: "<};

void main()
{
test one(1.1);
one.outstats();
}
-----------------------------------------------------------------
A very simplified class I used to test my constructor. It doesn't work. When I run this it tells me that cx = 9.47112e-39, but its obviously supposed to be 1.1. What am I doing wrong?
*note - iostream is not in >< because the board thinks its an HTML tag

Edited by - CHollman82 on March 9, 2001 3:52:47 PM
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
Aren''t you supposed to assign the value to cx in your constructor? Your constructor is just empty.

Harry.
Harry.
Its not printing out the value you expect because you do nothing in your contrusctor. You need to assign cx (in the class, not that member functon you have) to the value the constructor gets. So in the constructor it should look like this:

class test
{
private:
float cx;

public:
test(float value)
{
cx = value;
}

void outstats()
{
cout << "cx: "<< cx << endl;
}

};

void main()
{
test one(1.1);
one.outstats();
}





Edited by - SirKnight on March 10, 2001 6:41:15 PM

Edited by - SirKnight on March 10, 2001 9:37:16 PM

This topic is closed to new replies.

Advertisement