In the opening scenario of “The Glass Castle,” Jeannette Walls, a well-heeled writer at New York magazine, has just finished an elegant dinner with her fiance. Riding home in a cab, she spots a disheveled woman digging through a Dumpster and, like many of us would, Walls averts her eyes, then she also slides down in her seat nearly to the floor. The homeless woman, it turns out, is her mother.

Based on Walls’ 2005 memoir and starring Brie Larson as the author, “The Glass Castle” is an extended flashback that begins with that shocker of a moment. It isn’t mere mortification that plagues Walls but a deep anger at the unstable, near-feral childhood she experienced with her parents, Rex and Rose Mary Walls, excellently played by Woody Harrelson and Naomi Watts. Penniless vagabonds with a proto-hippie, nonconformist streak and an aversion to practicality, the couple moved their four children all over the United States, often in the dead of night, creating a life of romantic adventure that, over time, began to feel more like plain old poverty.

advertisement | advertise on newsday

The movie’s heroine is Jeannette, first played by Chandler Head as a suggestible tyke, then by Ella Anderson as a suspicious preteen and finally as a self-invented, slightly phony New Yorker by Larson. The film’s most fascinating figure, though, is Rex. As a father, he’s somewhere between the drifting con artist Moses Pray in “Paper Moon” and the self-aggrandizing striver who shares his name with “The Royal Tenenbaums.” On the one hand, Rex is a borderline lowlife who isn’t above using his teenage daughter as eye candy to hustle a game of pool. At the same time, Rex expects greatness from his offspring, as if they were scions in a famous dynasty. Much of his talk is empty, such as his plans to build Jeannette a whimsical glass castle, but we never doubt that this flawed man loves his children with an uncommon ferocity.

Harrelson is nothing less than perfect as Rex, alternating between dashing charmer and shameful drunk, while Watts has several crucial moments as Rose Mary, an artistic woman whose loyalty to her husband is both incomprehensible and deeply touching. Beautifully written by Andrew Lanham and director Destin Daniel Cretton (“Short Term 12,” also starring Larson), “The Glass Castle” nicely encapsulates the complicated emotions of a lifetime: rage, resentment, affection, gratitude. In other words, it’s a movie about family.