Page 60 of 68

Re: Noob learns to code in 3 months

Posted: September 22nd, 2017, 11:06 am
by Chrajdal
I didn't remember to look in the chillipedia. Nevertheless, I found it there: http://wiki.planetchili.net/index.php?t ... l_6#Errata

I just thought you might be interested in :)

Re: Noob learns to code in 3 months

Posted: September 22nd, 2017, 11:28 am
by Yumtard
Yeah for sure. Never considered it since "why would anyone do that?"

Added this

if (pPixels != rhs.pPixels)

Re: Noob learns to code in 3 months

Posted: September 22nd, 2017, 11:46 am
by Chrajdal
Yumtard wrote:Yeah for sure. Never considered it since "why would anyone do that?"

Added this

if (pPixels != rhs.pPixels)
I wouldn't suggest doing that. Suppose, you have several different dynamic arrays in your class. In your assignment operator you would have to check all the pointers eg.:

Code: Select all

if( arr1 != rhs.arr1 && arr2 != rhs.arr2 && arr3 != rhs.arr3 ... )
you get the idea

Simple

Code: Select all

 if(this != &rhs) 
should suffice, I think :)

Re: Noob learns to code in 3 months

Posted: September 22nd, 2017, 12:52 pm
by chili
Yeah, either would work, but better to check pointer to whole object than pointer to content I think. More idiomatic.

Re: Noob learns to code in 3 months

Posted: September 22nd, 2017, 12:58 pm
by Yumtard
solid point

Re: Noob learns to code in 3 months

Posted: September 28th, 2017, 4:23 pm
by Yumtard
Got a good grade on the pokemon simulator. Teacher had a bunch of feedback on things I could've done better tho.

For math assignment we got a framework with a bunch of declared functions we had to implement.

In the vector class we had
Distance()
Add()
Subtract()
DotProduct()
CrossProduct()

Matrix class:
Multiply()
RotateAroundX()
RotateAroundY()
RotateAroundZ()
RotateArouncXYZ()

and finally in the plane class:
bool IntersectsWithLine()

I finished these with a bunch of time to spare so I've added
in vector:
length()
lengthsq()
Normalize()

in Plane:
IntersectionPoint()

in Matrix
Identity()
bool Orthogonal()
bool Orthonormal()
bool Involutory()
Inverse()
Transpose()
Determinant()
Scale()

Overloaded a bunch of operators too to make life easier and make it possible to multiply a matrix with a vector.

Might be forgetting some functions. Not sure what else to add. Wanna be able to do translation but for that I need a 4x4 matrix. The matrix class we got to work with is a 3x3 matrix which has 3 vectors representing its rows.

Re: Noob learns to code in 3 months

Posted: September 28th, 2017, 7:25 pm
by albinopapa
Only need a 4x4 if you are doing 3D transformations, which I guess you are. A 3x2 matrix is all that is needed for 2D transformations, so you could still use it especially with your orthogonal view matrix.

Re: Noob learns to code in 3 months

Posted: September 29th, 2017, 7:47 pm
by Yumtard
Yeah we're doing 3D

I guess I could add a vector maybe..
Anyways I'm working on something else now. Trying to make a function that returns the line where 2 planes intersect. I know how to do it mathematically but having some trouble translating it into code.

Atm I'm always setting x to 0. This makes the function work, but not for all cases.. Will try to figure something out.

Found this on stackoverflow.


Image

he adds these 2 equations and get this result:

Image

could someone help me understand how he manages to get z by itself on the left hand side?
When I try adding these I get stuck with the left side being
(-B2/B1)*C1z + C2z
And I can't figure out a way to get this thing down to just z

Re: Noob learns to code in 3 months

Posted: September 29th, 2017, 8:49 pm
by Yumtard
nvm his answer was incorrect

Re: Noob learns to code in 3 months

Posted: September 29th, 2017, 10:49 pm
by Yumtard
Image

yay. Think I should be able to fix my function now